本文整理匯總了C#中PascalABCCompiler.SyntaxTree.var_def_statement類的典型用法代碼示例。如果您正苦於以下問題:C# var_def_statement類的具體用法?C# var_def_statement怎麽用?C# var_def_statement使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
var_def_statement類屬於PascalABCCompiler.SyntaxTree命名空間,在下文中一共展示了var_def_statement類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: visit
public override void visit(var_def_statement vd)
{
var idents = vd.vars.idents;
var IdentsToDeleteInVarDef = idents.FindAll(id => idsToDelete.Contains(id.name)); // найти в операторе все идентификаторы для удаления
if (IdentsToDeleteInVarDef.Count != 0)
{
deletedIdsToDeleteInLocalScope.UnionWith(IdentsToDeleteInVarDef.Select(id => id.name)); // добавить те идентификаторы, которые мы удаляем из данного описания
BlockDeletedIds.Add(new var_def_statement(new ident_list(IdentsToDeleteInVarDef), vd.vars_type, vd.inital_value)); // добавить описание из удаленных в данном разделе описаний идентификаторов
idents.RemoveAll(id => idsToDelete.Contains(id.name)); // удалить в операторе все идентификаторы для удаления
if (idents.Count == 0)
{
// Выше - variable_definitions, еще выше - declarations
var uvdsl = UpperNodeAs<variable_definitions>();
uvdsl.var_definitions.Remove(vd);
if (uvdsl.var_definitions.Count == 0)
{
var d = UpperNodeAs<declarations>(2);
d.defs.Remove(uvdsl);
}
}
}
}
示例2: CreateVarDef
/// <summary>
/// Создать var-выражение с несколькими переменными
/// </summary>
/// <param name="type">Тип переменных</param>
/// <param name="idents">Имена переменных</param>
/// <returns></returns>
public var_def_statement CreateVarDef(named_type_reference type, params string[] names)
{
var_def_statement res = new var_def_statement();
foreach (string x in names)
res.vars.Add(new ident(x));
res.vars_type = type;
return res;
}
示例3: visit
public override void visit(var_def_statement varDefStmt)
{
_visitor.visit(varDefStmt);
foreach (var id in varDefStmt.vars.idents)
{
var si = _visitor.context.find(id.name);
_currentTreeNode.VariablesDefinedInScope.Add(new CapturedVariablesTreeNode.CapturedSymbolInfo(varDefStmt, si));
}
if (varDefStmt.inital_value != null)
{
ProcessNode(varDefStmt.inital_value);
}
}
示例4: write_var_def_statement
public void write_var_def_statement(var_def_statement _var_def_statement)
{
write_declaration(_var_def_statement);
if (_var_def_statement.vars == null)
{
bw.Write((byte)0);
}
else
{
bw.Write((byte)1);
_var_def_statement.vars.visit(this);
}
if (_var_def_statement.vars_type == null)
{
bw.Write((byte)0);
}
else
{
bw.Write((byte)1);
_var_def_statement.vars_type.visit(this);
}
if (_var_def_statement.inital_value == null)
{
bw.Write((byte)0);
}
else
{
bw.Write((byte)1);
_var_def_statement.inital_value.visit(this);
}
bw.Write((byte)_var_def_statement.var_attr);
bw.Write(_var_def_statement.is_event);
}
示例5: visit
public override void visit(var_def_statement defs)
{
indef = true;
ProcessNode(defs.vars); // исключаем типы - просматриваем только имена переменных
indef = false;
}
示例6: var_statement
///<summary>
///Конструктор с параметрами.
///</summary>
public var_statement(var_def_statement _var_def,SourceContext sc)
{
this._var_def=_var_def;
source_context = sc;
}
示例7: visit
public override void visit(var_def_statement varStmt)
{
syntaxTreeVisitor.visit(varStmt);
}
示例8: CreateVarStatementNode
public static var_statement CreateVarStatementNode(string idName, string varTypeName, expression initValue)
{
var id = new ident(idName);
var idlist = new ident_list(id);
var varType = new named_type_reference(varTypeName, null);
var vdef = new var_def_statement(idlist, varType, initValue, definition_attribute.None, false, null);
return new var_statement(vdef, null);
}
示例9: ident_list14
public List<object> ident_list14(object lr1, object lr3)
{
List<object> ar = new List<object>();
//named_type_reference n_t_r = (named_type_reference)lr3;
var_def_statement vds = new var_def_statement();
vds.vars = new ident_list();
vds.vars.idents.Add((ident)lr1);
vds.vars_type = (type_definition)lr3;
ar.Add(vds);
return ar;
}
示例10: ident_list13
public List<object> ident_list13(object lr1, object lr3, object lr5)
{
List<object> ar = (List<object>)lr5;
//named_type_reference n_t_r = (named_type_reference)lr3;
var_def_statement vds = new var_def_statement();
vds.vars = new ident_list();
vds.vars.idents.Add((ident)lr1);
vds.vars_type = (type_definition)lr3;//n_t_r;
ar.Insert(0, vds);
return ar;
}
示例11: SubstituteTypesInCaseOfGenerics
private void SubstituteTypesInCaseOfGenerics()
{
if (!IsInGenerics)
{
return;
}
/* TODO: нужно заменить в полях сгенерированных классов, параметрах и возвращаемом значении лямбд - у всех, с учетом того как чистятся все дженерики...
/* Предусмотреть случай, когда захвата переменных не происходит, но мы все равно находимся в лямбде - это нужно сделать на FinishPhase в syntax_tree_visitor
/* Не забыть про where секцию */
var nestedLambdas = new List<CapturedVariablesTreeNodeLambdaScope>();
foreach (var cl in _generatedScopeClassesInfo.Where(cd => !(cd.Value.CorrespondingTreeNode is CapturedVariablesTreeNodeClassScope)))
{
nestedLambdas.AddRange(cl.Value.NestedLambdas);
}
foreach (CapturedVariablesTreeNodeLambdaScope t in _lambdasToBeAddedAsMethods.Concat(nestedLambdas))
{
var lambdaDef = t.LambdaDefinition;
if (lambdaDef.formal_parameters != null && lambdaDef.formal_parameters.params_list.Count > 0)
{
for (var j = 0; j < lambdaDef.formal_parameters.params_list.Count; j++)
{
if (lambdaDef.formal_parameters.params_list[j].vars_type is lambda_inferred_type)
{
if ((lambdaDef.formal_parameters.params_list[j].vars_type as lambda_inferred_type).real_type is type_node)
{
lambdaDef.formal_parameters.params_list[j].vars_type =
LambdaHelper.ConvertSemanticTypeToSyntaxType((type_node)(lambdaDef.formal_parameters.params_list[j].vars_type as lambda_inferred_type).real_type);
}
}
}
}
if (lambdaDef.return_type is lambda_inferred_type)
{
if ((lambdaDef.return_type as lambda_inferred_type).real_type is type_node)
{
lambdaDef.return_type = LambdaHelper.ConvertSemanticTypeToSyntaxType((type_node)(lambdaDef.return_type as lambda_inferred_type).real_type);
}
}
}
foreach (var clDecl in _generatedScopeClassesInfo.Where(cd => !(cd.Value.CorrespondingTreeNode is CapturedVariablesTreeNodeClassScope)))
{
var fields =
((class_definition) clDecl.Value.ClassDeclaration.type_def).body.class_def_blocks
.SelectMany(d => d.members)
.OfType<var_def_statement>();
foreach (var field in fields)
{
var semTypeNode = field.vars_type as semantic_type_node;
if (semTypeNode != null)
{
if (semTypeNode.type is type_node)
{
field.vars_type = LambdaHelper.ConvertSemanticTypeToSyntaxType((type_node) semTypeNode.type);
}
}
}
var constructors =
((class_definition)clDecl.Value.ClassDeclaration.type_def).body.class_def_blocks
.SelectMany(d => d.members)
.OfType<procedure_definition>()
.Where(pr => pr.proc_header is constructor);
foreach (var constructor in constructors)
{
if (constructor.proc_header != null && constructor.proc_header.parameters != null && constructor.proc_header.parameters.params_list != null)
{
var pars = constructor.proc_header.parameters.params_list;
foreach (var p in pars)
{
var semTypeNode = p.vars_type as semantic_type_node;
if (semTypeNode != null)
{
if (semTypeNode.type is type_node)
{
p.vars_type = LambdaHelper.ConvertSemanticTypeToSyntaxType((type_node)semTypeNode.type);
}
}
}
}
}
var upperField =
((class_definition)clDecl.Value.ClassDeclaration.type_def).body.class_def_blocks
.SelectMany(d => d.members)
.OfType<var_def_statement>()
.FirstOrDefault(vds =>
{
if (vds.vars != null && vds.vars.idents != null)
{
if (vds.vars.idents.FirstOrDefault(id => id.name == clDecl.Value.GeneratedUpperClassFieldName) != null)
{
return true;
}
//.........這裏部分代碼省略.........
示例12: SubstituteVarDefInProcedure
private void SubstituteVarDefInProcedure(statement_list statementList) //TODO: сейчас обрабатывается так, как будто блока объявлений declarations в функции нет. Нужно будет предусмотреть, но не только для функций, а еще для всех узлов где есть block, который содержит declarations
{
var classDefsTreeNode = _generatedScopeClassesInfo.Join(_capturedVarsTreeNodesDictionary,
outer => outer.Key,
inner => inner.Key,
(outer, inner) => new
{
ClassDeclaration = outer.Value,
TreeNode = inner.Value
})
.Where(p => p.TreeNode is CapturedVariablesTreeNodeProcedureScope)
.Select(p => new
{
p.ClassDeclaration,
TreeNode = (CapturedVariablesTreeNodeProcedureScope)p.TreeNode
})
.FirstOrDefault();
if (classDefsTreeNode == null)
{
return;
}
var variables = classDefsTreeNode
.TreeNode
.VariablesDefinedInScope
.Where(l => l.ReferencingLambdas.Count > 0)
.ToList();
if (variables.Count == 0)
{
return;
}
CapturedVariablesSubstitutionClassGenerator.ScopeClassDefinition generatedClass;
if (_generatedScopeClassesInfo.TryGetValue(classDefsTreeNode.TreeNode.ScopeIndex, out generatedClass))
{
var exprList = variables.Select(v => (expression)new ident(((IVAriableDefinitionNode) v.SymbolInfo.sym_info).name)).ToList();
if (IsInGenerics)
{
var newVarDefSyntaxTreeNode = new var_def_statement(generatedClass.GeneratedSubstitutingFieldName, new template_type_reference(new named_type_reference(generatedClass.ClassDeclaration.type_name.name), new template_param_list(AllGenericParameters.Select(l => SyntaxTreeBuilder.BuildSimpleType(l.name)).ToList())));
newVarDefSyntaxTreeNode.inital_value =
new new_expr(new template_type_reference(new named_type_reference(generatedClass.ClassDeclaration.type_name.name), new template_param_list(AllGenericParameters.Select(l => SyntaxTreeBuilder.BuildSimpleType(l.name)).ToList())),
new expression_list(exprList), null);
generatedClass.GeneratedVarStatementForScope.var_def = newVarDefSyntaxTreeNode;
}
else
{
generatedClass.GeneratedVarStatementForScope.var_def.inital_value =
new new_expr(SyntaxTreeBuilder.BuildSimpleType(generatedClass.ClassDeclaration.type_name.name),
new expression_list(exprList), null);
}
var nodesToAdd = new List<statement>();
nodesToAdd.Add(generatedClass.GeneratedVarStatementForScope);
if (generatedClass.AssignNodeForUpperClassFieldInitialization != null)
{
nodesToAdd.Add(generatedClass.AssignNodeForUpperClassFieldInitialization);
}
statementList.subnodes.InsertRange(0, nodesToAdd);
}
}
示例13: SubstituteVariablesDeclarations
private void SubstituteVariablesDeclarations()
{
var classDefsTreeNodes = _generatedScopeClassesInfo.Join(_capturedVarsTreeNodesDictionary,
outer => outer.Key,
inner => inner.Key,
(outer, inner) => new
{
ClassDeclaration = outer.Value,
TreeNode = inner.Value
})
.Where(p => p.TreeNode is CapturedVariablesTreeNodeBlockScope)
.Select(p => new
{
p.ClassDeclaration,
TreeNode = (CapturedVariablesTreeNodeBlockScope) p.TreeNode
}); //TODO: Сейчас рассматриваются только захватываемые переменные, определенные внутри какого-либо блока. Рассмотреть остальные случаи.
foreach (var classDefTreeNode in classDefsTreeNodes)
{
var statementListNode = classDefTreeNode.TreeNode.CorrespondingSyntaxTreeNode as statement_list; //TODO: Сейчас рассматриваются только захватываемые переменные, определенные внутри какого-либо блока. Рассмотреть остальные случаи.
if (statementListNode != null)
{
var variables = classDefTreeNode
.TreeNode
.VariablesDefinedInScope
.Where(var => var.ReferencingLambdas.Count > 0)
.GroupBy(var => var.SyntaxTreeNodeWithVarDeclaration)
.Select(gr => new
{
SyntaxTreeNodeWithVarDeclaration = gr.Key,
Vars = gr.ToList()
})
.ToList();
if (variables.Count == 0)
{
return;
}
var newStmtList = new statement_list();
newStmtList.Add(classDefTreeNode.ClassDeclaration.GeneratedVarStatementForScope);
if (classDefTreeNode.ClassDeclaration.AssignNodeForUpperClassFieldInitialization != null)
{
newStmtList.Add(classDefTreeNode.ClassDeclaration.AssignNodeForUpperClassFieldInitialization);
}
var stmtListQueue = new Queue<statement>(statementListNode.subnodes);
while (stmtListQueue.Count > 0)
{
var currentStatement = stmtListQueue.Dequeue();
var varStatement = currentStatement as var_statement; //TODO: пока что только локальные переменные, определенные внутри var_def_statement!!!!!!!!
if (varStatement != null &&
varStatement.var_def != null)
{
var varDefKey =
variables.FirstOrDefault(gr => gr.SyntaxTreeNodeWithVarDeclaration == varStatement.var_def);
if (varDefKey != null)
{
var varsToExclude =
varDefKey.Vars.Select(var => ((IVAriableDefinitionNode) var.SymbolInfo.sym_info).name.ToLower()); //TODO: пока что только локальные переменные!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
var newVarList = varStatement.var_def.vars.idents
.Where(id => !varsToExclude.Contains(id.name.ToLower()))
.ToList();
if (newVarList.Count > 0)
{
var newVarDefStmt = new var_def_statement(new ident_list(newVarList), varStatement.var_def.vars_type)
{
inital_value = varStatement.var_def.inital_value
};
var newVarStmt = new var_statement(newVarDefStmt);
newStmtList.Add(newVarStmt);
}
if (varStatement.var_def.inital_value != null)
{
var initVal = varStatement.var_def.inital_value;
string auxVarName = null;
if (initVal is array_const)
{
auxVarName = LambdaHelper.GetAuxVarName();
var newVarDefStmt = new var_def_statement(new ident_list(new ident(auxVarName)), varStatement.var_def.vars_type)
{
inital_value = initVal
};
var newVarStmt = new var_statement(newVarDefStmt);
newStmtList.Add(newVarStmt);
}
foreach (var variable in varsToExclude)
{
var assignStmt =
new assign(new dot_node(new ident(classDefTreeNode.ClassDeclaration.GeneratedSubstitutingFieldName),
new ident(variable)),
auxVarName == null ? varStatement.var_def.inital_value : new ident(auxVarName));
newStmtList.Add(assignStmt);
}
//.........這裏部分代碼省略.........
示例14: CreateNonTerminalObject
//.........這裏部分代碼省略.........
_expression_list.source_context = ((expression)LRParser.GetReductionSyntaxNode(0)).source_context;
return _expression_list;
}
case (int)RuleConstants.RULE_ID_LIST1_TK_IDENTIFIER:
//<Id_list1> ::= 'tk_Identifier'
{
ident_list _ident_list = new ident_list();
_ident_list.idents.Add(LRParser.GetReductionSyntaxNode(0) as ident);
_ident_list.source_context = ((ident)LRParser.GetReductionSyntaxNode(0)).source_context;
return _ident_list;
}
case (int)RuleConstants.RULE_ID_LIST1_TK_IDENTIFIER_TK_COMMA:
//<Id_list1> ::= 'tk_Identifier' 'tk_Comma' <Id_list1>
{
ident_list _ident_list = GetIdents(LRParser.GetReductionSyntaxNode(2));
_ident_list.idents.Add(LRParser.GetReductionSyntaxNode(0) as ident);
parsertools.create_source_context(_ident_list, LRParser.GetReductionSyntaxNode(0), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(0)));
return _ident_list;
}
case (int)RuleConstants.RULE_ARRAY_LIST1_TK_IDENTIFIER_TK_SQUAREOPEN_TK_SQUARECLOSE:
//<Array_list1> ::= 'tk_Identifier' 'tk_SquareOpen' <Diap_list> 'tk_SquareClose'
{
ident_list _ident_list = new ident_list();
_ident_list.idents.Add(LRParser.GetReductionSyntaxNode(0) as ident);
indexers_types _indexers_types = GetIndexers(LRParser.GetReductionSyntaxNode(2));
array_type _array_type = new array_type(_indexers_types, null);
var_def_statement _var_def_statement = new var_def_statement(_ident_list, _array_type, null, definition_attribute.None, false);
variable_definitions _variable_definitions = new variable_definitions();
_variable_definitions.var_definitions.Add(_var_def_statement);
//_ident_list.source_context = ((ident)LRParser.GetReductionSyntaxNode(0)).source_context;
parsertools.create_source_context(_array_type, LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(3));
//parsertools.create_source_context(LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(3));
parsertools.create_source_context(_ident_list, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
parsertools.create_source_context(_indexers_types, LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(2));
parsertools.create_source_context(_variable_definitions, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(3));
parsertools.create_source_context(_var_def_statement, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(3));
return _variable_definitions;
}
case (int)RuleConstants.RULE_ARRAY_LIST1_TK_IDENTIFIER_TK_SQUAREOPEN_TK_SQUARECLOSE_TK_COMMA:
//<Array_list1> ::= 'tk_Identifier' 'tk_SquareOpen' <Diap_list> 'tk_SquareClose' 'tk_Comma' <Array_list1>
{
ident_list _ident_list = new ident_list();
_ident_list.idents.Add(LRParser.GetReductionSyntaxNode(0) as ident);
indexers_types _indexers_types = GetIndexers(LRParser.GetReductionSyntaxNode(2));
array_type _array_type = new array_type(_indexers_types, null);
var_def_statement _var_def_statement = new var_def_statement(_ident_list, _array_type, null, definition_attribute.None, false);
variable_definitions _variable_definitions = (LRParser.GetReductionSyntaxNode(5) as variable_definitions);
_variable_definitions.var_definitions.Add(_var_def_statement);
//_ident_list.source_context = ((ident)LRParser.GetReductionSyntaxNode(0)).source_context;
parsertools.create_source_context(_array_type, LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(3));
parsertools.create_source_context(_ident_list, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
//parsertools.create_source_context(LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(3));
parsertools.create_source_context(_indexers_types, LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(2));
parsertools.create_source_context(_variable_definitions, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(5));
示例15: visit
public override void visit(var_def_statement _var_def_statement)
{
try
{
returned_scope = null;
if (_var_def_statement.vars_type != null)
_var_def_statement.vars_type.visit(this);
if (_var_def_statement.vars_type == null && _var_def_statement.inital_value != null || _var_def_statement.inital_value is function_lambda_definition)
{
_var_def_statement.inital_value.visit(this);
}
// if (si == null) dn = compiled_type_node.get_type_node(PascalABCCompiler.NetHelper.NetHelper.FindType((_var_def_statement.vars_type as named_type_reference).names[0].name,unl));
if (returned_scope == null) return;
if (returned_scope is ProcScope)
{
if (_var_def_statement.vars_type != null)
returned_scope = new ProcType(returned_scope as ProcScope);
else
returned_scope = (returned_scope as ProcScope).return_type;
}
if (_var_def_statement.vars != null)
foreach (ident s in _var_def_statement.vars.idents)
{
SymInfo si = new SymInfo(s.name, SymbolKind.Variable,s.name);
if (cur_scope is TypeScope) si.kind = SymbolKind.Field;
if (_var_def_statement.is_event) si.kind = SymbolKind.Event;
ElementScope es = new ElementScope(si, returned_scope,cur_scope);
if (add_doc_from_text && this.converter.controller.docs != null && this.converter.controller.docs.ContainsKey(_var_def_statement))
es.AddDocumentation(this.converter.controller.docs[_var_def_statement]);
es.acc_mod = cur_access_mod;
es.is_static = _var_def_statement.var_attr == definition_attribute.Static;
es.si.acc_mod = cur_access_mod;
es.loc = get_location(s);
cur_scope.AddName(s.name,es);
es.declaringUnit = cur_scope;
}
}
catch(Exception e)
{
}
}