Added RootScopes for AST roots.
2 * Copyright (C) 2012 David Anderson
4 * This file is part of JITCraft.
6 * JITCraft is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 3 of the License, or (at your option)
11 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * JITCraft. If not, see http://www.gnu.org/licenses/.
18 #ifndef _include_semantic_analysis_h_
19 #define _include_semantic_analysis_h_
26 class SemanticAnalysis : public AstVisitor
35 bool canTest(AstNode *node, Type *type);
36 void unaryTypeError(AstNode *node, TokenKind token, Type *type);
37 void binaryTypeError(AstNode *node, TokenKind token, Type *left, Type *right);
38 Type *typeCheckBinary(AstNode *node, TokenKind token, Type *left, Type *right);
40 // These check if one type is compatible with another type, for various
42 // return (expr) matches function return type
43 // call(a, b) matches expected arg type
44 // a = b matches declared type
46 bool typeCheckArrayAssignment(AstNode *node, Type *given, Type *actual, bool forAssign);
47 bool typeCheckAssignment(AstNode *node, Type *given, Type *actual, bool forAssign);
49 bool typeCheckParameter(AstNode *node, Type *given, Type *actual);
51 Type *visitForLoad(Expression *expression);
52 Type *visitForRef(Expression *expression);
53 bool preanalyze(FunctionStatement *node);
54 Type *visitForLValue(Expression *expression);
55 Type *visitAndApplyType(Expression *expression);
58 SemanticAnalysis(CompileContext &cc, ParseTree *tree);
62 void visit(NameProxy *name);
63 void visit(Assignment *node);
64 void visit(BinaryExpression *node);
65 void visit(ReturnStatement *node);
66 void visit(ForStatement *node);
67 void visit(BlockStatement *node);
68 void visit(VariableDeclaration *node);
69 void visit(IntegerLiteral *node);
70 void visit(ExpressionStatement *node);
71 void visit(FunctionStatement *node);
72 void visit(CallExpression *node);
73 void visit(IfStatement *node);
74 void visit(IndexExpression *node);
75 void visit(EnumStatement *node);
76 void visit(FloatLiteral *node);
77 void visit(WhileStatement *node);
78 void visit(BreakStatement *node);
79 void visit(ContinueStatement *node);
80 void visit(StringLiteral *node);
81 void visit(IncDecExpression *node);
86 #endif // _include_semantic_analysis_h_