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 | /// Mangle syntax tree object; primary interface to clients
|
---|
28 | template< typename SynTreeClass >
|
---|
29 | static std::string mangle( SynTreeClass *decl, bool mangleOverridable = true );
|
---|
30 | /// Mangle a type name; secondary interface
|
---|
31 | static std::string mangleType( Type* ty );
|
---|
32 |
|
---|
33 | virtual void visit( ObjectDecl *declaration );
|
---|
34 | virtual void visit( FunctionDecl *declaration );
|
---|
35 | virtual void visit( TypeDecl *declaration );
|
---|
36 |
|
---|
37 | virtual void visit( VoidType *voidType );
|
---|
38 | virtual void visit( BasicType *basicType );
|
---|
39 | virtual void visit( PointerType *pointerType );
|
---|
40 | virtual void visit( ArrayType *arrayType );
|
---|
41 | virtual void visit( FunctionType *functionType );
|
---|
42 | virtual void visit( StructInstType *aggregateUseType );
|
---|
43 | virtual void visit( UnionInstType *aggregateUseType );
|
---|
44 | virtual void visit( EnumInstType *aggregateUseType );
|
---|
45 | virtual void visit( TypeInstType *aggregateUseType );
|
---|
46 | virtual void visit( TupleType *tupleType );
|
---|
47 | virtual void visit( VarArgsType *varArgsType );
|
---|
48 |
|
---|
49 | std::string get_mangleName() { return mangleName.str(); }
|
---|
50 | private:
|
---|
51 | std::ostringstream mangleName; ///< Mangled name being constructed
|
---|
52 | typedef std::map< std::string, std::pair< int, int > > VarMapType;
|
---|
53 | VarMapType varNums; ///< Map of type variables to indices
|
---|
54 | int nextVarNum; ///< Next type variable index
|
---|
55 | bool isTopLevel; ///< Is the Mangler at the top level
|
---|
56 | bool mangleOverridable; ///< Specially mangle overridable built-in methods
|
---|
57 | bool typeMode; ///< Produce a unique mangled name for a type
|
---|
58 |
|
---|
59 | Mangler( bool mangleOverridable, bool typeMode );
|
---|
60 | Mangler( const Mangler & );
|
---|
61 |
|
---|
62 | void mangleDecl( DeclarationWithType *declaration );
|
---|
63 | void mangleRef( ReferenceToType *refType, std::string prefix );
|
---|
64 | void mangleGenericRef( ReferenceToType *refType, std::string prefix );
|
---|
65 |
|
---|
66 | void printQualifiers( Type *type );
|
---|
67 | }; // Mangler
|
---|
68 |
|
---|
69 | template< typename SynTreeClass >
|
---|
70 | std::string Mangler::mangle( SynTreeClass *decl, bool mangleOverridable ) {
|
---|
71 | Mangler mangler( mangleOverridable, false );
|
---|
72 | maybeAccept( decl, mangler );
|
---|
73 | return mangler.get_mangleName();
|
---|
74 | }
|
---|
75 | } // SymTab
|
---|
76 |
|
---|
77 | #endif // MANGLER_H
|
---|
78 |
|
---|
79 | // Local Variables: //
|
---|
80 | // tab-width: 4 //
|
---|
81 | // mode: c++ //
|
---|
82 | // compile-command: "make install" //
|
---|
83 | // End: //
|
---|