private void CreateAssignment(IValueRegister register, ClepsParser.RightHandExpressionContext rightHandExpression)
        {
            IValue value = Visit(rightHandExpression) as IValue;

            if (register.ExpressionType == value.ExpressionType && CompilerConstants.SystemSupportedTypes.Contains(register.ExpressionType))
            {
                CurrMethodGenerator.CreateAssignment(register, value);
            }
            else
            {
                throw new NotImplementedException("assignment for non byte types not supported yet");
            }
        }
Exemplo n.º 2
0
        private void ParseFilesWithGenerator(ClepsAbstractVisitor generator, CompileStatus status)
        {
            foreach (string fileName in Args.Files)
            {
                LexerParserErrorHandler lexerParserErrorHandler = new LexerParserErrorHandler(fileName, status);
                var data = File.ReadAllText(fileName);

                AntlrInputStream  s      = new AntlrInputStream(data);
                ClepsLexer        lexer  = new ClepsLexer(s);
                CommonTokenStream tokens = new CommonTokenStream(lexer);
                ClepsParser       parser = new ClepsParser(tokens);

                parser.RemoveErrorListeners();
                parser.AddErrorListener(lexerParserErrorHandler);
                var parsedFile = parser.compilationUnit();

                generator.ParseFile(fileName, parsedFile);
            }
        }
Exemplo n.º 3
0
        private void ParseFilesWithGenerator(ClepsAbstractVisitor generator, CompileStatus status)
        {
            foreach (string fileName in Args.Files)
            {
                LexerParserErrorHandler lexerParserErrorHandler = new LexerParserErrorHandler(fileName, status);
                var data = File.ReadAllText(fileName);

                AntlrInputStream s = new AntlrInputStream(data);
                ClepsLexer lexer = new ClepsLexer(s);
                CommonTokenStream tokens = new CommonTokenStream(lexer);
                ClepsParser parser = new ClepsParser(tokens);

                parser.RemoveErrorListeners();
                parser.AddErrorListener(lexerParserErrorHandler);
                var parsedFile = parser.compilationUnit();

                generator.ParseFile(fileName, parsedFile);
            }
        }
Exemplo n.º 4
0
        public static ClepsType GetBasicOrVoidType(ClepsParser.TypenameAndVoidContext typenameAndVoidContext)
        {
            if(typenameAndVoidContext.VOID() != null)
            {
                return GetVoidType();
            }

            return GetBasicType(typenameAndVoidContext.typename());
        }
Exemplo n.º 5
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);
 }
        private IValue doFunctionCall(ClepsParser.FunctionCallContext functionCall, ClepsType targetType, bool isMemberFunctionsAccessible, bool allowVoidReturn)
        {
            ClepsClass targetClepsClass;
            
            if(targetType is BasicClepsType)
            {
                targetClepsClass = ClassManager.GetClass(targetType.GetClepsTypeString());
            }
            else if(targetType is BasicStaticClepsType)
            {
                targetClepsClass = ClassManager.GetClass(targetType.GetClepsTypeString());
                isMemberFunctionsAccessible = false;
            }
            else
            {
                throw new NotImplementedException("Function calls on non basic types not supported");
            }

            string targetFunctionName = functionCall.FunctionName.GetText();
            List<IValue> parameters = functionCall._FunctionParameters.Select(p => Visit(p) as IValue).ToList();

            ClepsType functionType = null;
            if (targetClepsClass.StaticMemberMethods.ContainsKey(targetFunctionName))
            {
                functionType = targetClepsClass.StaticMemberMethods[targetFunctionName];
            }
            else if (isMemberFunctionsAccessible && targetClepsClass.MemberMethods.ContainsKey(targetFunctionName))
            {
                functionType = targetClepsClass.MemberMethods[targetFunctionName];
            }

            if (functionType == null)
            {
                string errorMessage = String.Format("Class {0} does not contain a function called {1}", targetClepsClass.FullyQualifiedName, targetFunctionName);
                Status.AddError(new CompilerError(FileName, functionCall.Start.Line, functionCall.Start.Column, errorMessage));
                //Just return something to avoid stalling compilation
                return CodeGenerator.CreateByte(0);
            }

            List<ClepsType> functionOverloads = new List<ClepsType> { functionType };

            int matchedPosition;
            string fnMatchErrorMessage;

            if (!FunctionOverloadManager.FindMatchingFunctionType(functionOverloads, parameters, out matchedPosition, out fnMatchErrorMessage))
            {
                Status.AddError(new CompilerError(FileName, functionCall.Start.Line, functionCall.Start.Column, fnMatchErrorMessage));
                //Just return something to avoid stalling compilation
                return CodeGenerator.CreateByte(0);
            }

            FunctionClepsType chosenFunctionType = functionOverloads[matchedPosition] as FunctionClepsType;

            if (!allowVoidReturn && chosenFunctionType.ReturnType == VoidType.GetVoidType())
            {
                string errorMessage = String.Format("Function {0} does not return a value", targetFunctionName);
                Status.AddError(new CompilerError(FileName, functionCall.Start.Line, functionCall.Start.Column, errorMessage));
                //Just return something to avoid stalling compilation
                return CodeGenerator.CreateByte(0);
            }

            IValue returnValue = CodeGenerator.GetFunctionCallReturnValue(FullyQualifiedClassName, targetFunctionName, chosenFunctionType, parameters);
            return returnValue;
        }
        private void CreateAssignment(IValueRegister register, ClepsParser.RightHandExpressionContext rightHandExpression)
        {
            IValue value = Visit(rightHandExpression) as IValue;

            if (register.ExpressionType == value.ExpressionType && register.ExpressionType == CompilerConstants.ClepsByteType)
            {
                IMethodRegister methodRegister = CodeGenerator.GetMethodRegister(FullyQualifiedClassName, CurrMemberIsStatic, CurrMemberType, CurrMemberName);
                methodRegister.CreateAssignment(register, value);
            }
            else
            {
                throw new NotImplementedException("assignment for non byte types not supported yet");
            }
        }