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