Exemple #1
0
        private type_declaration get_type_declaration(ICSharpCode.NRefactory.Ast.TypeDeclaration td)
        {
            type_declaration type_decl = new type_declaration();

            type_decl.type_name = new ident(td.Name);
            if (td.Type == ICSharpCode.NRefactory.Ast.ClassType.Enum)
            {
                type_decl.type_def       = get_enum_type(td);
                type_decl.source_context = type_decl.type_def.source_context;
                return(type_decl);
            }
            class_definition class_def = new class_definition();

            class_def.source_context = get_source_context(td);
            if (td.Type == ICSharpCode.NRefactory.Ast.ClassType.Interface)
            {
                class_def.keyword = class_keyword.Interface;
            }
            else if (td.Type == ICSharpCode.NRefactory.Ast.ClassType.Struct)
            {
                class_def.keyword = class_keyword.Record;
            }
            class_def.class_parents  = get_base_classes(td.BaseTypes);
            class_def.body           = get_class_body(td);
            type_decl.type_def       = class_def;
            type_decl.source_context = class_def.source_context;
            return(type_decl);
        }
		public override object VisitTypeDeclaration (ICSharpCode.NRefactory.Ast.TypeDeclaration typeDeclaration, object data)
		{
			if (BuildName (typeDeclaration) != fullName) {
				RemoveCurrentNode ();
				return null;
			}
			TypeDeclaration = typeDeclaration;
			object result = base.VisitTypeDeclaration (typeDeclaration, data);
			return result;
		}
Exemple #3
0
        private class_body get_class_body(ICSharpCode.NRefactory.Ast.TypeDeclaration td)
        {
            class_body body = new class_body();

            body.source_context = get_source_context(td);
            foreach (ICSharpCode.NRefactory.Ast.INode node in td.Children)
            {
                body.class_def_blocks.Add(get_class_member(node));
            }
            return(body);
        }
Exemple #4
0
        public override object VisitTypeDeclaration(ICSharpCode.NRefactory.Ast.TypeDeclaration typeDeclaration, object data)
        {
            if (BuildName(typeDeclaration) != fullName)
            {
                RemoveCurrentNode();
                return(null);
            }
            TypeDeclaration = typeDeclaration;
            object result = base.VisitTypeDeclaration(typeDeclaration, data);

            return(result);
        }
Exemple #5
0
        string BuildName(ICSharpCode.NRefactory.Ast.TypeDeclaration typeDeclaration)
        {
            // note: inner types can't be moved therefore they're missing here.
            StringBuilder result = new StringBuilder();

            foreach (var ns in namespaces)
            {
                result.Append(ns.Name);
                result.Append(".");
            }
            result.Append(typeDeclaration.Name);
            if (typeDeclaration.Templates != null && typeDeclaration.Templates.Count > 0)
            {
                result.Append("`");
                result.Append(typeDeclaration.Templates.Count);
            }

            return(result.ToString());
        }
Exemple #6
0
        private enum_type_definition get_enum_type(ICSharpCode.NRefactory.Ast.TypeDeclaration td)
        {
            enum_type_definition enum_td = new enum_type_definition();

            enum_td.source_context = get_source_context(td);
            enum_td.enumerators    = new enumerator_list();
            foreach (ICSharpCode.NRefactory.Ast.INode node in td.Children)
            {
                if (node is ICSharpCode.NRefactory.Ast.FieldDeclaration)
                {
                    ICSharpCode.NRefactory.Ast.FieldDeclaration fld = node as ICSharpCode.NRefactory.Ast.FieldDeclaration;
                    foreach (ICSharpCode.NRefactory.Ast.VariableDeclaration vd in fld.Fields)
                    {
                        enumerator en = new enumerator(new named_type_reference(vd.Name), null);                        // SSM здесь исправил 15.1.16
                        en.source_context = get_source_context(fld);
                        enum_td.enumerators.enumerators.Add(en);
                    }
                }
            }
            return(enum_td);
        }
            public override object VisitTypeDeclaration(ICSharpCode.NRefactory.Ast.TypeDeclaration typeDeclaration, object data)
            {
                var visitorData = (VisitorData)data;

                if (typeDeclaration.Name == visitorData.TargetClassName)
                {
                    var fullNamespace = string.Empty;
                    foreach (var ns in visitorData.CurrentNamespaces)
                    {
                        if (fullNamespace == string.Empty)
                        {
                            fullNamespace = ns;
                        }
                        else
                        {
                            fullNamespace = ns + "." + fullNamespace;
                        }
                    }
                    visitorData.DiscoveredNamespace = fullNamespace;
                }
                return(null);
            }
