source: src/SymTab/Mangler.h @ ffad73a

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since ffad73a was 78dd0da, checked in by Aaron Moss <a3moss@…>, 8 years ago

Switched size/align parameters over to use SymTab::Mangler in preparation for addition of generic types

  • Property mode set to 100644
File size: 2.7 KB
Line 
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
23namespace 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 
61                void printQualifiers( Type *type );
62        }; // Mangler
63
64        template< typename SynTreeClass >
65        std::string Mangler::mangle( SynTreeClass *decl, bool mangleOverridable, bool includeQualifiers ) {
66                Mangler mangler( mangleOverridable, includeQualifiers );
67                maybeAccept( decl, mangler );
68                return mangler.get_mangleName();
69        }
70} // SymTab
71
72#endif // MANGLER_H
73
74// Local Variables: //
75// tab-width: 4 //
76// mode: c++ //
77// compile-command: "make install" //
78// End: //
Note: See TracBrowser for help on using the repository browser.