1// 2// Copyright (C) 2005 Stefan Seefeld 3// All rights reserved. 4// Licensed to the public under the terms of the GNU LGPL (>= 2), 5// see the file COPYING for details. 6// 7#ifndef Synopsis_TypeAnalysis_TypeEvaluator_hh_ 8#define Synopsis_TypeAnalysis_TypeEvaluator_hh_ 9 10#include <Synopsis/PTree/Visitor.hh> 11#include <Synopsis/PTree/Atoms.hh> 12#include <Synopsis/PTree/Lists.hh> 13#include <Synopsis/SymbolLookup/Scope.hh> 14#include <Synopsis/TypeAnalysis/Type.hh> 15 16namespace Synopsis 17{ 18namespace TypeAnalysis 19{ 20 21//. evaluate the type of an expression 22class TypeEvaluator : private PTree::Visitor 23{ 24public: 25 TypeEvaluator(SymbolLookup::Scope const *s) : my_scope(s) {} 26 Type const *evaluate(PTree::Node const *node); 27 28private: 29 virtual void visit(PTree::Literal *); 30 virtual void visit(PTree::Identifier *); 31 virtual void visit(PTree::Kwd::This *); 32 virtual void visit(PTree::Name *); 33 virtual void visit(PTree::FstyleCastExpr *); 34 virtual void visit(PTree::AssignExpr *); 35 virtual void visit(PTree::CondExpr *); 36 virtual void visit(PTree::InfixExpr *); 37 virtual void visit(PTree::PmExpr *); 38 virtual void visit(PTree::CastExpr *); 39 virtual void visit(PTree::UnaryExpr *); 40 virtual void visit(PTree::ThrowExpr *); 41 virtual void visit(PTree::SizeofExpr *); 42 virtual void visit(PTree::TypeidExpr *); 43 virtual void visit(PTree::TypeofExpr *); 44 virtual void visit(PTree::NewExpr *); 45 virtual void visit(PTree::DeleteExpr *); 46 virtual void visit(PTree::ArrayExpr *); 47 virtual void visit(PTree::FuncallExpr *); 48 virtual void visit(PTree::PostfixExpr *); 49 virtual void visit(PTree::DotMemberExpr *); 50 virtual void visit(PTree::ArrowMemberExpr *); 51 virtual void visit(PTree::ParenExpr *); 52 53 SymbolLookup::Scope const *my_scope; 54 Type const * my_type; 55}; 56 57inline Type const *type_of(PTree::Node const *node, 58 SymbolLookup::Scope const *s) 59{ 60 TypeEvaluator evaluator(s); 61 return evaluator.evaluate(node); 62} 63 64} 65} 66 67#endif 68