jitcraft/SemanticAnalysis.h
author David Anderson <dvander@alliedmods.net>
Thu Jun 28 01:38:56 2012 -0700 (2012-06-28)
changeset 10 0c3bcd50e361
parent 9 73781c5a59d7
child 12 75e385f68b7e
permissions -rw-r--r--
Implemented break and continue support.
     1 /*
     2  * Copyright (C) 2012 David Anderson
     3  *
     4  * This file is part of JITCraft.
     5  *
     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)
     9  * any later version.
    10  * 
    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.
    14  *
    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/.
    17  */
    18 #ifndef _include_semantic_analysis_h_
    19 #define _include_semantic_analysis_h_
    20 
    21 #include <assert.h>
    22 #include "AST.h"
    23 
    24 namespace jc {
    25 
    26 class SemanticAnalysis : public AstVisitor
    27 {
    28     ParseTree *tree_;
    29     unsigned loopDepth_;
    30 
    31   private:
    32     void error() {
    33         assert(false);
    34     }
    35     void typeError(Expression *expr, const char *expected) {
    36         assert(false);
    37     }
    38     Type *visitForLoad(Expression *expression);
    39     Type *visitForRef(Expression *expression);
    40 
    41   public:
    42     SemanticAnalysis(ParseTree *tree);
    43     bool analyze();
    44 
    45   public:
    46     void visit(NameProxy *name);
    47     void visit(Assignment *node);
    48     void visit(BinaryExpression *node);
    49     void visit(ReturnStatement *node);
    50     void visit(ForStatement *node);
    51     void visit(BlockStatement *node);
    52     void visit(VariableDeclaration *node);
    53     void visit(IntegerLiteral *node);
    54     void visit(ExpressionStatement *node);
    55     void visit(FunctionStatement *node);
    56     void visit(CallExpression *node);
    57     void visit(IfStatement *node);
    58     void visit(IndexExpression *node);
    59     void visit(EnumStatement *node);
    60     void visit(FloatLiteral *node);
    61     void visit(WhileStatement *node);
    62     void visit(BreakStatement *node);
    63     void visit(ContinueStatement *node);
    64 };
    65 
    66 } // namespace jc
    67 
    68 #endif // _include_semantic_analysis_h_