/*
 * Copyright (C) 2012 David Anderson
 *
 * This file is part of JITCraft.
 *
 * JITCraft is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 * 
 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * JITCraft. If not, see http://www.gnu.org/licenses/.
 */
#ifndef _include_semantic_analysis_h_
#define _include_semantic_analysis_h_

#include <assert.h>
#include "AST.h"

namespace jc {

class SemanticAnalysis : public AstVisitor
{
    ParseTree *tree_;
    unsigned loopDepth_;
    Scope *scope_;

  private:
    void error() {
        assert(false);
    }
    void typeError(Expression *expr, const char *expected) {
        assert(false);
    }
    Type *visitForLoad(Expression *expression);
    Type *visitForRef(Expression *expression);
    bool preanalyze(FunctionStatement *node);

  public:
    SemanticAnalysis(ParseTree *tree);
    bool analyze();

  public:
    void visit(NameProxy *name);
    void visit(Assignment *node);
    void visit(BinaryExpression *node);
    void visit(ReturnStatement *node);
    void visit(ForStatement *node);
    void visit(BlockStatement *node);
    void visit(VariableDeclaration *node);
    void visit(IntegerLiteral *node);
    void visit(ExpressionStatement *node);
    void visit(FunctionStatement *node);
    void visit(CallExpression *node);
    void visit(IfStatement *node);
    void visit(IndexExpression *node);
    void visit(EnumStatement *node);
    void visit(FloatLiteral *node);
    void visit(WhileStatement *node);
    void visit(BreakStatement *node);
    void visit(ContinueStatement *node);
};

} // namespace jc

#endif // _include_semantic_analysis_h_
