Exemplo n.º 1
0
        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);*/
        }
Exemplo n.º 2
0
 public override void visit(unit_module _unit_module)
 {
     string path = get_assembly_path("mscorlib.dll",_unit_module.file_name);
 	Assembly _as = PascalABCCompiler.NetHelper.NetHelper.LoadAssembly(path);
     AssemblyDocCache.Load(_as, path);
     PascalABCCompiler.NetHelper.NetHelper.init_namespaces(_as);
     List<string> namespaces = new List<string>();
     namespaces.AddRange(PascalABCCompiler.NetHelper.NetHelper.GetNamespaces(_as));
     InterfaceUnitScope unit_scope = null;
     cur_scope = unit_scope= new InterfaceUnitScope(new SymInfo(_unit_module.unit_name.idunit_name.name, SymbolKind.Namespace,_unit_module.unit_name.idunit_name.name),null);
     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<Position> regions_stack = new Stack<Position>();
     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<PascalABCCompiler.SyntaxTree.compiler_directive>();
     	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));
             	unit_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<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, 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;
     }
     
 }