Add some more API.
1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of JITCraft.
7 * JITCraft is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 3 of the License, or (at your option)
12 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with
17 * JITCraft. If not, see http://www.gnu.org/licenses/.
19 #ifndef _include_semantic_analysis_h_
20 #define _include_semantic_analysis_h_
27 class SemanticAnalysis : public AstVisitor
34 ScopedRoot<Type> function_;
37 bool canTest(AstNode *node, Handle<Type> type);
38 void unaryTypeError(AstNode *node, TokenKind token, Handle<Type> type);
39 void binaryTypeError(AstNode *node, TokenKind token, Handle<Type> left, Handle<Type> right);
40 Type *typeCheckBinary(AstNode *node, TokenKind token, Handle<Type> left, Handle<Type> right);
42 // These check if one type is compatible with another type, for various
44 // return (expr) matches function return type
45 // call(a, b) matches expected arg type
46 // a = b matches declared type
48 bool typeCheckArrayAssignment(AstNode *node, Handle<Type> given, Handle<Type> actual, bool forAssign);
49 bool typeCheckAssignment(AstNode *node, Handle<Type> given, Handle<Type> actual, bool forAssign);
51 bool typeCheckParameter(AstNode *node, Handle<Type> given, Handle<Type> actual);
53 Type *visitForLoad(Expression *expression);
54 Type *visitForRef(Expression *expression);
55 bool preanalyze(FunctionStatement *node);
56 Type *visitForLValue(Expression *expression);
57 Type *visitAndApplyType(Expression *expression);
60 SemanticAnalysis(Zone *zone, CompileContext &cc, ParseTree *tree);
64 void visit(NameProxy *name);
65 void visit(Assignment *node);
66 void visit(BinaryExpression *node);
67 void visit(ReturnStatement *node);
68 void visit(ForStatement *node);
69 void visit(BlockStatement *node);
70 void visit(VariableDeclaration *node);
71 void visit(IntegerLiteral *node);
72 void visit(ExpressionStatement *node);
73 void visit(FunctionStatement *node);
74 void visit(CallExpression *node);
75 void visit(IfStatement *node);
76 void visit(IndexExpression *node);
77 void visit(EnumStatement *node);
78 void visit(FloatLiteral *node);
79 void visit(WhileStatement *node);
80 void visit(BreakStatement *node);
81 void visit(ContinueStatement *node);
82 void visit(StringLiteral *node);
83 void visit(IncDecExpression *node);
88 #endif // _include_semantic_analysis_h_