Exemple #8
0
            public override object VisitTypeDeclaration(ICSharpCode.NRefactory.Ast.TypeDeclaration typeDeclaration, object data)
            {
                DomType type = new DomType(cu,
                                           TranslateClassType(typeDeclaration.Type),
                                           (Modifiers)typeDeclaration.Modifier,
                                           typeDeclaration.Name,
                                           new DomLocation(typeDeclaration.StartLocation.Line, typeDeclaration.StartLocation.Column),
                                           currentNamespace.Count > 0 ? currentNamespace.Peek() : "",
                                           TranslateRegion(typeDeclaration.StartLocation, typeDeclaration.EndLocation));

                if (currentType.Count > 0)
                {
                    currentType.Peek().Add(type);
                }
                else
                {
                    cu.Add(type);
                }

                if (typeDeclaration.BaseTypes != null)
                {
                    foreach (ICSharpCode.NRefactory.Ast.TypeReference baseType in typeDeclaration.BaseTypes)
                    {
                        if (type.BaseType == null)
                        {
                            type.BaseType = TranslateTypeReference(baseType);
                        }
                        else
                        {
                            type.AddInterfaceImplementation(TranslateTypeReference(baseType));
                        }
                    }
                }
                currentType.Push(type);
                typeDeclaration.AcceptChildren(this, data);
                currentType.Pop();

                return(null);
            }
			public override object VisitTypeDeclaration (ICSharpCode.NRefactory.Ast.TypeDeclaration typeDeclaration, object data)
			{
				DomType newType = new DomType ();
				newType.Name = typeDeclaration.Name;
				newType.Documentation = RetrieveDocumentation (typeDeclaration.StartLocation.Line);
				newType.Location = ConvertLocation (typeDeclaration.StartLocation);
				newType.ClassType = ConvertClassType (typeDeclaration.Type);
				DomRegion region = ConvertRegion (typeDeclaration.BodyStartLocation, typeDeclaration.EndLocation);
				region.End = new DomLocation (region.End.Line, region.End.Column + 1);
				newType.BodyRegion = region;
				newType.Modifiers = ConvertModifiers (typeDeclaration.Modifier);

				AddAttributes (newType, typeDeclaration.Attributes);

				foreach (ICSharpCode.NRefactory.Ast.TemplateDefinition template in typeDeclaration.Templates) {
					TypeParameter parameter = ConvertTemplateDefinition (template);
					newType.AddTypeParameter (parameter);
				}

				if (typeDeclaration.BaseTypes != null) {

					foreach (ICSharpCode.NRefactory.Ast.TypeReference type in typeDeclaration.BaseTypes) {
						if (type == typeDeclaration.BaseTypes[0]) {
							newType.BaseType = ConvertReturnType (type);
						} else {
							newType.AddInterfaceImplementation (ConvertReturnType (type));
						}
					}
				}
				AddType (newType);

				// visit members
				typeStack.Push (newType);
				typeDeclaration.AcceptChildren (this, data);
				typeStack.Pop ();

				return null;
			}
 public override object VisitTypeDeclaration(ICSharpCode.NRefactory.Ast.TypeDeclaration typeDeclaration, object data)
 {
     types.Add(typeDeclaration);
     return(base.VisitTypeDeclaration(typeDeclaration, data));
 }
