public override void ExitXppclassvars([NotNull] XP.XppclassvarsContext context) { // add class vars to current class // use the current visibility saved with declMethodVis // IS and IN are not supported, so produce warning // include [SHARED], [READONLY] [ASSIGNMENT HIDDEN | PROTECTED | EXPORTED] and [NOSAVE] modifiers // on top of the visibility modifier // The [Readonly] clause and [Assignment] clause are not supported yet // In as future build we will create a private backing Ivar and // Create a property with Getter and Setter with property visibility // to emulate the possible combinations of [ReadOnly] and Assignment and Visibility // The following table lists what should be done // ========================================================================. // | Visibility | // Assignment | Hidden | Protected | Exported | // ========================================================================. // Hidden | pri Get/pri Set | pro Get pri Set | pub Get pri Set | // Protected | | pro Get pro Set | pub Get pro Set | // Exported | - | | pub Get pub Set | // ========================================================================. // // The Readonly clause does something similar as the ASSIGNMENT. // For the following visibilities this results in: // Private Readonly is useless // Protected Readonly creates a Protected Getter and a hidden/Private Setter // Exported/Public ReadOnly creates a Public Getter and a Protected Setter // var varList = _pool.AllocateSeparated <VariableDeclaratorSyntax>(); // Check to see if the variables have not been also declared as property // when they are we do not generate variables var varType = context.DataType?.Get <TypeSyntax>() ?? _getMissingType(); varType.XVoDecl = true; var fieldList = new List <FieldDeclarationSyntax>(); var attributeLists = _pool.Allocate <AttributeListSyntax>(); if (context.Nosave != null) { GenerateAttributeList(attributeLists, SystemQualifiedNames.NonSerialized); } foreach (var id in context._Vars) { varList.Clear(); var name = id.GetText(); var variable = GenerateVariable(id.Get <SyntaxToken>()); varList.Add(variable); // calculate modifiers // each field is added separately so we can later decide which field to keep and which one to delete when they are duplicated by a var modifiers = decodeXppMemberModifiers(context.Visibility, false, context.Modifiers?._Tokens); if (varList.Count > 0) { var decl = _syntaxFactory.VariableDeclaration( type: varType, variables: varList); var fdecl = _syntaxFactory.FieldDeclaration( attributeLists: attributeLists, modifiers: modifiers, declaration: decl, semicolonToken: SyntaxFactory.MakeToken(SyntaxKind.SemicolonToken)); ClassEntities.Peek().Members.Add(fdecl); fieldList.Add(fdecl); } } context.PutList(MakeList <FieldDeclarationSyntax>(fieldList)); _pool.Free(varList); _pool.Free(attributeLists); }
public override void EnterXppclassvars([NotNull] XP.XppclassvarsContext context) { context.Visibility = _currentClass.CurrentVisibility; }