using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.IO; using PascalABCCompiler.SyntaxTree; using System.Reflection; using PascalABCCompiler; using PascalABCCompiler.TreeConverter; using PascalABCCompiler.TreeRealization; using PascalABCCompiler.Parsers; namespace CodeCompletion { public class SemanticOptions { public bool allow_import_types=true; } public class DomSyntaxTreeVisitor : AbstractVisitor { private SymScope ret_tn; private List ret_names = new List(); public SymScope entry_scope; public SymScope impl_scope; private string cur_type_name; private location cur_loc; private DomConverter converter; private bool is_proc_realization=false; private string meth_name; private string cur_unit_file_name; //private Stack eval_stack = new Stack(); private RetValue cnst_val; private ExpressionEvaluator ev = new ExpressionEvaluator(); public bool add_doc_from_text=true; private bool search_all = false; internal bool parse_only_interface = false; public SemanticOptions semantic_options = new SemanticOptions(); public DomSyntaxTreeVisitor(DomConverter converter) { //tcst = new TreeConverterSymbolTable(false); this.converter = converter; } public override void visit(default_operator node) { node.type_name.visit(this); } public void Convert(compilation_unit cu) { try { cu.visit(this); } catch(Exception e) { //System.Diagnostics.Debug.WriteLine(e.StackTrace); } } public SymScope FindScopeByLocation(int line, int col) { try { SymScope ss = entry_scope.FindScopeByLocation(line,col); if (ss != null) return ss; if (impl_scope != null) return impl_scope.FindScopeByLocation(line,col); //if (impl_scope != null) return impl_scope.FindScopeByLocation(line,col); } catch { } return null; } public override void visit(syntax_tree_node _syntax_tree_node) { throw new Exception("The method or operation is not implemented."); } private bool HasVariablesInBlock(statement_list _statement_list) { foreach (statement stmt in _statement_list.subnodes) if (stmt is var_statement) return true; return false; } public override void visit(template_type_name node) { throw new Exception("The method or operation is not implemented."); } public override void visit(statement_list _statement_list) { SymScope tmp = cur_scope; if (HasVariablesInBlock(_statement_list)) { SymScope stmt_scope = new BlockScope(cur_scope); cur_scope.AddName("$block_scope",stmt_scope); stmt_scope.loc = get_location(_statement_list); cur_scope = stmt_scope; } //try { foreach (statement stmt in _statement_list.subnodes) stmt.visit(this); } //catch(Exception e) { } cur_scope = tmp; } public override void visit(expression _expression) { throw new Exception("The method or operation is not implemented."); } public override void visit(assign _assign) { //throw new Exception("The method or operation is not implemented."); if (_assign.to is ident && (_assign.to as ident).name == "result") _assign.from.visit(this); } public override void visit(bin_expr _bin_expr) { try { _bin_expr.left.visit(this); RetValue left = cnst_val; TypeScope tleft = ret_tn as TypeScope; cnst_val.prim_val = null; _bin_expr.right.visit(this); TypeScope tright = ret_tn as TypeScope; RetValue right = cnst_val; cnst_val.prim_val = null; if (left.prim_val != null && right.prim_val != null) { ev.eval_stack.Push(left); ev.eval_stack.Push(right); switch (_bin_expr.operation_type) { case Operators.Plus : ev.EvalPlus(); break; case Operators.Minus : ev.EvalMinus(); break; case Operators.Multiplication: ev.EvalMult(); break; case Operators.Division: ev.EvalDiv(); break; case Operators.IntegerDivision: ev.EvalIDiv(); break; case Operators.BitwiseAND: ev.EvalAnd(); break; case Operators.BitwiseOR: ev.EvalOr(); break; case Operators.BitwiseXOR: ev.EvalXor(); break; case Operators.BitwiseLeftShift: ev.EvalBitwiseLeft(); break; case Operators.BitwiseRightShift: ev.EvalBitwiseRight(); break; case Operators.Equal: ev.EvalEqual(); break; case Operators.NotEqual: ev.EvalNotEqual(); break; case Operators.Less: ev.EvalLess(); break; case Operators.LessEqual: ev.EvalLessEqual(); break; case Operators.Greater: ev.EvalGreater(); break; case Operators.GreaterEqual: ev.EvalGreaterEqual(); break; case Operators.LogicalAND: ev.EvalAnd(); break; case Operators.LogicalOR: ev.EvalOr(); break; case Operators.ModulusRemainder: ev.EvalRem(); break; } if (ev.eval_stack.Count > 0) { cnst_val = ev.eval_stack.Pop(); ret_tn = TypeTable.get_type(cnst_val.prim_val); } else { cnst_val.prim_val = null; } } else { cnst_val.prim_val = null; } if (tleft != null && tright != null) { RetValue tmp = cnst_val; List lst = tleft.FindOverloadNamesOnlyInType (PascalABCCompiler.TreeConverter.name_reflector.get_name(_bin_expr.operation_type)); ProcScope ps = select_method(lst.ToArray(),tleft,tright,_bin_expr.left,_bin_expr.right); if (ps != null) ret_tn = ps.return_type; else ret_tn = tleft; cnst_val = tmp; } else if (tleft != null) ret_tn = tleft; else ret_tn = tright; } catch (Exception e) { cnst_val.prim_val = null; ev.eval_stack.Clear(); ret_tn = null; } } public override void visit(un_expr _un_expr) { try { _un_expr.subnode.visit(this); TypeScope tleft = ret_tn as TypeScope; if (cnst_val.prim_val != null) { ev.eval_stack.Push(cnst_val); switch (_un_expr.operation_type) { case Operators.BitwiseNOT: ev.EvalNot(); break; case Operators.LogicalNOT: ev.EvalNot(); ret_tn = entry_scope.FindName(PascalABCCompiler.TreeConverter.compiler_string_consts.bool_type_name); break; case Operators.Minus: ev.EvalUnmin(); break; } if (ev.eval_stack.Count > 0) { cnst_val = ev.eval_stack.Pop(); ret_tn = TypeTable.get_type(cnst_val.prim_val); } else { cnst_val.prim_val = null; ret_tn = tleft; } } } catch (Exception e) { cnst_val.prim_val = null; ev.eval_stack.Clear(); ret_tn = null; } } public override void visit(token_taginfo node) { } public override void visit(declaration_specificator node) { } public override void visit(const_node _const_node) { throw new Exception("The method or operation is not implemented."); } public override void visit(bool_const _bool_const) { ret_tn = TypeTable.bool_type;//entry_scope.FindName(PascalABCCompiler.TreeConverter.compiler_string_consts.bool_type_name); cnst_val.prim_val = _bool_const.val; } public override void visit(int32_const _int32_const) { ret_tn = TypeTable.int_type;//entry_scope.FindName(PascalABCCompiler.TreeConverter.compiler_string_consts.integer_type_name); cnst_val.prim_val = _int32_const.val; } public override void visit(double_const _double_const) { ret_tn = TypeTable.real_type;//entry_scope.FindName(PascalABCCompiler.TreeConverter.compiler_string_consts.real_type_name); cnst_val.prim_val = _double_const.val; } public override void visit(statement _statement) { throw new Exception("The method or operation is not implemented."); } public override void visit(subprogram_body _subprogram_body) { throw new Exception("The method or operation is not implemented."); } public override void visit(ident _ident) { if (!search_all) { ret_tn = cur_scope.FindName(_ident.name); if (ret_tn == null) { //cnst_val.prim_val = _ident.name; cnst_val.prim_val = null; return; } if (ret_tn is ElementScope) { cnst_val.prim_val = (ret_tn as ElementScope).cnst_val; ret_tn = (ret_tn as ElementScope).sc; return; } else if (ret_tn is ProcScope) if ((ret_tn as ProcScope).parameters.Count == 0) ret_tn = (ret_tn as ProcScope).return_type; else if (ret_tn is TypeScope) is_type = true; } else { ret_names = cur_scope.FindOverloadNames(_ident.name); for (int i=0; i 0) ret_tn = ret_tn.FindNameOnlyInType(_named_type_reference.names[i].name); else ret_tn = ret_tn.FindName(_named_type_reference.names[i].name); if (ret_tn == null) break; } if (ret_tn == null || !(ret_tn is TypeScope)) ret_tn = new UnknownScope(new SymInfo(_named_type_reference.names[_named_type_reference.names.Count - 1].name, SymbolKind.Type, _named_type_reference.names[_named_type_reference.names.Count - 1].name)); } public override void visit(variable_definitions _variable_definitions) { bool is_event = false; foreach (var_def_statement vds in _variable_definitions.var_definitions) { if (vds.is_event && !is_event) is_event = true; else if (is_event) vds.is_event = true; vds.visit(this); } } public override void visit(ident_list _ident_list) { throw new Exception("The method or operation is not implemented."); } public System.Collections.Hashtable vars = new System.Collections.Hashtable(); public override void visit(var_def_statement _var_def_statement) { try { ret_tn = null; if (_var_def_statement.vars_type != null) _var_def_statement.vars_type.visit(this); else if (_var_def_statement.inital_value != null) { _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 (ret_tn == null) return; if (ret_tn is ProcScope) ret_tn = new ProcType(ret_tn as ProcScope); 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, ret_tn,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) { } } public document doc; public location get_location(syntax_tree_node tn) { if (tn.source_context==null) { return null; } return new location(tn.source_context.begin_position.line_num,tn.source_context.begin_position.column_num, tn.source_context.end_position.line_num,tn.source_context.end_position.column_num,doc); } public override void visit(declaration _declaration) { throw new Exception("The method or operation is not implemented."); } public override void visit(declarations _declarations) { //throw new Exception("The method or operation is not implemented."); foreach (declaration decl in _declarations.defs) decl.visit(this); } public override void visit(program_tree _program_tree) { } public override void visit(program_name _program_name) { throw new Exception("The method or operation is not implemented."); } public override void visit(string_const _string_const) { ret_tn = TypeTable.string_type;//entry_scope.FindName(PascalABCCompiler.TreeConverter.compiler_string_consts.string_type_name); //cnst_val.prim_val = "'"+_string_const.Value+"'"; cnst_val.prim_val = this.converter.controller.Parser.LanguageInformation.GetStringForString(_string_const.Value); } public override void visit(expression_list _expression_list) { throw new Exception("The method or operation is not implemented."); } public override void visit(dereference _dereference) { throw new Exception("The method or operation is not implemented."); } public override void visit(roof_dereference _roof_dereference) { //throw new Exception("The method or operation is not implemented."); _roof_dereference.dereferencing_value.visit(this); if (ret_tn != null && ret_tn is PointerScope) ret_tn = (ret_tn as PointerScope).ref_type; else ret_tn = null; } public override void visit(indexer _indexer) { //throw new Exception("The method or operation is not implemented."); _indexer.dereferencing_value.visit(this); if (ret_tn != null && ret_tn is TypeScope) { ret_tn = ret_tn.GetElementType(); } } public override void visit(PascalABCCompiler.SyntaxTree.for_node _for_node) { //throw new Exception("The method or operation is not implemented."); SymScope tmp = cur_scope; //if (_for_node.type_name != null) { SymScope stmt_scope = new BlockScope(cur_scope); cur_scope.AddName("$block_scope",stmt_scope); stmt_scope.loc = get_location(_for_node); ret_tn = null; if (_for_node.type_name != null) _for_node.type_name.visit(this); if (ret_tn != null) { cur_scope = stmt_scope; ElementScope es = new ElementScope(new SymInfo(_for_node.loop_variable.name, SymbolKind.Variable,_for_node.loop_variable.name),ret_tn,cur_scope); stmt_scope.AddName(_for_node.loop_variable.name,es); es.loc = get_location(_for_node.loop_variable); ret_tn = null; } else { _for_node.initial_value.visit(this); if (ret_tn != null) { cur_scope = stmt_scope; if (_for_node.create_loop_variable) { ElementScope es = new ElementScope(new SymInfo(_for_node.loop_variable.name, SymbolKind.Variable,_for_node.loop_variable.name),ret_tn,cur_scope); stmt_scope.AddName(_for_node.loop_variable.name,es); es.loc = get_location(_for_node.loop_variable); } ret_tn = null; } } } if (_for_node.statements != null) _for_node.statements.visit(this); cur_scope = tmp; } public override void visit(PascalABCCompiler.SyntaxTree.repeat_node _repeat_node) { if (_repeat_node.statements != null) _repeat_node.statements.visit(this); } public override void visit(PascalABCCompiler.SyntaxTree.while_node _while_node) { if (_while_node.statements != null) _while_node.statements.visit(this); } public override void visit(PascalABCCompiler.SyntaxTree.if_node _if_node) { if (_if_node.then_body != null) _if_node.then_body.visit(this); if (_if_node.else_body != null) _if_node.else_body.visit(this); } public override void visit(ref_type _ref_type) { //throw new Exception("The method or operation is not implemented."); _ref_type.pointed_to.visit(this); if (ret_tn != null && ret_tn is TypeScope) { ret_tn = new PointerScope(ret_tn as TypeScope); ret_tn.loc = get_location(_ref_type); } else { ret_tn = new PointerScope(); ret_tn.loc = get_location(_ref_type); } ret_tn.topScope = cur_scope; } public override void visit(diapason _diapason) { object left = null, right = null; try { _diapason.left.visit(this); left = cnst_val.prim_val; cnst_val.prim_val = null; _diapason.right.visit(this); right = cnst_val.prim_val; } catch (Exception e) { } if (left != null && right != null) { ret_tn = new DiapasonScope(left, right); ret_tn.loc = get_location(_diapason); ret_tn.topScope = cur_scope; } else ret_tn = null; } public override void visit(indexers_types _indexers_types) { throw new Exception("The method or operation is not implemented."); } public override void visit(array_type _array_type) { //throw new Exception("The method or operation is not implemented."); _array_type.elements_type.visit(this); if (ret_tn == null) return; SymScope of_type = ret_tn; List indexes = new List(); if (_array_type.indexers != null) { foreach (type_definition td in _array_type.indexers.indexers) { if (td != null) { td.visit(this); if (ret_tn != null) indexes.Add((TypeScope)ret_tn); else { ret_tn = null; return; } } else indexes.Add(null); } } else indexes.Add((TypeScope)entry_scope.FindName(PascalABCCompiler.TreeConverter.compiler_string_consts.integer_type_name)); ret_tn = new ArrayScope(of_type as TypeScope,indexes.ToArray()); ret_tn.topScope = cur_scope; if (_array_type.indexers == null) (ret_tn as ArrayScope).is_dynamic_arr = true; ret_tn.loc = get_location(_array_type); } public override void visit(label_definitions _label_definitions) { //throw new Exception("The method or operation is not implemented."); } public override void visit(procedure_attribute _procedure_attribute) { throw new Exception("The method or operation is not implemented."); } public override void visit(typed_parameters _typed_parametres) { throw new Exception("The method or operation is not implemented."); } public override void visit(formal_parameters _formal_parametres) { throw new Exception("The method or operation is not implemented."); } public override void visit(procedure_attributes_list _procedure_attributes_list) { throw new Exception("The method or operation is not implemented."); } private bool IsForward(procedure_header hdr) { if (hdr.proc_attributes == null) return false; for (int i=0; i lst = new List(); if (prms != null) { foreach (typed_parameters pars in prms.params_list) { pars.vars_type.visit(this); if (ret_tn != null) { foreach (ident id in pars.idents.idents) { if (ret_tn is ProcScope) ret_tn = new ProcType(ret_tn as ProcScope); ElementScope si = new ElementScope(new SymInfo(id.name, SymbolKind.Parameter,id.name),ret_tn,ps); si.loc = get_location(id); si.param_kind = pars.param_kind; lst.Add(si); } } } while (ps != null) { if (ps.parameters != null) { if (ps.parameters.Count == lst.Count) { bool eq = true; for (int i=0; i ref_type_wait_list = new List(); private ident_list template_args = null; public override void visit(type_declaration _type_declaration) { //throw new Exception("The method or operation is not implemented."); cur_type_name = _type_declaration.type_name.name; if (_type_declaration.type_name is template_type_name) { template_args = (_type_declaration.type_name as template_type_name).template_args; } _type_declaration.type_def.visit(this); if (ret_tn != null && ret_tn is PointerScope && (ret_tn as PointerScope).ref_type is UnknownScope) { ref_type_wait_list.Add(ret_tn as PointerScope); } //else if (ret_tn != null && ret_tn is TypeScope) { //if (ret_tn is TypeScope) //{ if (!(_type_declaration.type_def is named_type_reference)) { //(ret_tn as TypeScope).name = _type_declaration.type_name.name; ret_tn.si.name = _type_declaration.type_name.name; ret_tn.si.describe = ret_tn.GetDescription(); if (!(_type_declaration.type_def is class_definition)) ret_tn.MakeSynonimDescription(); ret_tn.loc = get_location(_type_declaration);//new location(loc.begin_line_num,loc.begin_column_num,ret_tn.loc.end_line_num,ret_tn.loc.end_column_num,ret_tn.loc.doc); if (_type_declaration.type_def is class_definition) { string key = this.converter.controller.Parser.LanguageInformation.GetClassKeyword((_type_declaration.type_def as class_definition).keyword); if (key != null && ret_tn.body_loc != null) { ret_tn.head_loc = new location(ret_tn.body_loc.begin_line_num,ret_tn.body_loc.begin_column_num, ret_tn.body_loc.begin_line_num,ret_tn.body_loc.begin_column_num+key.Length,doc); } } if (add_doc_from_text && this.converter.controller.docs != null && this.converter.controller.docs.ContainsKey(_type_declaration)) ret_tn.AddDocumentation(this.converter.controller.docs[_type_declaration]); if (!(_type_declaration.type_def is class_definition)) cur_scope.AddName(_type_declaration.type_name.name,ret_tn); } else { TypeSynonim ts = new TypeSynonim(new SymInfo(_type_declaration.type_name.name, SymbolKind.Type,_type_declaration.type_name.name),ret_tn); ts.loc = get_location(_type_declaration); ts.topScope = cur_scope; ts.declaringUnit = entry_scope; //ts.si.describe = "type "+ret_tn.si.name+" = "+ret_tn.si.describe; cur_scope.AddName(_type_declaration.type_name.name,ts); if (add_doc_from_text && this.converter.controller.docs != null && this.converter.controller.docs.ContainsKey(_type_declaration)) ts.AddDocumentation(this.converter.controller.docs[_type_declaration]); } //} } else if (ret_tn != null) { if (ret_tn is ProcScope) { ret_tn = new ProcType(ret_tn as ProcScope); ret_tn.topScope = cur_scope; } cur_scope.AddName(_type_declaration.type_name.name,ret_tn); if (ret_tn is ProcType) { ret_tn.MakeSynonimDescription(); } location loc = get_location(_type_declaration); if (ret_tn.loc == null) { ret_tn.loc = loc; //ret_tn.loc = new location(loc.begin_line_num,loc.begin_column_num,ret_tn.loc.end_line_num,ret_tn.loc.end_column_num,ret_tn.loc.doc); } } ret_tn.declaringUnit = entry_scope; if (ref_type_wait_list.Count == 0) ret_tn = null; cur_type_name = null; template_args = null; } public override void visit(type_declarations _type_declarations) { //throw new Exception("The method or operation is not implemented."); Hashtable ht = new Hashtable(StringComparer.OrdinalIgnoreCase); foreach (type_declaration td in _type_declarations.types_decl) { td.visit(this); if (td.type_name != null) ht[td.type_name.name] = ret_tn; } if (ref_type_wait_list.Count > 0) { for (int i=0; i namespaces = new List(); namespaces.AddRange(PascalABCCompiler.NetHelper.NetHelper.GetNamespaces(_as)); //List netScopes = new List(); //PascalABCCompiler.NetHelper.NetScope ns=new PascalABCCompiler.NetHelper.NetScope(unl,_as,tcst); cur_scope = new InterfaceUnitScope(new SymInfo(_unit_module.unit_name.idunit_name.name, SymbolKind.Namespace,_unit_module.unit_name.idunit_name.name),null,unl); this.cur_unit_file_name = _unit_module.file_name; //if (XmlDoc.LookupLocalizedXmlDocForUnitWithSources(_unit_module.file_name) != null) if (!add_doc_from_text) { UnitDocCache.LoadWithSources(cur_scope,_unit_module.file_name); //this.add_doc_from_text = false; } //add_standart_types_simple(); Stack regions_stack = new Stack(); if (CodeCompletionController.comp.CompilerOptions.CurrentProject != null && CodeCompletionController.comp.CompilerOptions.CurrentProject.ContainsSourceFile(_unit_module.file_name)) { IReferenceInfo[] refs = CodeCompletionController.comp.CompilerOptions.CurrentProject.References; if (_unit_module.compiler_directives == null) _unit_module.compiler_directives = new List(); foreach (IReferenceInfo ri in refs) { _unit_module.compiler_directives.Add (new PascalABCCompiler.SyntaxTree.compiler_directive(new token_info("reference"),new token_info(ri.FullAssemblyName))); } } if (_unit_module.compiler_directives != null) foreach (PascalABCCompiler.SyntaxTree.compiler_directive dir in _unit_module.compiler_directives) { if (dir.Name.text.ToLower() == "reference") { try { //System.Reflection.Assembly assm = System.Reflection.Assembly.LoadFrom(get_assembly_path(dir.Directive.text,_unit_module.file_name)); path = get_assembly_path(dir.Directive.text,_unit_module.file_name); System.Reflection.Assembly assm = PascalABCCompiler.NetHelper.NetHelper.LoadAssembly(path); PascalABCCompiler.NetHelper.NetHelper.init_namespaces(assm); AssemblyDocCache.Load(assm, path); namespaces.AddRange(PascalABCCompiler.NetHelper.NetHelper.GetNamespaces(assm)); cur_scope.AddReferencedAssembly(assm); } catch (Exception e) { } //ns=new PascalABCCompiler.NetHelper.NetScope(unl,assm,tcst); } else if (dir.Name.text.ToLower() == "region") { if (cur_scope.regions == null) cur_scope.regions = new List(); regions_stack.Push(new Position(dir.source_context.begin_position.line_num, dir.source_context.begin_position.column_num, dir.source_context.end_position.line_num, dir.source_context.end_position.column_num, dir.source_context.FileName, dir.Directive.text)); } else if (dir.Name.text.ToLower() == "endregion") { if (regions_stack.Count > 0) { Position pos = regions_stack.Pop(); if (cur_scope.regions != null) { cur_scope.regions.Add(new Position(pos.line, pos.column-1, dir.source_context.end_position.line_num, dir.source_context.end_position.column_num, pos.file_name, pos.fold_text)); } } } } ns_cache = new Hashtable(StringComparer.CurrentCultureIgnoreCase); doc = new document(_unit_module.file_name); cur_scope.head_loc = get_location(_unit_module.unit_name); cur_scope.file_name = _unit_module.file_name; cur_scope.loc = get_location(_unit_module); cur_scope.AddName(_unit_module.unit_name.idunit_name.name,cur_scope); if (add_doc_from_text && this.converter.controller.docs != null && this.converter.controller.docs.ContainsKey(_unit_module.unit_name)) cur_scope.AddDocumentation(this.converter.controller.docs[_unit_module.unit_name]); entry_scope = cur_scope; //add_standart_types(); if (_unit_module.unit_name.idunit_name.name == this.converter.controller.Parser.LanguageInformation.SystemUnitName) //add_system_unit(); { is_system_unit = true; add_standart_types(entry_scope); } CodeCompletionController.comp_modules[_unit_module.file_name] = this.converter; _unit_module.interface_part.visit(this); foreach (string s in namespaces) { if (!ns_cache.ContainsKey(s)) { NamespaceScope ns_scope = new NamespaceScope(s); entry_scope.AddName(s,ns_scope); ns_cache[s] = s; } } //if (parse_only_interface) // return; if (_unit_module.implementation_part != null) _unit_module.implementation_part.visit(this); if (_unit_module.initialization_part != null) { SymScope tmp = cur_scope; SymScope stmt_scope = new BlockScope(cur_scope); cur_scope.AddName("$block_scope",stmt_scope); stmt_scope.loc = get_location(_unit_module.initialization_part); /*if (_unit_module.implementation_part != null) { cur_scope.loc.end_line_num = entry_scope.loc.end_line_num; cur_scope.loc.end_column_num = entry_scope.loc.end_column_num; }*/ cur_scope = stmt_scope; _unit_module.initialization_part.visit(this); cur_scope = tmp; } if (_unit_module.finalization_part != null) { SymScope tmp = cur_scope; SymScope stmt_scope = new BlockScope(cur_scope); cur_scope.AddName("$block_scope",stmt_scope); stmt_scope.loc = get_location(_unit_module.finalization_part); /*if (_unit_module.implementation_part != null) { cur_scope.loc.end_line_num = entry_scope.loc.end_line_num; cur_scope.loc.end_column_num =entry_scope.loc.end_column_num; }*/ cur_scope = stmt_scope; _unit_module.finalization_part.visit(this); cur_scope = tmp; } } public string get_assembly_path(string name, string CompFile) { string fname = (string.Format("{0}\\{1}",System.IO.Path.GetDirectoryName(CompFile), name)).ToLower(); if (System.IO.File.Exists(fname)) return fname; return Compiler.get_assembly_path(name,true); } PascalABCCompiler.TreeRealization.using_namespace_list unl = new PascalABCCompiler.TreeRealization.using_namespace_list(); public SymScope cur_scope; public string FindPCUFileName(string UnitName) { return CodeCompletionController.comp.FindPCUFileNameWithoutSources(UnitName,System.IO.Path.GetDirectoryName(doc.file_name)); } private void add_system_unit() { string unit_file_name = this.converter.controller.Parser.LanguageInformation.SystemUnitName; if (unit_file_name == null) return; string unit_name = CodeCompletionNameHelper.FindSourceFileName(unit_file_name); if (unit_name != null) { DomConverter dc = CodeCompletionController.comp_modules[unit_name] as DomConverter; if (dc == null) { CodeCompletionController ccc = new CodeCompletionController(); dc = ccc.CompileAllIfNeed(unit_name, true); //dc.CompileAllIfNeed(unit_name); if (dc.stv != null && dc.stv.entry_scope != null) { dc.stv.entry_scope.InitAssemblies(); entry_scope.AddUsedUnit(dc.stv.entry_scope); add_standart_types(dc.stv.entry_scope); //get_standart_types(dc.stv); entry_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.system_unit_file_name,dc.stv.entry_scope); } CodeCompletionController.comp_modules[unit_name] = dc; } else if (dc.stv != null && dc.stv.entry_scope != null) { dc.stv.entry_scope.InitAssemblies(); entry_scope.AddUsedUnit(dc.stv.entry_scope); //get_standart_types(dc.stv); entry_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.system_unit_file_name,dc.stv.entry_scope); } } } public override void visit(program_module _program_module) { //Assembly _as = System.Reflection.Assembly.LoadFrom(get_assembly_path("mscorlib.dll",_program_module.file_name)); string path = get_assembly_path("mscorlib.dll",_program_module.file_name); System.Reflection.Assembly _as = PascalABCCompiler.NetHelper.NetHelper.LoadAssembly(path); List namespaces = new List(); PascalABCCompiler.NetHelper.NetHelper.init_namespaces(_as); AssemblyDocCache.Load(_as,path); namespaces.AddRange(PascalABCCompiler.NetHelper.NetHelper.GetNamespaces(_as)); //List netScopes = new List(); //PascalABCCompiler.NetHelper.NetScope ns=new PascalABCCompiler.NetHelper.NetScope(unl,_as,tcst); cur_scope = new InterfaceUnitScope(new SymInfo("", SymbolKind.Namespace,"program"),null,unl); // if (XmlDoc.LookupLocalizedXmlDocForUnitWithSources(_program_module.file_name) != null) // { // UnitDocCache.LoadWithSources(cur_scope,_program_module.file_name); // this.add_doc_from_text = false; // } //add_standart_types_simple(); CodeCompletionController.comp_modules[_program_module.file_name] = this.converter; Stack regions_stack = new Stack(); if (CodeCompletionController.comp.CompilerOptions.CurrentProject != null && CodeCompletionController.comp.CompilerOptions.CurrentProject.ContainsSourceFile(_program_module.file_name)) { IReferenceInfo[] refs = CodeCompletionController.comp.CompilerOptions.CurrentProject.References; if (_program_module.compiler_directives == null) _program_module.compiler_directives = new List(); foreach (IReferenceInfo ri in refs) { _program_module.compiler_directives.Add (new PascalABCCompiler.SyntaxTree.compiler_directive(new token_info("reference"),new token_info(ri.FullAssemblyName))); } } if (_program_module.compiler_directives != null) foreach (PascalABCCompiler.SyntaxTree.compiler_directive dir in _program_module.compiler_directives) { if (dir.Name.text.ToLower() == "reference") { try { //System.Reflection.Assembly assm = System.Reflection.Assembly.LoadFrom(get_assembly_path(dir.Directive.text,_program_module.file_name)); path = get_assembly_path(dir.Directive.text,_program_module.file_name); System.Reflection.Assembly assm = PascalABCCompiler.NetHelper.NetHelper.LoadAssembly(path); if (assm != null) { PascalABCCompiler.NetHelper.NetHelper.init_namespaces(assm); AssemblyDocCache.Load(assm, path); namespaces.AddRange(PascalABCCompiler.NetHelper.NetHelper.GetNamespaces(assm)); cur_scope.AddReferencedAssembly(assm); } } catch (Exception e) { } } else if (dir.Name.text.ToLower() == "region") { if (cur_scope.regions == null) cur_scope.regions = new List(); regions_stack.Push(new Position(dir.source_context.begin_position.line_num,dir.source_context.begin_position.column_num,dir.source_context.end_position.line_num,dir.source_context.end_position.column_num,dir.source_context.FileName)); } else if (dir.Name.text.ToLower() == "endregion") { if (regions_stack.Count > 0) { Position pos = regions_stack.Pop(); if (cur_scope.regions != null) { cur_scope.regions.Add(new Position(pos.end_line,pos.end_column,dir.source_context.end_position.line_num,dir.source_context.end_position.column_num,pos.file_name)); } } } } doc = new document(_program_module.file_name); cur_scope.loc = get_location(_program_module); entry_scope = cur_scope; if (_program_module.program_name != null) cur_scope.head_loc = get_location(_program_module.program_name); Hashtable ns_cache = new Hashtable(StringComparer.CurrentCultureIgnoreCase); bool has_system_unit = false; if (_program_module.used_units != null) { cur_scope.uses_source_range = get_location(_program_module.used_units); //foreach (unit_or_namespace s in _program_module.used_units.units) for (int j = _program_module.used_units.units.Count - 1; j >= 0; j--) { unit_or_namespace s = _program_module.used_units.units[j]; try { string str = ""; for (int i = 0; i < s.name.idents.Count; i++) { str += s.name.idents[i].name; NamespaceScope ns_scope = null; if (i == 0) { if (PascalABCCompiler.NetHelper.NetHelper.IsNetNamespace(str)) { ns_scope = new NamespaceScope(str); ns_cache[str] = str; cur_scope.AddName(str, ns_scope); if (s.name.idents.Count == 1) cur_scope.AddUsedUnit(ns_scope); } else if (PascalABCCompiler.NetHelper.NetHelper.IsType(str) && semantic_options.allow_import_types) { Type t = PascalABCCompiler.NetHelper.NetHelper.FindType(str); cur_scope.AddUsedUnit(new NamespaceTypeScope(TypeTable.get_compiled_type(new SymInfo(t.Name, SymbolKind.Class, t.FullName), t))); } else { string unit_name = null; string pcu_unit_name = FindPCUFileName(str); if (s is uses_unit_in) unit_name = (s as uses_unit_in).in_file.Value; else unit_name = CodeCompletionNameHelper.FindSourceFileName(str, System.IO.Path.GetDirectoryName(_program_module.file_name)); if (pcu_unit_name != null && unit_name != null && string.Compare(System.IO.Path.GetDirectoryName(_program_module.file_name), System.IO.Path.GetDirectoryName(pcu_unit_name), true) == 0 && string.Compare(System.IO.Path.GetDirectoryName(_program_module.file_name), System.IO.Path.GetDirectoryName(unit_name), true) != 0) unit_name = null; if (unit_name != null) { DomConverter dc = CodeCompletionController.comp_modules[unit_name] as DomConverter; if (dc == null /*|| CodeCompletionController.recomp_files[unit_name] != null*/) { dc = new CodeCompletionController().CompileAllIfNeed(unit_name, true); } if (dc.stv != null) { dc.stv.entry_scope.InitAssemblies(); cur_scope.AddUsedUnit(dc.stv.entry_scope); cur_scope.AddName(str, dc.stv.entry_scope); } } else { //unit_name = FindPCUFileName(str); unit_name = pcu_unit_name; if (unit_name != null) { IntellisensePCUReader pcu_rdr = new IntellisensePCUReader(); SymScope ss = pcu_rdr.GetUnit(unit_name); UnitDocCache.Load(ss, unit_name); cur_scope.AddUsedUnit(ss); cur_scope.AddName(str, ss); } //unit_name = System.IO.Path.GetDirectoryName(_program_module.file_name)+"\\"+str+System.IO.Path.GetExtension(_program_module.file_name); } } } if (i == s.name.idents.Count - 1 && i > 0 /*&& PascalABCCompiler.NetHelper.NetHelper.IsNetNamespace(str)*/) //possible_namespaces.Add(str); cur_scope.AddUsedUnit(new NamespaceScope(str)); if (i < s.name.idents.Count - 1) str += "."; } if (string.Compare(str,"PABCSystem",true) == 0) { has_system_unit = true; } unl.AddElement(new PascalABCCompiler.TreeRealization.using_namespace(str)); } catch (Exception e) { } } } if (!has_system_unit) add_system_unit(); foreach (string s in namespaces) { if (!ns_cache.ContainsKey(s)) { NamespaceScope ns_scope = new NamespaceScope(s); cur_scope.AddName(s,ns_scope); ns_cache[s] = s; } } //PascalABCCompiler.TreeRealization.common_type_node ctn = new ; if (_program_module.program_block.defs != null) foreach (declaration decl in _program_module.program_block.defs.defs) { try { decl.visit(this); } catch(Exception e) { } } if (_program_module.program_block.program_code != null) { //cur_scope.body_loc = get_location(_program_module.program_block.program_code); cur_scope.body_loc = new location(_program_module.program_block.program_code.left_logical_bracket.source_context.end_position.line_num, _program_module.program_block.program_code.left_logical_bracket.source_context.end_position.column_num, _program_module.program_block.program_code.source_context.end_position.line_num,_program_module.program_block.program_code.source_context.end_position.column_num, doc); //cur_scope.head_loc = get_location(_program_module.program_block.program_code.left_logical_bracket); _program_module.program_block.program_code.visit(this); } /*if (_program_module.program_block.program_code != null) cur_scope.loc = get_location(_program_module.program_block.program_code); else cur_scope.loc = new location(0,0,0,0,doc);*/ } private void add_standart_types(SymScope cur_scope) { string type_name = null; //obj_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.object_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.object_type_name),typeof(object)); cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.object_type_name,TypeTable.obj_type); //int_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.integer_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.integer_type_name),typeof(int)); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.integer_type_name, int_type); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.IntType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.int_type); //real_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.real_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.real_type_name),typeof(double)); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.real_type_name,real_type); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.DoubleType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.real_type); //string_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.string_type_name, SymbolKind.Class,PascalABCCompiler.TreeConverter.compiler_string_consts.string_type_name),typeof(string)); cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.string_type_name,TypeTable.string_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.string_type_name, //new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.string_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.ShortStringTypeName),typeof(string))); //char_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.char_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.char_type_name),typeof(char)); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.CharType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.char_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.char_type_name,char_type); //bool_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.bool_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.bool_type_name),typeof(bool)); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.BoolType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.bool_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.bool_type_name,bool_type); //byte_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.byte_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.byte_type_name),typeof(byte)); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.ByteType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.byte_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.byte_type_name,byte_type); //int16_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.short_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.short_type_name),typeof(short)); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.ShortType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.int16_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.short_type_name,int16_type); //sbyte_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.sbyte_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.sbyte_type_name),typeof(sbyte)); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.SByteType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.sbyte_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.sbyte_type_name,sbyte_type); //uint16_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.ushort_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.ushort_type_name),typeof(ushort)); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.UShortType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.uint16_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.ushort_type_name,uint16_type); //uint32_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.uint_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.uint_type_name),typeof(uint)); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.UIntType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.uint32_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.uint_type_name,uint32_type); //int64_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.long_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.long_type_name),typeof(long)); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.Int64Type); if (type_name != null) cur_scope.AddName(type_name, TypeTable.int64_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.long_type_name,int64_type); //uint64_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.ulong_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.ulong_type_name),typeof(ulong)); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.UInt64Type); if (type_name != null) cur_scope.AddName(type_name, TypeTable.uint64_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.ulong_type_name,uint64_type); //float_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.float_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.float_type_name),typeof(float)); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.FloatType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.float_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.float_type_name,float_type); //ptr_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.pointer_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.pointer_type_name),Type.GetType("System.Void*")); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.PointerType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.ptr_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.pointer_type_name,ptr_type); ProcScope ps = new ProcScope(PascalABCCompiler.TreeConverter.compiler_string_consts.set_length_procedure_name,null); ps.AddParameter(new ElementScope(new SymInfo("arr", SymbolKind.Parameter,"arr"),new ArrayScope(),null,ps)); ps.parameters[0].param_kind = parametr_kind.var_parametr; ps.AddParameter(new ElementScope(new SymInfo("length", SymbolKind.Parameter,"length"),TypeTable.int_type,null,ps)); ps.Complete(); cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.set_length_procedure_name,ps); cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.true_const_name,new ElementScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.true_const_name, SymbolKind.Constant,PascalABCCompiler.TreeConverter.compiler_string_consts.true_const_name),TypeTable.bool_type,true,null)); cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.false_const_name,new ElementScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.false_const_name, SymbolKind.Constant,PascalABCCompiler.TreeConverter.compiler_string_consts.false_const_name),TypeTable.bool_type,false,null)); ps = new ProcScope(PascalABCCompiler.TreeConverter.compiler_string_consts.new_procedure_name,null); ElementScope prm = new ElementScope(new SymInfo("p", SymbolKind.Parameter,"p"),TypeTable.ptr_type,null,ps); prm.param_kind = parametr_kind.var_parametr; ps.AddParameter(prm); ps.Complete(); cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.new_procedure_name,ps); ps = new ProcScope(PascalABCCompiler.TreeConverter.compiler_string_consts.dispose_procedure_name,null); prm = new ElementScope(new SymInfo("p", SymbolKind.Parameter,"p"),TypeTable.ptr_type,null,ps); prm.param_kind = parametr_kind.var_parametr; ps.AddParameter(prm); ps.Complete(); cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.dispose_procedure_name,ps); } public override void visit(hex_constant _hex_constant) { //throw new Exception("The method or operation is not implemented."); ret_tn = TypeTable.uint64_type;//entry_scope.FindName(PascalABCCompiler.TreeConverter.compiler_string_consts.ulong_type_name); cnst_val.prim_val = _hex_constant.val; } public override void visit(get_address _get_address) { //throw new Exception("The method or operation is not implemented."); _get_address.address_of.visit(this); if (ret_tn != null && ret_tn is TypeScope) { ret_tn = new PointerScope(ret_tn as TypeScope); } else ret_tn = null; } public override void visit(case_variant _case_variant) { //throw new Exception("The method or operation is not implemented."); } public override void visit(compiler_directive_if _compiler_directive_if) { } public override void visit(compiler_directive_list _compiler_directive_list) { } public override void visit(case_node _case_node) { //throw new Exception("The method or operation is not implemented."); if ( _case_node.conditions != null) for (int i=0; i<_case_node.conditions.variants.Count; i++) _case_node.conditions.variants[i].exec_if_true.visit(this); if (_case_node.else_statement != null) _case_node.else_statement.visit(this); } public override void visit(method_name _method_name) { if (_method_name.meth_name is operator_name_ident) _method_name.meth_name.visit(this); else meth_name = _method_name.meth_name.name; } public override void visit(dot_node _dot_node) { bool tmp = search_all; search_all = false; _dot_node.left.visit(this); search_all = tmp; if (ret_tn != null) { if (_dot_node.right is ident) { if (!search_all) { ret_tn = ret_tn.FindNameOnlyInType((_dot_node.right as ident).name); if (ret_tn != null && ret_tn is ProcScope && (ret_tn as ProcScope).return_type != null) { if ((ret_tn as ProcScope).parameters.Count == 0) ret_tn = (ret_tn as ProcScope).return_type; return; } else if (ret_tn is ElementScope) { this.cnst_val.prim_val = (ret_tn as ElementScope).cnst_val; ret_tn = (ret_tn as ElementScope).sc; return; } else if (ret_tn is TypeScope) is_type = true; } else { ret_names = ret_tn.FindOverloadNamesOnlyInType((_dot_node.right as ident).name); search_all = false; } } } } public override void visit(PascalABCCompiler.SyntaxTree.empty_statement _empty_statement) { //throw new Exception("The method or operation is not implemented."); } public override void visit(PascalABCCompiler.SyntaxTree.goto_statement _goto_statement) { //throw new Exception("The method or operation is not implemented."); } public override void visit(PascalABCCompiler.SyntaxTree.labeled_statement _labeled_statement) { //throw new Exception("The method or operation is not implemented."); if (_labeled_statement.to_statement != null) _labeled_statement.to_statement.visit(this); } private bool is_type = false; public override void visit(with_statement _with_statement) { //throw new Exception("The method or operation is not implemented."); SymScope tmp = cur_scope; WithScope ws = new WithScope(cur_scope); for (int i=_with_statement.do_with.expressions.Count-1; i>=0; i--) { is_type = false; _with_statement.do_with.expressions[i].visit(this); if (ret_tn != null) { ws.AddWithScope(ret_tn,is_type); } is_type = false; } cur_scope.AddName("$with_block",ws); ws.loc = get_location(_with_statement); cur_scope = ws; _with_statement.what_do.visit(this); cur_scope = tmp; } internal static bool is_good_overload(ProcScope ps, List args) { if (ps.parameters == null || ps.parameters.Count == 0) if (args.Count == 0) return true; else return false; if (args.Count == 0) if (ps.parameters.Count == 1 && ps.parameters[0].param_kind == parametr_kind.params_parametr) return true; else return false; if (args.Count == ps.parameters.Count || ps.IsExtension && args.Count == ps.parameters.Count - 1) { int off = 0; if (ps.IsExtension && args.Count == ps.parameters.Count - 1) off = 1; for (int i=0; i args) { if (ps.parameters == null || ps.parameters.Count == 0) if (args.Count == 0) return true; else return false; if (args.Count == 0) if (ps.parameters.Count == 1 && ps.parameters[0].param_kind == parametr_kind.params_parametr) return true; else return false; if (args.Count == ps.parameters.Count) { for (int i=0; i arg_types = new List(); List arg_types2 = new List(); if (tleft != null || tright != null) { if (tleft != null) { arg_types.Add(tleft); arg_types2.Add(tleft); } if (tright != null) { arg_types.Add(tright); arg_types2.Add(tright); } } else if (args != null) { foreach (expression e in args) { e.visit(this); ret_names.Clear(); arg_types.Add(ret_tn); arg_types2.Add(ret_tn as TypeScope); } } List good_procs = new List(); for (int i=0; i 1) for (int i=0; i 0) return good_procs[0].GetInstance(arg_types2); return null; } public override void visit(method_call _method_call) { search_all = true; _method_call.dereferencing_value.visit(this); search_all = false; this.cnst_val.prim_val = null; SymScope[] names = ret_names.ToArray(); ProcScope ps = select_method(names,null,null,_method_call.parameters != null?_method_call.parameters.expressions.ToArray():null); ret_names.Clear(); if (ps != null) { if (ps.return_type != null) { ret_tn = ps.return_type; } else ret_tn = null; } else if (names.Length > 0) { ret_tn = null; foreach (SymScope ss in names) if (ss is ProcScope) { ps = ss as ProcScope; if (ps.return_type != null) { ret_tn = ps.return_type; break; } else ret_tn = null; } else if (ss is TypeScope) { ret_tn = ss; } } } public override void visit(pascal_set_constant _pascal_set_constant) { //throw new Exception("The method or operation is not implemented."); ret_tn = cur_scope.FindName(PascalABCCompiler.TreeConverter.compiler_string_consts.set_name); cnst_val.prim_val = null; } public override void visit(PascalABCCompiler.SyntaxTree.array_const _array_const) { //throw new Exception("The method or operation is not implemented."); cnst_val.prim_val = null; } public override void visit(write_accessor_name _write_accessor_name) { //throw new Exception("The method or operation is not implemented."); } public override void visit(read_accessor_name _read_accessor_name) { //throw new Exception("The method or operation is not implemented."); } public override void visit(property_accessors _property_accessors) { //throw new Exception("The method or operation is not implemented."); } public override void visit(simple_property _simple_property) { //throw new Exception("The method or operation is not implemented."); _simple_property.property_type.visit(this); if (ret_tn == null) return; ElementScope es = new ElementScope(new SymInfo(_simple_property.property_name.name, SymbolKind.Property,_simple_property.property_name.name), ret_tn, cur_scope); es.declaringUnit = entry_scope; if (_simple_property.array_default != null) { TypeScope ts = cur_scope as TypeScope; if (_simple_property.parameter_list != null) { ts.elementType = ret_tn as TypeScope; for (int i=0; i<_simple_property.parameter_list.parameters.Count; i++) { _simple_property.parameter_list.parameters[i].type.visit(this); if (ret_tn == null || !(ret_tn is TypeScope)) return; for (int j=0; j<_simple_property.parameter_list.parameters[i].names.idents.Count; j++) ts.AddIndexer(ret_tn as TypeScope); } } } if (_simple_property.parameter_list != null) { es.elementType = ret_tn as TypeScope; for (int i=0; i<_simple_property.parameter_list.parameters.Count; i++) { _simple_property.parameter_list.parameters[i].type.visit(this); if (ret_tn == null || !(ret_tn is TypeScope)) return; for (int j=0; j<_simple_property.parameter_list.parameters[i].names.idents.Count; j++) es.AddIndexer(ret_tn as TypeScope); } es.MakeDescription(); } es.loc = get_location(_simple_property); if (add_doc_from_text && this.converter.controller.docs != null && this.converter.controller.docs.ContainsKey(_simple_property)) es.AddDocumentation(this.converter.controller.docs[_simple_property]); if (_simple_property.attr == definition_attribute.Static) es.is_static = true; es.acc_mod = cur_access_mod; es.si.acc_mod = cur_access_mod; cur_scope.AddName(_simple_property.property_name.name,es); } public override void visit(index_property _index_property) { //throw new Exception("The method or operation is not implemented."); if (_index_property.is_default != null) { TypeScope ts = cur_scope as TypeScope; if (_index_property.parameter_list != null) { for (int i=0; i<_index_property.parameter_list.parameters.Count; i++) { _index_property.parameter_list.parameters[i].type.visit(this); if (ret_tn == null || !(ret_tn is TypeScope)) return; for (int j=0; j<_index_property.parameter_list.parameters[i].names.idents.Count; j++) ts.AddIndexer(ret_tn as TypeScope); } } } } public override void visit(class_members _class_members) { //throw new Exception("The method or operation is not implemented."); } public override void visit(access_modifer_node _access_modifer_node) { //throw new Exception("The method or operation is not implemented."); } private access_modifer cur_access_mod = access_modifer.none; public override void visit(class_body _class_body) { //throw new Exception("The method or operation is not implemented."); foreach (class_members mems in _class_body.class_def_blocks) { if (mems.access_mod != null) cur_access_mod = mems.access_mod.access_level; foreach (declaration decl in mems.members) { try { decl.visit(this); } catch(Exception e) { } } cur_access_mod = access_modifer.none; } } private bool has_cyclic_inheritance(TypeScope ts) { TypeScope tmp = ts.baseScope; while (tmp != null) if (tmp == ts) return true; else tmp = tmp.baseScope; return false; } public override void visit(class_definition _class_definition) { //throw new Exception("The method or operation is not implemented."); SymScope tmp = cur_scope; TypeScope ss = null; ret_tn = null; if (_class_definition.class_parents != null && _class_definition.class_parents.types.Count > 0) _class_definition.class_parents.types[0].visit(this); if (ret_tn is TypeScope && has_cyclic_inheritance(ret_tn as TypeScope)) ret_tn = null; if (cur_type_name != null) ss = cur_scope.FindNameOnlyInType(cur_type_name) as TypeScope; if (ss == null || !(ss.members != null && ss.members.Count == 0)) { if (_class_definition.keyword == class_keyword.Record) { ss = new TypeScope(SymbolKind.Struct, cur_scope, ret_tn); if (cur_type_name == null) cur_type_name = "$record"; } else if (_class_definition.keyword == class_keyword.Class) { ss = new TypeScope(SymbolKind.Class, cur_scope, ret_tn); if (_class_definition.attribute == class_attribute.Sealed) ss.is_final = true; if (cur_type_name == null) cur_type_name = "$class"; } else if (_class_definition.keyword == class_keyword.Interface || _class_definition.keyword == class_keyword.TemplateInterface) { ss = new TypeScope(SymbolKind.Interface, cur_scope, ret_tn); if (cur_type_name == null) cur_type_name = "$interface"; } else if (_class_definition.keyword == class_keyword.TemplateClass) { ss = new TypeScope(SymbolKind.Class, cur_scope, ret_tn); if (cur_type_name == null) cur_type_name = "$class"; } else if (_class_definition.keyword == class_keyword.TemplateRecord) { ss = new TypeScope(SymbolKind.Struct, cur_scope, ret_tn); if (cur_type_name == null) cur_type_name = "$record"; } if (ss != null) cur_scope.AddName(cur_type_name, ss); } else ss.baseScope = ret_tn as TypeScope; int num = 0; if (_class_definition.keyword != class_keyword.Interface) num = 1; else ss.baseScope = null; if (_class_definition.class_parents != null && _class_definition.class_parents.types.Count > num) { for (int i=num; i<_class_definition.class_parents.types.Count; i++) { _class_definition.class_parents.types[i].visit(this); if (ret_tn != null && ret_tn is TypeScope && has_cyclic_inheritance(ret_tn as TypeScope)) ret_tn = null; if (ret_tn != null && ret_tn is TypeScope && (ret_tn as TypeScope).si.kind == SymbolKind.Interface) ss.AddImplementedInterface(ret_tn as TypeScope); } } if (has_cyclic_inheritance(ss)) ss.baseScope = null; ss.loc = get_location(_class_definition); cur_scope = ss; if (_class_definition.template_args != null) { foreach (ident id in _class_definition.template_args.idents) ss.AddGenericParameter(id.name); } else if (template_args != null) { foreach (ident id in template_args.idents) ss.AddGenericParameter(id.name); } string tmp_name = cur_type_name; cur_type_name = null; if (_class_definition.body != null) { _class_definition.body.visit(this); ss.body_loc = get_location(_class_definition); ss.real_body_loc = get_location(_class_definition.body); ss.AddDefaultConstructorIfNeed(); } cur_type_name = tmp_name; ret_tn = ss; cur_scope = tmp; } public override void visit(default_indexer_property_node _default_indexer_property_node) { //throw new Exception("The method or operation is not implemented."); } public override void visit(known_type_definition _known_type_definition) { //throw new Exception("The method or operation is not implemented."); } public override void visit(set_type_definition _set_type_definition) { //throw new Exception("The method or operation is not implemented."); _set_type_definition.of_type.visit(this); ret_tn = new SetScope(ret_tn as TypeScope); ret_tn.topScope = cur_scope; } public override void visit(try_statement _try_statement) { //throw new Exception("The method or operation is not implemented."); } public override void visit(on_exception _on_exception) { //throw new Exception("The method or operation is not implemented."); } public override void visit(on_exception_list _on_exception_list) { //throw new Exception("The method or operation is not implemented."); } public override void visit(try_finally_statement _try_finally_statement) { //throw new Exception("The method or operation is not implemented."); } public override void visit(try_except_statement _try_except_statement) { //throw new Exception("The method or operation is not implemented."); } public override void visit(record_const_definition _record_const_definition) { //throw new Exception("The method or operation is not implemented."); } public override void visit(record_const _record_const) { // throw new Exception("The method or operation is not implemented."); } public override void visit(record_type _record_type) { //throw new Exception("The method or operation is not implemented."); SymScope tmp = cur_scope; RecordScope rs = new RecordScope(); rs.loc = get_location(_record_type); cur_scope.AddName("$record",rs); cur_scope = rs; if (_record_type.parts.fixed_part != null) foreach (var_def_statement vds in _record_type.parts.fixed_part.vars) { vds.visit(this); } ret_tn = cur_scope; cur_scope = tmp; } public override void visit(enum_type_definition _enum_type_definition) { //throw new Exception("The method or operation is not implemented."); EnumScope enum_scope = new EnumScope(SymbolKind.Enum,cur_scope, TypeTable.get_compiled_type(new SymInfo(typeof(Enum).Name, SymbolKind.Enum,typeof(Enum).FullName),typeof(Enum))); enum_scope.loc = get_location(_enum_type_definition); enum_scope.topScope = cur_scope; List elems = new List(); if (_enum_type_definition.enumerators != null) foreach (enumerator en in _enum_type_definition.enumerators.enumerators) { ElementScope ss = new ElementScope(new SymInfo(en.name.name, SymbolKind.Constant, en.name.name),/*cur_scope.FindName(PascalABCCompiler.TreeConverter.compiler_string_consts.integer_type_name)*/enum_scope,cur_scope); ss.is_static = true; ss.cnst_val = en.name.name; elems.Add(ss); ss.loc = get_location(en); cur_scope.AddName(en.name.name, ss); enum_scope.AddName(en.name.name, ss); enum_scope.AddEnumConstant(en.name.name); } for (int i=0; i= 0; j--) { unit_or_namespace s = _interface_node.uses_modules.units[j]; string str = ""; for (int i = 0; i < s.name.idents.Count; i++) { str += s.name.idents[i].name; NamespaceScope ns_scope = null; if (i == 0) { if (PascalABCCompiler.NetHelper.NetHelper.IsNetNamespace(str)) { ns_scope = new NamespaceScope(str); ns_cache[str] = str; cur_scope.AddName(str, ns_scope); if (s.name.idents.Count == 1) cur_scope.AddUsedUnit(ns_scope); } else if (PascalABCCompiler.NetHelper.NetHelper.IsType(str) && semantic_options.allow_import_types) { Type t = PascalABCCompiler.NetHelper.NetHelper.FindType(str); cur_scope.AddUsedUnit(new NamespaceTypeScope(TypeTable.get_compiled_type(new SymInfo(t.Name, SymbolKind.Class, t.FullName), t))); } else { try { string unit_name = null; string pcu_unit_name = FindPCUFileName(str); if (s is uses_unit_in) unit_name = (s as uses_unit_in).in_file.Value; else unit_name = CodeCompletionNameHelper.FindSourceFileName(str, System.IO.Path.GetDirectoryName(this.cur_unit_file_name)); if (pcu_unit_name != null && unit_name != null && string.Compare(System.IO.Path.GetDirectoryName(this.cur_unit_file_name), System.IO.Path.GetDirectoryName(pcu_unit_name), true) == 0 && string.Compare(System.IO.Path.GetDirectoryName(this.cur_unit_file_name), System.IO.Path.GetDirectoryName(unit_name), true) != 0) unit_name = null; if (unit_name != null) { DomConverter dc = CodeCompletionController.comp_modules[unit_name] as DomConverter; if (dc == null /*|| CodeCompletionController.recomp_files[unit_name] != null*/) { dc = new CodeCompletionController().CompileAllIfNeed(unit_name, true); } if (dc.stv != null) { dc.stv.entry_scope.InitAssemblies(); cur_scope.AddUsedUnit(dc.stv.entry_scope); cur_scope.AddName(str, dc.stv.entry_scope); } } else { //unit_name = FindPCUFileName(str); unit_name = pcu_unit_name; if (unit_name != null) { IntellisensePCUReader pcu_rdr = new IntellisensePCUReader(); SymScope ss = pcu_rdr.GetUnit(unit_name); UnitDocCache.Load(ss, unit_name); cur_scope.AddUsedUnit(ss); cur_scope.AddName(str, ss); } //unit_name = System.IO.Path.GetDirectoryName(_program_module.file_name)+"\\"+str+System.IO.Path.GetExtension(_program_module.file_name); } } catch (Exception e) { } } } if (i == s.name.idents.Count - 1 && i > 0 /*&& PascalABCCompiler.NetHelper.NetHelper.IsNetNamespace(str)*/) cur_scope.AddUsedUnit(new NamespaceScope(str)); if (i < s.name.idents.Count - 1) str += "."; } if (string.Compare(str, "PABCSystem", true) == 0) has_system_unit = true; unl.AddElement(new PascalABCCompiler.TreeRealization.using_namespace(str)); } } //if (_interface_node.unit_name.idunit_name.name != PascalABCCompiler.TreeConverter.compiler_string_consts.system_unit_file_name) if (!is_system_unit && !has_system_unit) add_system_unit(); if (_interface_node.interface_definitions != null) foreach (declaration decl in _interface_node.interface_definitions.defs) { try { decl.visit(this); } catch (Exception e) { } } } public override void visit(implementation_node _implementation_node) { //throw new Exception("The method or operation is not implemented."); SymScope tmp = cur_scope; unl.clear(); cur_scope = new ImplementationUnitScope(new SymInfo("$implementation",SymbolKind.Namespace,"implementation"),cur_scope,unl); tmp.AddName("$implementation",cur_scope); (tmp as InterfaceUnitScope).impl_scope = cur_scope as ImplementationUnitScope; cur_scope.loc = get_location(_implementation_node); if (_implementation_node.uses_modules != null) { cur_scope.uses_source_range = get_location(_implementation_node.uses_modules); for (int j=_implementation_node.uses_modules.units.Count-1; j>=0;j--) { unit_or_namespace s =_implementation_node.uses_modules.units[j]; string str=""; for (int i = 0; i < s.name.idents.Count; i++) { str += s.name.idents[i].name; NamespaceScope ns_scope = null; NamespaceScope ns_scope2 = null; if (i == 0) { if (PascalABCCompiler.NetHelper.NetHelper.IsNetNamespace(str)) { ns_scope = new NamespaceScope(str); cur_scope.AddName(str,ns_scope); if (s.name.idents.Count == 1) cur_scope.AddUsedUnit(ns_scope); } else if (PascalABCCompiler.NetHelper.NetHelper.IsType(str) && semantic_options.allow_import_types) { Type t = PascalABCCompiler.NetHelper.NetHelper.FindType(str); cur_scope.AddUsedUnit( new NamespaceTypeScope(TypeTable.get_compiled_type(new SymInfo(t.Name, SymbolKind.Class,t.FullName),t))); } else { try { string unit_name = null; string pcu_unit_name = FindPCUFileName(str); if (s is uses_unit_in) unit_name = (s as uses_unit_in).in_file.Value; else unit_name = CodeCompletionNameHelper.FindSourceFileName(str, System.IO.Path.GetDirectoryName(this.cur_unit_file_name)); if (pcu_unit_name != null && unit_name != null && string.Compare(System.IO.Path.GetDirectoryName(this.cur_unit_file_name),System.IO.Path.GetDirectoryName(pcu_unit_name),true)==0 && string.Compare(System.IO.Path.GetDirectoryName(this.cur_unit_file_name),System.IO.Path.GetDirectoryName(unit_name),true) != 0) unit_name = null; if (unit_name != null) { DomConverter dc = CodeCompletionController.comp_modules[unit_name] as DomConverter; if (dc == null /*|| CodeCompletionController.recomp_files[unit_name] != null*/) { dc = new CodeCompletionController().CompileAllIfNeed(unit_name, true); } if (dc.stv != null) { dc.stv.entry_scope.InitAssemblies(); cur_scope.AddUsedUnit(dc.stv.entry_scope); cur_scope.AddName(str,dc.stv.entry_scope); } } else { //unit_name = FindPCUFileName(str); unit_name = pcu_unit_name; if (unit_name != null) { IntellisensePCUReader pcu_rdr = new IntellisensePCUReader(); SymScope ss = pcu_rdr.GetUnit(unit_name); UnitDocCache.Load(ss,unit_name); cur_scope.AddUsedUnit(ss); cur_scope.AddName(str,ss); } //unit_name = System.IO.Path.GetDirectoryName(_program_module.file_name)+"\\"+str+System.IO.Path.GetExtension(_program_module.file_name); } } catch (Exception e) { } } } if (i == s.name.idents.Count - 1 && i > 0 /*&& PascalABCCompiler.NetHelper.NetHelper.IsNetNamespace(str)*/) cur_scope.AddUsedUnit(new NamespaceScope(str)); if (i < s.name.idents.Count - 1) str += "."; } unl.AddElement(new PascalABCCompiler.TreeRealization.using_namespace(str)); } } impl_scope = cur_scope; if (_implementation_node.implementation_definitions != null) foreach (declaration decl in _implementation_node.implementation_definitions.defs) { try { decl.visit(this); } catch (Exception e) { } } } public override void visit(diap_expr _diap_expr) { //throw new Exception("The method or operation is not implemented."); } public override void visit(block _block) { //throw new Exception("The method or operation is not implemented."); if (_block.defs != null) _block.defs.visit(this); if (_block.program_code != null) _block.program_code.visit(this); //cur_scope.loc = get_location(_block.program_code); } public override void visit(proc_block _proc_block) { //throw new Exception("The method or operation is not implemented."); } public override void visit(array_of_named_type_definition _array_of_named_type_definition) { //throw new Exception("The method or operation is not implemented."); } public override void visit(array_of_const_type_definition _array_of_const_type_definition) { //throw new Exception("The method or operation is not implemented."); } public override void visit(literal _literal) { //throw new Exception("The method or operation is not implemented."); } public override void visit(case_variants _case_variants) { //throw new Exception("The method or operation is not implemented."); } public override void visit(diapason_expr _diapason_expr) { //throw new Exception("The method or operation is not implemented."); } public override void visit(var_def_list _var_def_list) { //throw new Exception("The method or operation is not implemented."); } public override void visit(record_type_parts _record_type_parts) { //throw new Exception("The method or operation is not implemented."); } public override void visit(property_array_default _property_array_default) { //throw new Exception("The method or operation is not implemented."); } public override void visit(property_interface _property_interface) { // throw new Exception("The method or operation is not implemented."); } public override void visit(property_parameter _property_parameter) { //throw new Exception("The method or operation is not implemented."); } public override void visit(property_parameter_list _property_parameter_list) { //throw new Exception("The method or operation is not implemented."); } public override void visit(inherited_ident _inherited_ident) { //throw new Exception("The method or operation is not implemented."); } public override void visit(format_expr _format_expr) { //throw new Exception("The method or operation is not implemented."); ret_tn = TypeTable.string_type; } public override void visit(initfinal_part _initfinal_part) { //throw new Exception("The method or operation is not implemented."); } public override void visit(token_info _token_info) { throw new Exception("The method or operation is not implemented."); } public override void visit(raise_stmt _raise_stmt) { //throw new Exception("The method or operation is not implemented."); } public override void visit(op_type_node _op_type_node) { throw new Exception("The method or operation is not implemented."); } public override void visit(file_type _file_type) { if (_file_type.file_of_type != null) _file_type.file_of_type.visit(this); ret_tn = new FileScope(ret_tn as TypeScope, cur_scope); } public override void visit(known_type_ident _known_type_ident) { throw new Exception("The method or operation is not implemented."); } public override void visit(exception_handler _exception_handler) { SymScope tmp = cur_scope; SymScope stmt_scope = new BlockScope(cur_scope); cur_scope.AddName("$block_scope",stmt_scope); stmt_scope.loc = get_location(_exception_handler); stmt_scope.loc = new location(stmt_scope.loc.begin_line_num,stmt_scope.loc.begin_column_num, _exception_handler.statements.source_context.end_position.line_num, _exception_handler.statements.source_context.end_position.column_num,stmt_scope.loc.doc); ret_tn = null; if (_exception_handler.variable == null) return; if (_exception_handler.type_name != null) _exception_handler.type_name.visit(this); else ret_tn = cur_scope.FindName(_exception_handler.variable.name); if (ret_tn != null) { cur_scope = stmt_scope; ElementScope es = new ElementScope(new SymInfo(_exception_handler.variable.name, SymbolKind.Variable,_exception_handler.variable.name),ret_tn,cur_scope); es.loc = get_location(_exception_handler.variable); stmt_scope.AddName(_exception_handler.variable.name,es); } _exception_handler.statements.visit(this); cur_scope = tmp; } public override void visit(exception_ident _exception_ident) { //throw new Exception("The method or operation is not implemented."); } public override void visit(exception_handler_list _exception_handler_list) { foreach (exception_handler eh in _exception_handler_list.handlers) eh.visit(this); } public override void visit(exception_block _exception_block) { //throw new Exception("The method or operation is not implemented."); if (_exception_block.handlers != null) _exception_block.handlers.visit(this); if (_exception_block.stmt_list != null) _exception_block.stmt_list.visit(this); if (_exception_block.else_stmt_list != null) _exception_block.else_stmt_list.visit(this); } public override void visit(try_handler _try_handler) { } public override void visit(try_handler_finally _try_handler_finally) { //throw new Exception("The method or operation is not implemented."); _try_handler_finally.stmt_list.visit(this); } public override void visit(try_handler_except _try_handler_except) { //throw new Exception("The method or operation is not implemented."); _try_handler_except.except_block.visit(this); } public override void visit(try_stmt _try_stmt) { //throw new Exception("The method or operation is not implemented."); if (_try_stmt.stmt_list != null) _try_stmt.stmt_list.visit(this); if (_try_stmt.handler != null) _try_stmt.handler.visit(this); } public override void visit(inherited_message _inherited_message) { //throw new Exception("The method or operation is not implemented."); } public override void visit(external_directive _external_directive) { } public override void visit(using_list _using_list) { throw new Exception("The method or operation is not implemented."); } public override void visit(oberon_import_module _oberon_import_module) { throw new Exception("The method or operation is not implemented."); } public override void visit(oberon_module _oberon_module) { throw new Exception("The method or operation is not implemented."); } public override void visit(oberon_ident_with_export_marker _oberon_ident_with_export_marker) { throw new Exception("The method or operation is not implemented."); } public override void visit(oberon_exit_stmt _oberon_exit_stmt) { throw new Exception("The method or operation is not implemented."); } public override void visit(jump_stmt _jump_stmt) { throw new Exception("The method or operation is not implemented."); } public override void visit(oberon_procedure_receiver _oberon_procedure_receiver) { throw new Exception("The method or operation is not implemented."); } public override void visit(oberon_procedure_header _oberon_procedure_header) { throw new Exception("The method or operation is not implemented."); } public override void visit(oberon_withstmt_guardstat _oberon_withstmt_guardstat) { throw new Exception("The method or operation is not implemented."); } public override void visit(oberon_withstmt_guardstat_list _oberon_withstmt_guardstat_list) { throw new Exception("The method or operation is not implemented."); } public override void visit(oberon_withstmt _oberon_withstmt) { throw new Exception("The method or operation is not implemented."); } public override void visit(loop_stmt _loop_stmt) { throw new Exception("The method or operation is not implemented."); } public override void visit(foreach_stmt _foreach_stmt) { //throw new Exception("The method or operation is not implemented."); SymScope tmp = cur_scope; if (_foreach_stmt.type_name != null) { SymScope stmt_scope = new BlockScope(cur_scope); cur_scope.AddName("$block_scope",stmt_scope); stmt_scope.loc = get_location(_foreach_stmt); if (_foreach_stmt.type_name is no_type_foreach) { _foreach_stmt.in_what.visit(this); if (ret_tn != null) ret_tn = ret_tn.GetElementType(); } else { _foreach_stmt.type_name.visit(this); } if (ret_tn != null) { cur_scope = stmt_scope; ElementScope es = new ElementScope(new SymInfo(_foreach_stmt.identifier.name, SymbolKind.Variable,_foreach_stmt.identifier.name),ret_tn,cur_scope); es.loc = get_location(_foreach_stmt.identifier); stmt_scope.AddName(_foreach_stmt.identifier.name,es); } } if (_foreach_stmt.stmt != null) _foreach_stmt.stmt.visit(this); cur_scope = tmp; } public override void visit(addressed_value_funcname _addressed_value_funcname) { throw new Exception("The method or operation is not implemented."); } public override void visit(named_type_reference_list _named_type_reference_list) { throw new Exception("The method or operation is not implemented."); } public override void visit(template_param_list _template_param_list) { throw new Exception("The method or operation is not implemented."); } public override void visit(template_type_reference _template_type_reference) { //throw new Exception("The method or operation is not implemented."); ret_tn = null; _template_type_reference.name.visit(this); List gen_args = new List(); if (ret_tn != null && ret_tn is TypeScope) { TypeScope ts = ret_tn as TypeScope; if (_template_type_reference.params_list != null) { List instances = new List(); foreach (type_definition td in _template_type_reference.params_list.params_list) { ret_tn = null; td.visit(this); if (ret_tn != null && ret_tn is TypeScope) //instances.Add(ret_tn as TypeScope); //ts.AddGenericInstanciation(ret_tn as TypeScope); gen_args.Add(ret_tn as TypeScope); } } if (gen_args.Count > 0) ts = ts.GetInstance(gen_args); //ts.MakeInstance(); //ret_tn = ts.GetGenericInstance(gen_args); //ts.si.describe = ts.ToString(); //else ret_tn = ts; } } public override void visit(int64_const _int64_const) { //throw new Exception("The method or operation is not implemented."); ret_tn = TypeTable.int64_type;//entry_scope.FindName(PascalABCCompiler.TreeConverter.compiler_string_consts.long_type_name); cnst_val.prim_val = _int64_const.val; } public override void visit(uint64_const _uint64_const) { ret_tn = TypeTable.uint64_type;//entry_scope.FindName(PascalABCCompiler.TreeConverter.compiler_string_consts.ulong_type_name); cnst_val.prim_val = _uint64_const.val; } public override void visit(new_expr _new_expr) { _new_expr.type.visit(this); if (_new_expr.new_array && ret_tn != null && ret_tn is TypeScope) { ret_tn = new ArrayScope(ret_tn as TypeScope,new TypeScope[1]{TypeTable.int_type}); (ret_tn as ArrayScope).is_dynamic_arr = true; } /*if (ret_tn != null && ret_tn is TypeScope) { TypeScope ts = ret_tn as TypeScope; ret_tn = ts.GetConstructor(); }*/ } public override void visit(type_definition_list _type_definition_list) { throw new Exception("The method or operation is not implemented."); } public override void visit(where_definition _where_definition) { //throw new Exception("The method or operation is not implemented."); } public override void visit(where_definition_list _where_definition_list) { //throw new Exception("The method or operation is not implemented."); } public override void visit(PascalABCCompiler.SyntaxTree.sizeof_operator _sizeof_operator) { ret_tn = TypeTable.int_type; } public override void visit(PascalABCCompiler.SyntaxTree.typeof_operator _typeof_operator) { //throw new Exception("The method or operation is not implemented."); ret_tn = TypeTable.get_compiled_type(new SymInfo(null, SymbolKind.Class,null),typeof(Type)); } public override void visit(PascalABCCompiler.SyntaxTree.compiler_directive _compiler_directive) { //throw new Exception("The method or operation is not implemented."); } private string get_operator_sign(Operators op) { switch(op) { case Operators.Plus : return PascalABCCompiler.TreeConverter.compiler_string_consts.plus_name; case Operators.Minus : return PascalABCCompiler.TreeConverter.compiler_string_consts.minus_name; case Operators.Division : return PascalABCCompiler.TreeConverter.compiler_string_consts.div_name; case Operators.Multiplication : return PascalABCCompiler.TreeConverter.compiler_string_consts.mul_name; case Operators.ModulusRemainder : return PascalABCCompiler.TreeConverter.compiler_string_consts.mod_name; case Operators.Less : return PascalABCCompiler.TreeConverter.compiler_string_consts.sm_name; case Operators.LessEqual : return PascalABCCompiler.TreeConverter.compiler_string_consts.smeq_name; case Operators.Greater : return PascalABCCompiler.TreeConverter.compiler_string_consts.gr_name; case Operators.GreaterEqual : return PascalABCCompiler.TreeConverter.compiler_string_consts.greq_name; case Operators.Equal : return PascalABCCompiler.TreeConverter.compiler_string_consts.eq_name; case Operators.NotEqual : return PascalABCCompiler.TreeConverter.compiler_string_consts.noteq_name; case Operators.AssignmentAddition : return PascalABCCompiler.TreeConverter.compiler_string_consts.plusassign_name; case Operators.AssignmentMultiplication : return PascalABCCompiler.TreeConverter.compiler_string_consts.multassign_name; case Operators.AssignmentSubtraction : return PascalABCCompiler.TreeConverter.compiler_string_consts.minusassign_name; case Operators.AssignmentDivision : return PascalABCCompiler.TreeConverter.compiler_string_consts.divassign_name; case Operators.Implicit : return " implicit"; case Operators.Explicit : return " explicit"; } return ""; } public override void visit(operator_name_ident _operator_name_ident) { //throw new Exception("The method or operation is not implemented."); meth_name = "operator"+get_operator_sign(_operator_name_ident.operator_type); } public override void visit(var_statement _var_statement) { //throw new Exception("The method or operation is not implemented."); _var_statement.var_def.visit(this); } public override void visit(PascalABCCompiler.SyntaxTree.question_colon_expression _question_colon_expression) { _question_colon_expression.ret_if_true.visit(this); } public override void visit(expression_as_statement _expression_as_statement) { //throw new Exception("The method or operation is not implemented."); } public override void visit(c_scalar_type _c_scalar_type) { switch (_c_scalar_type.scalar_name) { case c_scalar_type_name.tn_int : ret_tn = TypeTable.int_type; break; case c_scalar_type_name.tn_double : ret_tn = TypeTable.real_type; break; case c_scalar_type_name.tn_float : ret_tn = TypeTable.float_type; break; case c_scalar_type_name.tn_char : ret_tn = TypeTable.char_type; break; case c_scalar_type_name.tn_long : case c_scalar_type_name.tn_long_int : if (_c_scalar_type.sign == c_scalar_sign.unsigned) ret_tn = TypeTable.uint64_type; else ret_tn = TypeTable.int64_type; break; case c_scalar_type_name.tn_short : case c_scalar_type_name.tn_short_int : if (_c_scalar_type.sign == c_scalar_sign.unsigned) ret_tn = TypeTable.uint16_type; else ret_tn = TypeTable.int16_type; break; case c_scalar_type_name.tn_void : ret_tn = TypeTable.void_type; break; } } public override void visit(c_module _c_module) { //Assembly _as = System.Reflection.Assembly.LoadFrom(get_assembly_path("mscorlib.dll",_c_module.file_name)); System.Reflection.Assembly _as = System.Reflection.Assembly.LoadFrom(get_assembly_path("mscorlib.dll",_c_module.file_name)); PascalABCCompiler.NetHelper.NetHelper.init_namespaces(_as); //add_standart_types_simple(); //List netScopes = new List(); //PascalABCCompiler.NetHelper.NetScope ns=new PascalABCCompiler.NetHelper.NetScope(unl,_as,tcst); if (_c_module.compiler_directives != null) foreach (PascalABCCompiler.SyntaxTree.compiler_directive dir in _c_module.compiler_directives) { if (dir.Name.text == "reference") { try { //System.Reflection.Assembly assm = System.Reflection.Assembly.LoadFrom(get_assembly_path(dir.Directive.text,_c_module.file_name)); System.Reflection.Assembly assm = PascalABCCompiler.NetHelper.NetHelper.LoadAssembly(get_assembly_path(dir.Directive.text,_c_module.file_name)); PascalABCCompiler.NetHelper.NetHelper.init_namespaces(assm); } catch (Exception e) { } } } cur_scope = new InterfaceUnitScope(new SymInfo("", SymbolKind.Block,"module"),null,unl); doc = new document(_c_module.file_name); cur_scope.loc = get_location(_c_module); entry_scope = cur_scope; add_system_unit(); if (_c_module.used_units != null) { cur_scope.uses_source_range = get_location(_c_module.used_units); foreach (unit_or_namespace s in _c_module.used_units.units) { try { string str = ""; for (int i = 0; i < s.name.idents.Count; i++) { str += s.name.idents[i].name; NamespaceScope ns_scope = null; if (i == 0) { if (PascalABCCompiler.NetHelper.NetHelper.IsNetNamespace(str)) { ns_scope = new NamespaceScope(str); cur_scope.AddName(str, ns_scope); if (s.name.idents.Count == 1) cur_scope.AddUsedUnit(ns_scope); } else { string unit_name = CodeCompletionController.comp.FindSourceFileName(str); if (unit_name == null) { unit_name = Path.Combine(System.IO.Path.GetDirectoryName(_c_module.file_name), str) + System.IO.Path.GetExtension(_c_module.file_name); if (!System.IO.File.Exists(unit_name)) unit_name = null; } if (unit_name != null) { DomConverter dc = CodeCompletionController.comp_modules[unit_name] as DomConverter; if (dc == null /*|| CodeCompletionController.recomp_files[unit_name] != null*/) { dc = new CodeCompletionController().CompileAllIfNeed(unit_name); } if (dc.stv != null) { cur_scope.AddUsedUnit(dc.stv.entry_scope); cur_scope.AddName(str, dc.stv.entry_scope); } } } } if (i < s.name.idents.Count - 1) str += "."; if (i == s.name.idents.Count - 1 && i > 0) cur_scope.AddUsedUnit(new NamespaceScope(str)); } unl.AddElement(new PascalABCCompiler.TreeRealization.using_namespace(str)); } catch (Exception e) { } } } //PascalABCCompiler.TreeRealization.common_type_node ctn = new ; if (_c_module.defs != null) foreach (declaration decl in _c_module.defs.defs) { decl.visit(this); } } public override void visit(declarations_as_statement _declarations_as_statement) { throw new Exception("The method or operation is not implemented."); } public override void visit(array_size _array_size) { throw new Exception("The method or operation is not implemented."); } public override void visit(enumerator _enumerator) { throw new Exception("The method or operation is not implemented."); } public override void visit(enumerator_list _enumerator_list) { throw new Exception("The method or operation is not implemented."); } public override void visit(c_for_cycle _c_for_cycle) { //throw new Exception("The method or operation is not implemented."); } public override void visit(switch_stmt _switch_stmt) { throw new Exception("The method or operation is not implemented."); } public override void visit(type_definition_attr_list _type_definition_attr_list) { throw new Exception("The method or operation is not implemented."); } public override void visit(type_definition_attr _type_definition_attr) { throw new Exception("The method or operation is not implemented."); } public override void visit(lock_stmt _lock_stmt) { if (_lock_stmt != null) _lock_stmt.stmt.visit(this); } public override void visit(documentation_comment_list node) { throw new NotImplementedException(); } public override void visit(documentation_comment_section node) { throw new NotImplementedException(); } public override void visit(documentation_comment_tag node) { throw new NotImplementedException(); } public override void visit(documentation_comment_tag_param node) { throw new NotImplementedException(); } public override void visit(ident_with_templateparams node) { throw new NotImplementedException(); } public override void visit(bracket_expr _bracket_expr) { _bracket_expr.expr.visit(this); } public override void visit(attribute _attribute) { } public override void visit(attribute_list _attribute_list) { } public override void visit(simple_attribute_list _simple_attribute_list) { } public override void visit(function_lambda_definition _function_lambda_definition) { ProcScope ps = new ProcScope(_function_lambda_definition.lambda_name, this.cur_scope); ps.loc = get_location(_function_lambda_definition); cur_scope.AddName(_function_lambda_definition.lambda_name, ps); if (_function_lambda_definition.ident_list != null) foreach (ident id in _function_lambda_definition.ident_list.idents) ps.AddParameter(new ElementScope(new SymInfo(id.name,SymbolKind.Parameter,""),new UnknownScope(new SymInfo("",SymbolKind.Type,"")),ps)); _function_lambda_definition.proc_body.visit(this); ps.return_type = ret_tn as TypeScope; ret_tn = new ProcType(ps); } public override void visit(function_lambda_call _function_lambda_call) { // } public override void visit(semantic_check _semantic_check) { } public override void visit(lambda_inferred_type lit) //lroman// { } public override void visit(same_type_node stn) //SS 22/06/13// { } public override void visit(name_assign_expr _name_assign_expr) // SSM 27.06.13 { ret_tn = null; _name_assign_expr.expr.visit(this); if (ret_tn != null) { ElementScope es = new ElementScope(new SymInfo(_name_assign_expr.name.name, SymbolKind.Property, ""), ret_tn, cur_scope); cur_scope.AddName(_name_assign_expr.name.name, es); } } public override void visit(name_assign_expr_list _name_assign_expr_list) // SSM 27.06.13 { foreach (name_assign_expr expr in _name_assign_expr_list.name_expr) expr.visit(this); } public override void visit(unnamed_type_object _unnamed_type_object) // SSM 27.06.13 { SymScope tmp = cur_scope; TypeScope ts = null; cur_scope = ts = new TypeScope(SymbolKind.Class, tmp, null); tmp.AddName("class", cur_scope); ts.loc = get_location(_unnamed_type_object); ts.si = new SymInfo("class", SymbolKind.Class, ""); if (_unnamed_type_object.ne_list != null) _unnamed_type_object.ne_list.visit(this); ret_tn = cur_scope; cur_scope = tmp; } public override void visit(semantic_type_node stn) // SSM { } public override void visit(sequence_type _sequence_type) { template_type_reference ttr = new template_type_reference(); ttr.name = new named_type_reference("IEnumerable"); ttr.source_context = _sequence_type.source_context; ttr.params_list = new template_param_list(); ttr.params_list.params_list.Add(_sequence_type.elements_type); visit(ttr); } } }