Exemple #11
0
 private void add_module_members(unit_module mod, ICSharpCode.NRefactory.Ast.TypeDeclaration td)
 {
     foreach (ICSharpCode.NRefactory.Ast.INode node in td.Children)
     {
         if (node is ICSharpCode.NRefactory.Ast.FieldDeclaration)
         {
             ICSharpCode.NRefactory.Ast.FieldDeclaration vd = node as ICSharpCode.NRefactory.Ast.FieldDeclaration;
             if ((vd.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.Dim) == ICSharpCode.NRefactory.Ast.Modifiers.Dim)
             {
                 foreach (ICSharpCode.NRefactory.Ast.VariableDeclaration vard in vd.Fields)
                 {
                     var_def_statement vds = new var_def_statement();
                     vds.source_context = get_source_context(vd);
                     vds.vars_type      = get_type_reference(vard.TypeReference);
                     ident_list idents = new ident_list();
                     ident      name   = new ident(vard.Name);
                     name.source_context = vds.source_context;
                     idents.idents.Add(name);
                     vds.vars = idents;
                     mod.interface_part.interface_definitions.defs.Add(vds);
                 }
             }
             else if ((vd.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.Const) == ICSharpCode.NRefactory.Ast.Modifiers.Const)
             {
                 foreach (ICSharpCode.NRefactory.Ast.VariableDeclaration vard in vd.Fields)
                 {
                     const_definition tcd = null;
                     if (vard.TypeReference is ICSharpCode.NRefactory.Ast.TypeReference)
                     {
                         tcd = new simple_const_definition();
                     }
                     else
                     {
                         tcd = new typed_const_definition();
                     }
                     tcd.source_context = get_source_context(vd);
                     if (tcd is typed_const_definition)
                     {
                         (tcd as typed_const_definition).const_type = get_type_reference(vard.TypeReference);
                     }
                     tcd.const_name = new ident(vard.Name);
                     tcd.const_name.source_context = tcd.source_context;
                     tcd.const_value = get_expression(vard.Initializer);
                     mod.interface_part.interface_definitions.defs.Add(tcd);
                 }
             }
         }
         else if (node is ICSharpCode.NRefactory.Ast.TypeDeclaration)
         {
             mod.interface_part.interface_definitions.defs.Add(get_type_declaration(node as ICSharpCode.NRefactory.Ast.TypeDeclaration));
         }
         else if (node is ICSharpCode.NRefactory.Ast.MethodDeclaration)
         {
             ICSharpCode.NRefactory.Ast.MethodDeclaration meth = node as ICSharpCode.NRefactory.Ast.MethodDeclaration;
             if (!meth.Body.IsNull)
             {
                 mod.interface_part.interface_definitions.defs.Add(get_method_declaration(meth));
             }
             else
             {
                 mod.interface_part.interface_definitions.defs.Add(get_method_header(meth));
             }
         }
     }
 }
