Пример #1
0
        public override bool Visit(AstClassMethod node)
        {
            var stmts = node.StatementsBlock.Statements.Statements;

            var validCodepaths = CheckStmtsHasReturn(stmts);
            if (!validCodepaths)
            {
                DispatchError(node.TextPosition, "Not all code paths return a value");
                return false;
            }

            return true;
        }
        public override bool Visit(AstClassMethod node)
        {
            table.UseNamedChildScope(node.Name.Id);

            var argumentsTypes = new List<string>();
            foreach (var argDef in node.ArgumentsDefinition.ArgumentsDefinition)
            {
                argumentsTypes.Add(argDef.TypeDef.Id);
                table.EnterSymbol(argDef.Name.Id, argDef.TypeDef.Id, null);
            }

            table.UseParentScope();

            var entryPoint = node.Name.Id == "Main";
            table.EnterFunction("", node.Name.Id, node.TypeDef.Id, argumentsTypes, entryPoint);

            return true;
        }
 public override bool Visit(AstClassMethod node)
 {
     ErrorIfIsNull(node.ArgumentsDefinition);
     ErrorIfIsNull(node.Name);
     ErrorIfIsNull(node.StatementsBlock);
     ErrorIfIsNull(node.TypeDef);
     return true;
 }
Пример #4
0
        // #METHOD_DECLARATION #METHOD_HEADER BLOCK_START #STATEMENTS_BLOCK BLOCK_END
        private void ConstructMethodDeclaration()
        {
            var statementsBlock = nodes.Pop() as AstStatementsBlock;

            var argumentsDefList = nodes.Pop() as AstArgumentsDefList;
            var name = nodes.Pop() as AstIdExpression;
            var typeDef = nodes.Pop() as AstIdExpression;
            var staticMod = nodes.Pop() as AstStaticModifier;
            var visibilityMod = nodes.Pop() as AstVisibilityModifier;

            var method = new AstClassMethod(
                visibilityMod,
                staticMod,
                typeDef,
                name,
                argumentsDefList,
                statementsBlock
            );
            PushNode(method);
        }
Пример #5
0
        public override bool Visit(AstClassMethod node)
        {
            table.UseNamedChildScope(node.Name.Id);

            ResetUnnamedVariable();
            var isEntryPoint = node.Name.Id == "Main";
            var name = isEntryPoint ? "main" : node.Name.Id;
            codeStream.Write("define " + GetLLVMType(node.TypeDef.Id) + " @" + name);

            currReturnType = GetLLVMType(node.TypeDef.Id);
            node.ArgumentsDefinition.Accept(this);

            if (isEntryPoint)
            {
                InitStringFields();
                CallRandomize();
            }

            node.StatementsBlock.Accept(this);
            var type = GetLLVMType(node.TypeDef.Id);
            var fakeRetVal = GetDefaultTypeValue(node.TypeDef);
            codeStream.WriteLine("ret " + type + " " + fakeRetVal);//fake return for
            codeStream.WriteLine("}");

            table.UseParentScope();

            return false;
        }
 public override bool Visit(AstClassMethod node)
 {
     return true;
 }
Пример #7
0
        public override bool Visit(AstClassMethod node)
        {
            table.UseNamedChildScope(node.Name.Id);
            currFunctionReturnType = node.TypeDef.Id;

            node.Visibility.Accept(this);
            node.Static.Accept(this);
            node.TypeDef.Accept(this);
            node.Name.Accept(this);
            node.ArgumentsDefinition.Accept(this);

            currStateInsideExpr = true;
            node.StatementsBlock.Accept(this);
            currStateInsideExpr = false;

            return true;
        }
Пример #8
0
 public abstract bool Visit(AstClassMethod node);