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