Exemple #12
0
        public syntax_tree_node get_syntax_tree(ICSharpCode.NRefactory.Ast.CompilationUnit unit, string FileName)
        {
            unit_module   mod     = null;
            List <string> imports = new List <string>();

            foreach (ICSharpCode.NRefactory.Ast.INode cu in unit.Children)
            {
                if (cu is ICSharpCode.NRefactory.Ast.TypeDeclaration)
                {
                    ICSharpCode.NRefactory.Ast.TypeDeclaration td = cu as ICSharpCode.NRefactory.Ast.TypeDeclaration;
                    if (td.Type == ICSharpCode.NRefactory.Ast.ClassType.Module)
                    {
                        mod                       = new unit_module();
                        mod.Language              = LanguageId.VBNET;
                        mod.file_name             = FileName;
                        mod.unit_name             = new unit_name();
                        mod.unit_name.idunit_name = new ident(td.Name);
                        mod.compiler_directives   = new List <compiler_directive>();
                        mod.compiler_directives.Add(new compiler_directive(new token_info("reference"), new token_info("System.dll")));
                        mod.compiler_directives.Add(new compiler_directive(new token_info("reference"), new token_info("Microsoft.VisualBasic.dll")));
                        mod.compiler_directives.Add(new compiler_directive(new token_info("reference"), new token_info("System.Windows.Forms.dll")));
                        mod.compiler_directives.Add(new compiler_directive(new token_info("reference"), new token_info("System.Drawing.dll")));
                        mod.source_context = get_source_context(td);
                        mod.interface_part = new interface_node();
                        mod.interface_part.interface_definitions = new declarations();
                        //mod.interface_part.source_context = new SourceContext(td.StartLocation.Line,td.StartLocation.Column,td.EndLocation.Line,td.EndLocation.Column);
                        mod.interface_part.uses_modules = new uses_list();

                        foreach (string s in imports)
                        {
                            List <ident> id_name = new List <ident>();
                            id_name.Add(new ident(s));
                            mod.interface_part.uses_modules.units.Add(new unit_or_namespace(new ident_list(id_name)));
                        }
                        List <ident> ids = new List <ident>();
                        ids.Add(new ident("Microsoft.VisualBasic.Strings"));
                        mod.interface_part.uses_modules.units.Add(new unit_or_namespace(new ident_list(ids)));
                        ids = new List <ident>();
                        ids.Add(new ident("System"));
                        mod.interface_part.uses_modules.units.Add(new unit_or_namespace(new ident_list(ids)));
                        ids = new List <ident>();
                        ids.Add(new ident("System.Collections.Generic"));
                        mod.interface_part.uses_modules.units.Add(new unit_or_namespace(new ident_list(ids)));
                        ids = new List <ident>();
                        ids.Add(new ident("Microsoft.VisualBasic.Constants"));
                        mod.interface_part.uses_modules.units.Add(new unit_or_namespace(new ident_list(ids)));
                        ids = new List <ident>();
                        ids.Add(new ident("Microsoft.VisualBasic.VBMath"));
                        mod.interface_part.uses_modules.units.Add(new unit_or_namespace(new ident_list(ids)));
                        ids = new List <ident>();
                        ids.Add(new ident("Microsoft.VisualBasic.Information"));
                        mod.interface_part.uses_modules.units.Add(new unit_or_namespace(new ident_list(ids)));
                        ids = new List <ident>();
                        ids.Add(new ident("Microsoft.VisualBasic.Interaction"));
                        mod.interface_part.uses_modules.units.Add(new unit_or_namespace(new ident_list(ids)));
                        ids = new List <ident>();
                        ids.Add(new ident("Microsoft.VisualBasic.FileSystem"));
                        mod.interface_part.uses_modules.units.Add(new unit_or_namespace(new ident_list(ids)));
                        ids = new List <ident>();
                        ids.Add(new ident("Microsoft.VisualBasic.Financial"));
                        mod.interface_part.uses_modules.units.Add(new unit_or_namespace(new ident_list(ids)));
                        ids = new List <ident>();
                        ids.Add(new ident("Microsoft.VisualBasic.DateAndTime"));
                        mod.interface_part.uses_modules.units.Add(new unit_or_namespace(new ident_list(ids)));

                        add_module_members(mod, td);
                    }
                }
                else if (cu is ICSharpCode.NRefactory.Ast.UsingDeclaration)
                {
                    ICSharpCode.NRefactory.Ast.UsingDeclaration usings = cu as ICSharpCode.NRefactory.Ast.UsingDeclaration;
                    for (int i = 0; i < usings.Usings.Count; i++)
                    {
                        imports.Add(usings.Usings[i].Name);
                    }
                }
            }
            return(mod);
        }