[51b7345] | 1 | #ifndef SYMTAB_MANGLER_H |
---|
| 2 | #define SYMTAB_MANGLER_H |
---|
| 3 | |
---|
| 4 | #include <strstream> |
---|
| 5 | #include "SynTree/SynTree.h" |
---|
| 6 | #include "SynTree/Visitor.h" |
---|
| 7 | |
---|
| 8 | namespace SymTab { |
---|
[ea3eb06] | 9 | class Mangler : public Visitor { |
---|
| 10 | public: |
---|
| 11 | template< typename SynTreeClass > |
---|
| 12 | static std::string mangle( SynTreeClass *decl ); // interface to clients |
---|
[51b7345] | 13 | |
---|
| 14 | /// using Visitor::visit; |
---|
[ea3eb06] | 15 | virtual void visit( ObjectDecl *declaration ); |
---|
| 16 | virtual void visit( FunctionDecl *declaration ); |
---|
| 17 | virtual void visit( TypeDecl *declaration ); |
---|
| 18 | |
---|
| 19 | virtual void visit( VoidType *voidType ); |
---|
| 20 | virtual void visit( BasicType *basicType ); |
---|
| 21 | virtual void visit( PointerType *pointerType ); |
---|
| 22 | virtual void visit( ArrayType *arrayType ); |
---|
| 23 | virtual void visit( FunctionType *functionType ); |
---|
| 24 | virtual void visit( StructInstType *aggregateUseType ); |
---|
| 25 | virtual void visit( UnionInstType *aggregateUseType ); |
---|
| 26 | virtual void visit( EnumInstType *aggregateUseType ); |
---|
| 27 | virtual void visit( TypeInstType *aggregateUseType ); |
---|
| 28 | virtual void visit( TupleType *tupleType ); |
---|
[51b7345] | 29 | |
---|
[ea3eb06] | 30 | std::string get_mangleName() { return std::string( mangleName.str(), mangleName.pcount() ); } |
---|
| 31 | private: |
---|
| 32 | std::ostrstream mangleName; |
---|
| 33 | typedef std::map< std::string, std::pair< int, int > > VarMapType; |
---|
| 34 | VarMapType varNums; |
---|
| 35 | int nextVarNum; |
---|
| 36 | bool isTopLevel; |
---|
[51b7345] | 37 | |
---|
[ea3eb06] | 38 | Mangler(); |
---|
| 39 | Mangler( const Mangler & ); |
---|
[51b7345] | 40 | |
---|
[ea3eb06] | 41 | void mangleDecl( DeclarationWithType *declaration ); |
---|
| 42 | void mangleRef( ReferenceToType *refType, std::string prefix ); |
---|
[51b7345] | 43 | |
---|
[ea3eb06] | 44 | void printQualifiers( Type *type ); |
---|
| 45 | }; // Mangler |
---|
| 46 | |
---|
| 47 | template< typename SynTreeClass > |
---|
| 48 | std::string Mangler::mangle( SynTreeClass *decl ) { |
---|
| 49 | Mangler mangler; |
---|
| 50 | maybeAccept( decl, mangler ); |
---|
| 51 | return mangler.get_mangleName(); |
---|
| 52 | } |
---|
| 53 | } // SymTab |
---|
| 54 | |
---|
| 55 | #endif // SYMTAB_MANGLER_H |
---|