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 : Rob Schluntz |
---|
12 | // Last Modified On : Wed Aug 19 15:48:46 2015 |
---|
13 | // Update Count : 14 |
---|
14 | // |
---|
15 | |
---|
16 | #ifndef MANGLER_H |
---|
17 | #define MANGLER_H |
---|
18 | |
---|
19 | #include <sstream> |
---|
20 | #include "SynTree/SynTree.h" |
---|
21 | #include "SynTree/Visitor.h" |
---|
22 | |
---|
23 | namespace SymTab { |
---|
24 | /// Mangles names to a unique C identifier |
---|
25 | class Mangler : public Visitor { |
---|
26 | public: |
---|
27 | template< typename SynTreeClass > |
---|
28 | static std::string mangle( SynTreeClass *decl, bool mangleOverridable = true, bool includeQualifiers = true ); // interface to clients |
---|
29 | |
---|
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 mangleName.str(); } |
---|
46 | private: |
---|
47 | std::ostringstream mangleName; ///< Mangled name being constructed |
---|
48 | typedef std::map< std::string, std::pair< int, int > > VarMapType; |
---|
49 | VarMapType varNums; ///< Map of type variables to indices |
---|
50 | int nextVarNum; ///< Next type variable index |
---|
51 | bool isTopLevel; ///< Is the Mangler at the top level |
---|
52 | bool mangleOverridable; ///< Specially mangle overridable built-in methods |
---|
53 | bool includeQualifiers; ///< Include type qualifiers in mangled name |
---|
54 | |
---|
55 | Mangler( bool mangleOverridable, bool includeQualifiers ); |
---|
56 | Mangler( const Mangler & ); |
---|
57 | |
---|
58 | void mangleDecl( DeclarationWithType *declaration ); |
---|
59 | void mangleRef( ReferenceToType *refType, std::string prefix ); |
---|
60 | void mangleGenericRef( ReferenceToType *refType, std::string prefix ); |
---|
61 | |
---|
62 | void printQualifiers( Type *type ); |
---|
63 | }; // Mangler |
---|
64 | |
---|
65 | template< typename SynTreeClass > |
---|
66 | std::string Mangler::mangle( SynTreeClass *decl, bool mangleOverridable, bool includeQualifiers ) { |
---|
67 | Mangler mangler( mangleOverridable, includeQualifiers ); |
---|
68 | maybeAccept( decl, mangler ); |
---|
69 | return mangler.get_mangleName(); |
---|
70 | } |
---|
71 | } // SymTab |
---|
72 | |
---|
73 | #endif // MANGLER_H |
---|
74 | |
---|
75 | // Local Variables: // |
---|
76 | // tab-width: 4 // |
---|
77 | // mode: c++ // |
---|
78 | // compile-command: "make install" // |
---|
79 | // End: // |
---|