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<Scope> netScopes = new List<Scope>(); //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); 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 as InterfaceUnitScope).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(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); 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 as ImplementationUnitScope).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) { } } }
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<string> namespaces = new List<string>(); PascalABCCompiler.NetHelper.NetHelper.init_namespaces(_as); AssemblyDocCache.Load(_as,path); namespaces.AddRange(PascalABCCompiler.NetHelper.NetHelper.GetNamespaces(_as)); //List<Scope> netScopes = new List<Scope>(); //PascalABCCompiler.NetHelper.NetScope ns=new PascalABCCompiler.NetHelper.NetScope(unl,_as,tcst); InterfaceUnitScope unit_scope = null; cur_scope = unit_scope = new InterfaceUnitScope(new SymInfo("", SymbolKind.Namespace,"program"),null); // 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<Position> regions_stack = new Stack<Position>(); 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<PascalABCCompiler.SyntaxTree.compiler_directive>(); 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)); unit_scope.AddReferencedAssembly(assm); } } catch (Exception e) { } } else if (dir.Name.text.ToLower() == "region") { if (cur_scope.regions == null) cur_scope.regions = new List<Position>(); 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) { unit_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);*/ }
public DomConverter(CodeCompletionController controller) { stv = new DomSyntaxTreeVisitor(this); this.controller = controller; if (standard_units == null) InitModules(); }