Exemple #1
0
        public override LLVMRegister VisitMemberOperatorFunctionDeclarationStatement([NotNull] ClepsParser.MemberOperatorFunctionDeclarationStatementContext context)
        {
            bool isStatic = context.STATIC() != null;

            ClepsParser.TypenameContext returnTypeContext = context.operatorFunctionDeclarationStatment().FunctionReturnType;
            ClepsType clepsReturnType = ClepsType.GetBasicType(returnTypeContext);

            ClepsParser.FunctionParametersListContext parametersContext = context.operatorFunctionDeclarationStatment().functionParametersList();
            string functionName = context.operatorFunctionDeclarationStatment().FunctionName.GetText();

            return(VisitFunctionDeclarationBody(context, clepsReturnType, parametersContext, functionName, isStatic));
        }
Exemple #2
0
        public override int VisitMemberOperatorFunctionDeclarationStatement([NotNull] ClepsParser.MemberOperatorFunctionDeclarationStatementContext context)
        {
            bool   isStatic = context.STATIC() != null;
            var    assignmentFunctionDeclarationStatement = context.operatorFunctionDeclarationStatment();
            string functionName = assignmentFunctionDeclarationStatement.FunctionName.GetText();

            ClepsParser.TypenameContext functionReturnContext = assignmentFunctionDeclarationStatement.FunctionReturnType;
            ClepsType clepsReturnType = ClepsType.GetBasicType(functionReturnContext);

            ClepsParser.FunctionParametersListContext parameterContext = assignmentFunctionDeclarationStatement.functionParametersList();
            var ret = GenerateMemberFunction(context, isStatic, functionName, clepsReturnType, parameterContext);

            return(ret);
        }
Exemple #3
0
        public override int VisitMemberVariableDeclarationStatement([NotNull] ClepsParser.MemberVariableDeclarationStatementContext context)
        {
            string className    = String.Join(".", CurrentNamespaceAndClass);
            bool   isStatic     = context.STATIC() != null;
            string variableName = context.FieldName.Name.Text;

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

            ClepsParser.TypenameContext variableTypeContext = context.typename();
            ClepsType clepsVariableType = ClepsType.GetBasicType(variableTypeContext);

            // only static members are defined immediately. member variables are defined at the at end of parsing a class
            if (isStatic)
            {
                string      fullyQualifiedName = String.Format("{0}.{1}", className, variableName);
                LLVMTypeRef?llvmMemberType     = ClepsLLVMTypeConvertorInst.GetLLVMTypeOrNull(clepsVariableType);

                if (llvmMemberType == null)
                {
                    string errorMessage = String.Format("Type {0} was not found", clepsVariableType.GetTypeName());
                    Status.AddError(new CompilerError(FileName, context.Start.Line, context.Start.Column, errorMessage));
                    return(-1);
                }

                LLVM.AddGlobal(Module, llvmMemberType.Value, fullyQualifiedName);
            }

            ClassManager.AddNewMember(className, variableName, isStatic, clepsVariableType);
            return(0);
        }
Exemple #4
0
        public static ClepsType GetBasicType(ClepsParser.TypenameContext typeContext)
        {
            List <uint> arrayDimensions = typeContext._ArrayDimensions.Select(n => uint.Parse(n.GetText())).ToList();

            return(GetBasicType(typeContext.RawTypeName.GetText(), arrayDimensions, typeContext._PtrIndirectionLevel.Count));
        }
Exemple #5
0
 public static ClepsType GetBasicType(ClepsParser.TypenameContext typeContext)
 {
     return(GetBasicType(typeContext.RawTypeName.GetText(), typeContext._PtrIndirectionLevel.Count));
 }