private Namespace TraverseNamespace(NamespaceDeclarationSyntax nds) { Namespace retNS = new Namespace(); retNS.Name = nds.Name.ToString(); if (nds.HasLeadingTrivia) { SetOuterComments(retNS, nds.GetLeadingTrivia().ToFullString()); } if (nds.HasTrailingTrivia) { SetInnerComments(retNS, nds.GetTrailingTrivia().ToFullString()); } //First, grab any objects defined at the beginning of the namespace (even delegates!) var delegates = from aDelegate in nds.ChildNodes().OfType<DelegateDeclarationSyntax>() select aDelegate; foreach (DelegateDeclarationSyntax dds in delegates) { //TraverseDelegate } //Next, traverse any classes var classes = from cls in nds.ChildNodes().OfType<ClassDeclarationSyntax>() select cls; foreach (ClassDeclarationSyntax cds in classes) { retNS.Classes.Add(TraverseClass(cds)); } var interfaces = from anInterface in nds.ChildNodes().OfType<InterfaceDeclarationSyntax>() select anInterface; foreach (InterfaceDeclarationSyntax ids in interfaces) { Interface tempInterface = TraverseInterface(ids); retNS.Interfaces.Add(tempInterface); } var enums = from aEnum in nds.ChildNodes().OfType<EnumDeclarationSyntax>() select aEnum; foreach (EnumDeclarationSyntax eds in enums) { Model.Enum tempEnum = TraverseEnums(eds); retNS.Enums.Add(tempEnum); } //TODO: Don't forget enums return retNS; }
public Namespace TraverseTree() { Namespace retNS = new Namespace(); //Get using statements first List<UsingList> usingList = TraverseUsingList(); retNS.UsingList = usingList; List<DelegateStatementSyntax> delegates = new List<DelegateStatementSyntax>(); List<EventBlockSyntax> delegates2 = new List<EventBlockSyntax>(); List<InterfaceBlockSyntax> interfaces = new List<InterfaceBlockSyntax>(); List<EnumBlockSyntax> enums = new List<EnumBlockSyntax>(); List<StructureBlockSyntax> structs = new List<StructureBlockSyntax>(); List<MethodBlockSyntax> methods = new List<MethodBlockSyntax>(); List<ConstructorBlockSyntax> constructors = new List<ConstructorBlockSyntax>(); List<ModuleBlockSyntax> modules = new List<ModuleBlockSyntax>(); List<ClassBlockSyntax> classes = new List<ClassBlockSyntax>(); List<NamespaceBlockSyntax> namespaces = new List<NamespaceBlockSyntax>(); foreach (SyntaxNode sn in mRoot.ChildNodes()) { if (sn is DelegateStatementSyntax) { delegates.Add(sn as DelegateStatementSyntax); } if (sn is EventBlockSyntax) { delegates2.Add(sn as EventBlockSyntax); } else if (sn is InterfaceBlockSyntax) { interfaces.Add(sn as InterfaceBlockSyntax); } if (sn is EnumBlockSyntax) { enums.Add(sn as EnumBlockSyntax); } else if (sn is StructureBlockSyntax) { structs.Add(sn as StructureBlockSyntax); } else if (sn is MethodBlockSyntax) { methods.Add(sn as MethodBlockSyntax); } else if (sn is ConstructorBlockSyntax) { constructors.Add(sn as ConstructorBlockSyntax); } else if (sn is ModuleBlockSyntax) { modules.Add(sn as ModuleBlockSyntax); } else if (sn is ClassBlockSyntax) { classes.Add(sn as ClassBlockSyntax); } else if (sn is NamespaceBlockSyntax) { namespaces.Add(sn as NamespaceBlockSyntax); } } foreach (EnumBlockSyntax ebs in enums) { //traverse enums retNS.Enums.Add(TraverseEnum(ebs)); } foreach (StructureBlockSyntax sbs in structs) { retNS.Structs.Add(TraverseStruct(sbs)); } foreach (MethodBlockSyntax mbs in methods) { bool isConstructor = false; Method tempMethod = TraverseMethod(mbs, ref isConstructor); if (isConstructor) { retNS.Constructors.Add(tempMethod as Constructor); } else { retNS.Methods.Add(tempMethod); } } foreach (ConstructorBlockSyntax css in constructors) { retNS.Constructors.Add(TraverseConstructor(css)); } foreach (ModuleBlockSyntax mbs in modules) { } foreach (ClassBlockSyntax cbs2 in classes) { retNS.Classes.Add(TraverseClass(cbs2)); } foreach (DelegateStatementSyntax dds in delegates) { //TraverseDelegate retNS.Delegates.Add(TraverseDelegate(dds)); } foreach (EventBlockSyntax ebs in delegates2) { //TraverseDelegate retNS.Delegates.Add(TraverseDelegate(ebs)); } //Next, traverse any classes foreach (ClassBlockSyntax cds in classes) { TraverseClass(cds); } foreach (InterfaceBlockSyntax ids in interfaces) { //TraverseInterface } foreach (NamespaceBlockSyntax nbs2 in namespaces) { retNS.Namespaces.Add(TraverseNamespace(nbs2)); retNS.UsingList = usingList; } return retNS; }
public Namespace TraverseTree() { Namespace retNS = new Namespace(); //Get using statements first List<UsingList> usingList = TraverseUsingList(); retNS.UsingList = usingList; //Next, traverse namespaces var ns = from aNS in mRoot.ChildNodes().OfType<NamespaceDeclarationSyntax>() select aNS; foreach (NamespaceDeclarationSyntax nds in ns) { Namespace aNS = TraverseNamespace(nds); aNS.UsingList = usingList; retNS.Namespaces.Add(aNS); } //TODO check if this needs to be declaration rather than declarator var vars = from aVar in mRoot.ChildNodes().OfType<VariableDeclaratorSyntax>() select aVar; foreach (VariableDeclaratorSyntax vds in vars) { Method tempMethod = TraverseVarDeclarators(vds); retNS.Attributes.AddRange(tempMethod.AccessedVariables); } var classes = from aClass in mRoot.ChildNodes().OfType<ClassDeclarationSyntax>() select aClass; foreach (ClassDeclarationSyntax cds in classes) { Class tempClass = TraverseClass(cds); retNS.Classes.Add(tempClass); } //public List<Class> ClassPrototypes { get; set; } var constructors = from aConstructor in mRoot.ChildNodes().OfType<ConstructorDeclarationSyntax>() select aConstructor; foreach (ConstructorDeclarationSyntax cds in constructors) { Constructor tempConstructor = TransverseConstructors(cds); retNS.Constructors.Add(tempConstructor); } var delegates = from aDelegate in mRoot.ChildNodes().OfType<DelegateDeclarationSyntax>() select aDelegate; foreach (DelegateDeclarationSyntax dds in delegates) { Model.Delegate tempDelegate = TraverseDelegates(dds); retNS.Delegates.Add(tempDelegate); } var destructors = from aDestructor in mRoot.ChildNodes().OfType<DestructorDeclarationSyntax>() select aDestructor; foreach (DestructorDeclarationSyntax dds in destructors) { Destructor tempDestructor = TransverseDestructors(dds); retNS.Destructors.Add(tempDestructor); } var enums = from aEnum in mRoot.ChildNodes().OfType<EnumDeclarationSyntax>() select aEnum; foreach (EnumDeclarationSyntax eds in enums) { Model.Enum tempEnum = TraverseEnums(eds); retNS.Enums.Add(tempEnum); } //TODO find the difference between funcdefs and methods var methods = from aMethod in mRoot.ChildNodes().OfType<MethodDeclarationSyntax>() select aMethod; foreach (MethodDeclarationSyntax mds in methods) { Method tempMethod = TransverseMethods(mds); retNS.Methods.Add(tempMethod); retNS.FunctionDefs.Add(tempMethod); } var interfaces = from aInterface in mRoot.ChildNodes().OfType<InterfaceDeclarationSyntax>() select aInterface; foreach (InterfaceDeclarationSyntax ids in interfaces) { Interface tempInterface = TraverseInterface(ids); retNS.Interfaces.Add(tempInterface); } //public List<Module> Modules { get; set; } //public string Name { get; set; } //public List<Preprocessor> Preprocessors { get; set; } //public List<Qualifiers> Qualifiers { get; set; } //public List<Struct> StructPrototypes { get; set; } var structs = from aStruct in mRoot.ChildNodes().OfType<StructDeclarationSyntax>() select aStruct; foreach (StructDeclarationSyntax sds in structs) { Struct tempStruct = TransverseStructs(sds); retNS.Structs.Add(tempStruct); } //public List<Union> Unions { get; set; } return retNS; }