public override void EnterXppclass([NotNull] XP.XppclassContext context) { ClassEntities.Push(CreateClassEntities()); var info = AddClassInfo(context.Id.GetText()); info.Entity = context; _currentClass = info; }
public override void ExitXppclass([NotNull] XP.XppclassContext context) { context.SetSequencePoint(context.C, context.e.Stop); var members = _pool.Allocate <MemberDeclarationSyntax>(); var generated = ClassEntities.Pop(); var mods = context.Modifiers?.GetList <SyntaxToken>() ?? TokenListWithDefaultVisibility(); XP.DatatypeContext basetype = null; if (generated.Members.Count > 0) // inline methods, properties and fields { members.AddRange(generated.Members); } if (context.Modifiers != null) { if (context.Modifiers._Tokens.Any(t => t.Type == XP.STATIC)) { context.Data.HasStatic = true; } } // check if all declared methods have been implemented // and if so, then add the methods to the members list string className = context.Id.GetText(); if (context._BaseTypes.Count == 1) { basetype = context._BaseTypes[0]; } XppClassInfo thisClass = FindClassInfo(className); if (thisClass == null || thisClass.Entity != context) { context.AddError(new ParseErrorData(context, ErrorCode.ERR_ParserError, "Could not locate ClassInfo for class " + className)); return; } generated.Free(); var baseTypes = _pool.AllocateSeparated <BaseTypeSyntax>(); var baseType = basetype.Get <TypeSyntax>(); if (baseType != null) { baseTypes.Add(_syntaxFactory.SimpleBaseType(baseType)); } foreach (var iCtx in context._Implements) { if (baseTypes.Count > 0) { baseTypes.AddSeparator(SyntaxFactory.MakeToken(SyntaxKind.CommaToken)); } baseTypes.Add(_syntaxFactory.SimpleBaseType(iCtx.Get <TypeSyntax>())); } MemberDeclarationSyntax m = _syntaxFactory.ClassDeclaration( attributeLists: context.Attributes?.GetList <AttributeListSyntax>() ?? EmptyList <AttributeListSyntax>(), modifiers: mods, keyword: SyntaxFactory.MakeToken(SyntaxKind.ClassKeyword), identifier: context.Id.Get <SyntaxToken>(), typeParameterList: null, baseList: _syntaxFactory.BaseList(SyntaxFactory.MakeToken(SyntaxKind.ColonToken), baseTypes), constraintClauses: null, openBraceToken: SyntaxFactory.MakeToken(SyntaxKind.OpenBraceToken), members: members, closeBraceToken: SyntaxFactory.MakeToken(SyntaxKind.CloseBraceToken), semicolonToken: null); _pool.Free(members); _pool.Free(baseTypes); context.Put(m); _currentClass = null; }