[51b7345] | 1 | /* |
---|
| 2 | * This file is part of the Cforall project |
---|
| 3 | * |
---|
| 4 | * $Id: AlternativeFinder.h,v 1.19 2005/08/29 20:14:15 rcbilson Exp $ |
---|
| 5 | * |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #ifndef RESOLVEXPR_ALTERNATIVEFINDER_H |
---|
| 9 | #define RESOLVEXPR_ALTERNATIVEFINDER_H |
---|
| 10 | |
---|
| 11 | #include <set> |
---|
| 12 | |
---|
| 13 | #include "Alternative.h" |
---|
| 14 | #include "Unify.h" |
---|
| 15 | #include "SynTree/SynTree.h" |
---|
| 16 | #include "SymTab/Indexer.h" |
---|
| 17 | #include "SynTree/TypeSubstitution.h" |
---|
| 18 | |
---|
| 19 | namespace ResolvExpr { |
---|
| 20 | |
---|
| 21 | class AlternativeFinder : public Visitor |
---|
| 22 | { |
---|
| 23 | public: |
---|
| 24 | AlternativeFinder( const SymTab::Indexer &indexer, const TypeEnvironment &env ); |
---|
| 25 | void find( Expression *expr, bool adjust = false ); |
---|
| 26 | void findWithAdjustment( Expression *expr ); |
---|
| 27 | AltList &get_alternatives() { return alternatives; } |
---|
| 28 | |
---|
| 29 | // make this look like an STL container so that we can apply generic algorithms |
---|
| 30 | typedef Alternative value_type; |
---|
| 31 | typedef AltList::iterator iterator; |
---|
| 32 | typedef AltList::const_iterator const_iterator; |
---|
| 33 | AltList::iterator begin() { return alternatives.begin(); } |
---|
| 34 | AltList::iterator end() { return alternatives.end(); } |
---|
| 35 | AltList::const_iterator begin() const { return alternatives.begin(); } |
---|
| 36 | AltList::const_iterator end() const { return alternatives.end(); } |
---|
| 37 | |
---|
| 38 | const SymTab::Indexer &get_indexer() const { return indexer; } |
---|
| 39 | const TypeEnvironment &get_environ() const { return env; } |
---|
| 40 | private: |
---|
| 41 | virtual void visit(ApplicationExpr *applicationExpr); |
---|
| 42 | virtual void visit(UntypedExpr *untypedExpr); |
---|
| 43 | virtual void visit(AddressExpr *addressExpr); |
---|
| 44 | virtual void visit(CastExpr *castExpr); |
---|
| 45 | virtual void visit(UntypedMemberExpr *memberExpr); |
---|
| 46 | virtual void visit(MemberExpr *memberExpr); |
---|
| 47 | virtual void visit(NameExpr *variableExpr); |
---|
| 48 | virtual void visit(VariableExpr *variableExpr); |
---|
| 49 | virtual void visit(ConstantExpr *constantExpr); |
---|
| 50 | virtual void visit(SizeofExpr *sizeofExpr); |
---|
| 51 | virtual void visit(AttrExpr *attrExpr); |
---|
| 52 | virtual void visit(LogicalExpr *logicalExpr); |
---|
| 53 | virtual void visit(ConditionalExpr *conditionalExpr); |
---|
| 54 | virtual void visit(CommaExpr *commaExpr); |
---|
| 55 | virtual void visit(TupleExpr *tupleExpr); |
---|
| 56 | public: // xxx - temporary hack - should make Tuples::TupleAssignment a friend |
---|
| 57 | template< typename InputIterator, typename OutputIterator > |
---|
| 58 | void findSubExprs( InputIterator begin, InputIterator end, OutputIterator out ); |
---|
| 59 | |
---|
| 60 | private: |
---|
| 61 | template< typename StructOrUnionType > void addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const std::string &name ); |
---|
| 62 | bool instantiateFunction( std::list< DeclarationWithType* >& formals, /*const*/ AltList &actuals, bool isVarArgs, OpenVarSet& openVars, TypeEnvironment &resultEnv, AssertionSet &resultNeed, AssertionSet &resultHave ); |
---|
| 63 | template< typename OutputIterator > |
---|
| 64 | void makeFunctionAlternatives( const Alternative &func, FunctionType *funcType, AltList &actualAlt, OutputIterator out ); |
---|
| 65 | template< typename OutputIterator > |
---|
| 66 | void inferParameters( const AssertionSet &need, AssertionSet &have, const Alternative &newAlt, OpenVarSet &openVars, OutputIterator out ); |
---|
| 67 | void resolveAttr( DeclarationWithType *funcDecl, FunctionType *function, Type *argType, const TypeEnvironment &env ); |
---|
| 68 | |
---|
| 69 | const SymTab::Indexer &indexer; |
---|
| 70 | AltList alternatives; |
---|
| 71 | const TypeEnvironment &env; |
---|
| 72 | }; |
---|
| 73 | |
---|
| 74 | Expression *resolveInVoidContext( Expression *expr, const SymTab::Indexer &indexer, TypeEnvironment &env ) |
---|
| 75 | ; |
---|
| 76 | |
---|
| 77 | } // namespace ResolvExpr |
---|
| 78 | |
---|
| 79 | #endif /* #ifndef RESOLVEXPR_ALTERNATIVEFINDER_H */ |
---|