private void addFields(XCodeTypeDeclaration newClass, XSharpParserRuleContext context) { if (FieldList.ContainsKey(context)) { var fields = FieldList[context]; foreach (var f in fields) { newClass.Members.Add(f); var xtype = findType(f.Type.BaseType); if (xtype != null) { addClassMember(new XMemberType(f.Name, MemberTypes.Field, false, xtype.FullName)); } else { addClassMember(new XMemberType(f.Name, MemberTypes.Field, false, f.Type.BaseType)); } } } }
public override void EnterStructure_(XSharpParser.Structure_Context context) { XCodeTypeDeclaration newClass = new XCodeTypeDeclaration(context.Id.GetCleanText()); // Set as Current working Class CurrentClass = newClass; if (context.Attributes != null) { newClass.CustomAttributes = GenerateAttributes(context.Attributes); } // and push into the Namespace CurrentNamespace.Types.Add(newClass); // That's a Class newClass.IsStruct = true; writeTrivia(newClass, context); // if (context.Modifiers == null) { newClass.TypeAttributes = System.Reflection.TypeAttributes.Public; } else { // Modifiers foreach (var t in context.Modifiers._Tokens) { switch (t.Type) { case XSharpParser.PARTIAL: newClass.IsPartial = true; break; case XSharpParser.SEALED: newClass.Attributes |= MemberAttributes.Final; break; case XSharpParser.ABSTRACT: newClass.Attributes |= MemberAttributes.Abstract; break; case XSharpParser.INTERNAL: newClass.Attributes |= MemberAttributes.Assembly; break; case XSharpParser.PUBLIC: newClass.Attributes |= MemberAttributes.Public; break; } } // What Visibility ? newClass.TypeAttributes = ContextToStructureModifiers(context.Modifiers); } // IMPLEMENTS ? if ((context._Implements != null) && (context._Implements.Count > 0)) { foreach (var interfaces in context._Implements) { var ifName = interfaces.GetCleanText(); newClass.BaseTypes.Add(BuildTypeReference(ifName)); } } // // Add the variables from this class to the Members collection and lookup table ClearMembers(); if (FieldList.ContainsKey(context)) { var fields = FieldList[context]; foreach (var f in fields) { newClass.Members.Add(f); addClassMember(new XMemberType(f.Name, MemberTypes.Field, false, findType(f.Type.BaseType), f.Type.BaseType)); } } var token = context.Stop as XSharpToken; var tokenIndex = token.OriginalTokenIndex; var line = token.Line; for (;;) { if (tokenIndex >= _tokens.Count - 1) { break; } tokenIndex++; if (_tokens[tokenIndex].Line > line) { break; } } }