source: src/SymTab/Mangler.h @ 8360977

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 8360977 was 8360977, checked in by Aaron Moss <a3moss@…>, 8 years ago

Mangler now mangles parameters to generic types

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[0dd3a2f]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
[4aa0858]11// Last Modified By : Rob Schluntz
12// Last Modified On : Wed Aug 19 15:48:46 2015
13// Update Count     : 14
[0dd3a2f]14//
15
16#ifndef MANGLER_H
17#define MANGLER_H
[51b7345]18
[5f2f2d7]19#include <sstream>
[51b7345]20#include "SynTree/SynTree.h"
21#include "SynTree/Visitor.h"
22
23namespace SymTab {
[78dd0da]24        /// Mangles names to a unique C identifier
[a08ba92]25        class Mangler : public Visitor {
26          public:
[0dd3a2f]27                template< typename SynTreeClass >
[78dd0da]28            static std::string mangle( SynTreeClass *decl, bool mangleOverridable = true, bool includeQualifiers = true ); // interface to clients
[51b7345]29
[0dd3a2f]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 );
[51b7345]44 
[5f2f2d7]45                std::string get_mangleName() { return mangleName.str(); }
[a08ba92]46          private:
[78dd0da]47                std::ostringstream mangleName;  ///< Mangled name being constructed
[0dd3a2f]48                typedef std::map< std::string, std::pair< int, int > > VarMapType;
[78dd0da]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
[51b7345]54 
[78dd0da]55                Mangler( bool mangleOverridable, bool includeQualifiers );
[0dd3a2f]56                Mangler( const Mangler & );
[51b7345]57 
[0dd3a2f]58                void mangleDecl( DeclarationWithType *declaration );
59                void mangleRef( ReferenceToType *refType, std::string prefix );
[8360977]60                void mangleGenericRef( ReferenceToType *refType, std::string prefix );
[51b7345]61 
[0dd3a2f]62                void printQualifiers( Type *type );
[a08ba92]63        }; // Mangler
[ea3eb06]64
[a08ba92]65        template< typename SynTreeClass >
[78dd0da]66        std::string Mangler::mangle( SynTreeClass *decl, bool mangleOverridable, bool includeQualifiers ) {
67                Mangler mangler( mangleOverridable, includeQualifiers );
[0dd3a2f]68                maybeAccept( decl, mangler );
69                return mangler.get_mangleName();
[a08ba92]70        }
[ea3eb06]71} // SymTab
72
[0dd3a2f]73#endif // MANGLER_H
74
75// Local Variables: //
76// tab-width: 4 //
77// mode: c++ //
78// compile-command: "make install" //
79// End: //
Note: See TracBrowser for help on using the repository browser.