1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
3 | // |
---|
4 | // The contents of this file are covered under the licence agreement in the |
---|
5 | // file "LICENCE" distributed with Cforall. |
---|
6 | // |
---|
7 | // Mangler.h -- |
---|
8 | // |
---|
9 | // Author : Richard C. Bilson |
---|
10 | // Created On : Sun May 17 21:44:03 2015 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Sun May 17 21:45:05 2015 |
---|
13 | // Update Count : 2 |
---|
14 | // |
---|
15 | |
---|
16 | #ifndef MANGLER_H |
---|
17 | #define MANGLER_H |
---|
18 | |
---|
19 | #include <strstream> |
---|
20 | #include "SynTree/SynTree.h" |
---|
21 | #include "SynTree/Visitor.h" |
---|
22 | |
---|
23 | namespace SymTab { |
---|
24 | class Mangler : public Visitor { |
---|
25 | public: |
---|
26 | template< typename SynTreeClass > |
---|
27 | static std::string mangle( SynTreeClass *decl ); // interface to clients |
---|
28 | |
---|
29 | /// using Visitor::visit; |
---|
30 | virtual void visit( ObjectDecl *declaration ); |
---|
31 | virtual void visit( FunctionDecl *declaration ); |
---|
32 | virtual void visit( TypeDecl *declaration ); |
---|
33 | |
---|
34 | virtual void visit( VoidType *voidType ); |
---|
35 | virtual void visit( BasicType *basicType ); |
---|
36 | virtual void visit( PointerType *pointerType ); |
---|
37 | virtual void visit( ArrayType *arrayType ); |
---|
38 | virtual void visit( FunctionType *functionType ); |
---|
39 | virtual void visit( StructInstType *aggregateUseType ); |
---|
40 | virtual void visit( UnionInstType *aggregateUseType ); |
---|
41 | virtual void visit( EnumInstType *aggregateUseType ); |
---|
42 | virtual void visit( TypeInstType *aggregateUseType ); |
---|
43 | virtual void visit( TupleType *tupleType ); |
---|
44 | |
---|
45 | std::string get_mangleName() { return std::string( mangleName.str(), mangleName.pcount() ); } |
---|
46 | private: |
---|
47 | std::ostrstream mangleName; |
---|
48 | typedef std::map< std::string, std::pair< int, int > > VarMapType; |
---|
49 | VarMapType varNums; |
---|
50 | int nextVarNum; |
---|
51 | bool isTopLevel; |
---|
52 | |
---|
53 | Mangler(); |
---|
54 | Mangler( const Mangler & ); |
---|
55 | |
---|
56 | void mangleDecl( DeclarationWithType *declaration ); |
---|
57 | void mangleRef( ReferenceToType *refType, std::string prefix ); |
---|
58 | |
---|
59 | void printQualifiers( Type *type ); |
---|
60 | }; // Mangler |
---|
61 | |
---|
62 | template< typename SynTreeClass > |
---|
63 | std::string Mangler::mangle( SynTreeClass *decl ) { |
---|
64 | Mangler mangler; |
---|
65 | maybeAccept( decl, mangler ); |
---|
66 | return mangler.get_mangleName(); |
---|
67 | } |
---|
68 | } // SymTab |
---|
69 | |
---|
70 | #endif // MANGLER_H |
---|
71 | |
---|
72 | // Local Variables: // |
---|
73 | // tab-width: 4 // |
---|
74 | // mode: c++ // |
---|
75 | // compile-command: "make install" // |
---|
76 | // End: // |
---|