コード例 #1
0
        public override object VisitMemberDeclarationStatement([NotNull] ClepsParser.MemberDeclarationStatementContext context)
        {
            string    memberName = context.FieldName.Name.Text;
            bool      isStatic   = context.STATIC() != null;
            ClepsType memberType = Visit(context.typename()) as ClepsType;

            var oldMemberName     = CurrMemberName;
            var oldMemberIsStatic = CurrMemberIsStatic;
            var oldMemberType     = CurrMemberType;

            CurrMemberName     = memberName;
            CurrMemberIsStatic = isStatic;
            CurrMemberType     = memberType;

            if (context.rightHandExpression() != null)
            {
                Visit(context.rightHandExpression());
            }

            CurrMemberName     = oldMemberName;
            CurrMemberIsStatic = oldMemberIsStatic;
            CurrMemberType     = oldMemberType;

            return(true);
        }
コード例 #2
0
        public override object VisitMemberDeclarationStatement([NotNull] ClepsParser.MemberDeclarationStatementContext context)
        {
            string memberName = context.FieldName.Name.Text;

            ClepsClassBuilder classBuilder = ClassManager.GetClassBuilder(FullyQualifiedClassName);

            if (classBuilder == null)
            {
                //This is probably because of some earlier error. Return gracefully
                return(false);
            }

            if (classBuilder.DoesClassContainMember(memberName))
            {
                string errorMessage = String.Format("Class {0} has multiple definitions of member {1}", FullyQualifiedClassName, memberName);
                Status.AddError(new CompilerError(FileName, context.Start.Line, context.Start.Column, errorMessage));
                //Don't process this member
                return(false);
            }

            bool      isStatic   = context.STATIC() != null;
            ClepsType memberType = Visit(context.typename()) as ClepsType;

            if (memberType.IsFunctionType)
            {
                CodeGenerator.CreateMethod(FullyQualifiedClassName, isStatic, memberType, memberName);
            }

            classBuilder.AddNewMember(isStatic, memberType, memberName);
            return(true);
        }
コード例 #3
0
        public override object VisitMemberDeclarationStatement([NotNull] ClepsParser.MemberDeclarationStatementContext context)
        {
            string memberName;

            if (context.OPERATOR() == null)
            {
                memberName = context.FieldName.Name.Text;
            }
            else
            {
                memberName = context.OperatorName.GetText();
            }

            ClepsClassBuilder classBuilder = ClassManager.GetClassBuilder(FullyQualifiedClassName);

            if (classBuilder == null)
            {
                //This is probably because of some earlier error. Return gracefully
                return(false);
            }

            bool      isStatic   = context.STATIC() != null;
            ClepsType memberType = Visit(context.typename()) as ClepsType;

            string cantAddReason;

            if (!classBuilder.CanAddMemberToClass(memberName, memberType, isStatic, out cantAddReason))
            {
                Status.AddError(new CompilerError(FileName, context.Start.Line, context.Start.Column, cantAddReason));
                //Don't process this member
                return(false);
            }

            bool isConst = context.CONST() != null;

            classBuilder.AddNewMember(isStatic, new ClepsVariable(memberName, memberType, isConst));

            EntryPointManager.NewMemberSeen(FullyQualifiedClassName, memberName, memberType, isStatic);

            return(true);
        }
コード例 #4
0
        public override object VisitMemberDeclarationStatement([NotNull] ClepsParser.MemberDeclarationStatementContext context)
        {
            string memberName;

            if (context.OPERATOR() == null)
            {
                memberName = context.FieldName.Name.Text;
            }
            else
            {
                memberName = context.OperatorName.GetText();
            }

            bool      isStatic   = context.STATIC() != null;
            ClepsType memberType = Visit(context.typename()) as ClepsType;
            bool      isConst    = context.CONST() != null;

            //var oldMemberName = CurrMemberName;
            var oldMemberIsStatic = CurrMemberIsStatic;

            //var oldMemberType = CurrMemberType;

            //CurrMemberName = memberName;
            CurrMemberIsStatic = isStatic;
            //CurrMemberType = memberType;

            if (context.rightHandExpression() != null)
            {
                var expressionValue = Visit(context.rightHandExpression());

                //if(!memberType.IsFunctionType)
                {
                    IValue         expressionRegister = expressionValue as IValue;
                    IValueRegister targetRegister;
                    IMethodValue   initializerMethod;

                    if (isStatic)
                    {
                        initializerMethod = CodeGenerator.GetClassStaticInitializerRegister(FullyQualifiedClassName);
                        targetRegister    = CodeGenerator.GetStaticFieldRegister(FullyQualifiedClassName, memberName, memberType);
                    }
                    else
                    {
                        if (isConst)
                        {
                            initializerMethod = CodeGenerator.GetGlobalInitializerRegister();
                            targetRegister    = CodeGenerator.GetConstantMemberFieldRegisterForWrite(FullyQualifiedClassName, memberName, memberType);
                        }
                        else
                        {
                            initializerMethod = CodeGenerator.GetClassInitializerRegister(FullyQualifiedClassName);
                            targetRegister    = CodeGenerator.GetMemberFieldRegisterFromSameClass(FullyQualifiedClassName, memberName, memberType);
                        }
                    }

                    initializerMethod.CreateAssignment(targetRegister, expressionRegister);
                }
            }

            //CurrMemberName = oldMemberName;
            CurrMemberIsStatic = oldMemberIsStatic;
            //CurrMemberType = oldMemberType;

            return(true);
        }