public override void EnterXppclass([NotNull] XP.XppclassContext context)
        {
            ClassEntities.Push(CreateClassEntities());
            var info = AddClassInfo(context.Id.GetText());

            info.Entity   = context;
            _currentClass = info;
        }
 public XSharpTreeTransformationXPP(XSharpParser parser, CSharpParseOptions options, SyntaxListPool pool,
                                    ContextAwareSyntax syntaxFactory, string fileName) :
     base(parser, options, pool, syntaxFactory, fileName)
 {
     _classes      = new List <XppClassInfo>();
     _classstack   = new Stack <IList <XppClassInfo> >();
     _currentClass = null;
     _entryPoint   = "Main";
 }
        private XppClassInfo AddClassInfo(string name)
        {
            var classinfo = new XppClassInfo()
            {
                Name = name
            };

            _classes.Add(classinfo);
            return(classinfo);
        }
        public override void EnterXppmethod([NotNull] XP.XppmethodContext context)
        {
            Check4ClipperCC(context, context.ParamList?._Params, null, context.Type);
            CheckInitMethods(context);
            string       name;
            XppClassInfo current = null;

            if (context.ClassId == null)
            {
                current = _classes.LastOrDefault();
            }
            else
            {
                // when context contains a classname, find the right class in the list of classes
                name    = context.ClassId.GetText();
                current = FindClassInfo(name);
                if (current == null)
                {
                    context.AddError(new ParseErrorData(context, ErrorCode.ERR_XPPClassNotFound, name));
                }
                current = _classes.LastOrDefault();
            }
            current.ExternalMethods.Add(context);
            if (current != null)
            {
                // link to method
                name = context.Id.GetText();
                var decl = current.FindMethod(name);
                if (decl == null)
                {
                    decl = current.FindPropertyMethod(name);
                }
                if (decl != null)
                {
                    if (decl.IsProperty)
                    {
                        if (XSharpString.Equals(decl.AccessMethod, name))
                        {
                            decl.Entity = context;
                        }
                        if (XSharpString.Equals(decl.AssignMethod, name))
                        {
                            decl.SetEntity = context;
                        }
                    }
                    else
                    {
                        decl.Entity = context;
                    }
                    context.Info = decl;
                }
            }
        }
 internal XppDeclaredMethodInfo()
 {
     Name         = null;
     Visibility   = XP.HIDDEN;
     Entity       = null;
     Parent       = null;
     Inline       = false;
     HasVarName   = false;
     IsProperty   = false;
     AccessMethod = null;
     AssignMethod = null;
 }
        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;
        }