source: src/SymTab/Mangler.h @ d16d159

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since d16d159 was e35f30a, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

Fix generic type name mangling, add mangleGenericParams mode to name mangler [fixes #41]

  • Property mode set to 100644
File size: 3.4 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 : Peter A. Buhr
12// Last Modified On : Sat Jul 22 09:45:30 2017
13// Update Count     : 15
14//
15
16#pragma once
17
18#include <map>                // for map, map<>::value_compare
19#include <sstream>            // for ostringstream
20#include <string>             // for string
21#include <utility>            // for pair
22
23#include "SynTree/SynTree.h"  // for Types
24#include "SynTree/Visitor.h"  // for Visitor, maybeAccept
25
26namespace SymTab {
27        /// Mangles names to a unique C identifier
28        class Mangler : public Visitor {
29          public:
30                /// Mangle syntax tree object; primary interface to clients
31                template< typename SynTreeClass >
32            static std::string mangle( SynTreeClass *decl, bool mangleOverridable = true, bool typeMode = false, bool mangleGenericParams = true );
33                /// Mangle a type name; secondary interface
34                static std::string mangleType( Type* ty );
35                /// Mangle ignoring generic type parameters
36                static std::string mangleConcrete( Type* ty );
37
38
39                virtual void visit( ObjectDecl *declaration );
40                virtual void visit( FunctionDecl *declaration );
41                virtual void visit( TypeDecl *declaration );
42
43                virtual void visit( VoidType *voidType );
44                virtual void visit( BasicType *basicType );
45                virtual void visit( PointerType *pointerType );
46                virtual void visit( ArrayType *arrayType );
47                virtual void visit( ReferenceType *refType );
48                virtual void visit( FunctionType *functionType );
49                virtual void visit( StructInstType *aggregateUseType );
50                virtual void visit( UnionInstType *aggregateUseType );
51                virtual void visit( EnumInstType *aggregateUseType );
52                virtual void visit( TypeInstType *aggregateUseType );
53                virtual void visit( TupleType *tupleType );
54                virtual void visit( VarArgsType *varArgsType );
55                virtual void visit( ZeroType *zeroType );
56                virtual void visit( OneType *oneType );
57
58                std::string get_mangleName() { return mangleName.str(); }
59          private:
60                std::ostringstream mangleName;  ///< Mangled name being constructed
61                typedef std::map< std::string, std::pair< int, int > > VarMapType;
62                VarMapType varNums;             ///< Map of type variables to indices
63                int nextVarNum;                 ///< Next type variable index
64                bool isTopLevel;                ///< Is the Mangler at the top level
65                bool mangleOverridable;         ///< Specially mangle overridable built-in methods
66                bool typeMode;                  ///< Produce a unique mangled name for a type
67                bool mangleGenericParams;       ///< Include generic parameters in name mangling if true
68
69                Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams );
70                Mangler( const Mangler & );
71
72                void mangleDecl( DeclarationWithType *declaration );
73                void mangleRef( ReferenceToType *refType, std::string prefix );
74
75                void printQualifiers( Type *type );
76        }; // Mangler
77
78        template< typename SynTreeClass >
79        std::string Mangler::mangle( SynTreeClass *decl, bool mangleOverridable, bool typeMode, bool mangleGenericParams ) {
80                Mangler mangler( mangleOverridable, typeMode, mangleGenericParams );
81                maybeAccept( decl, mangler );
82                return mangler.get_mangleName();
83        }
84} // SymTab
85
86// Local Variables: //
87// tab-width: 4 //
88// mode: c++ //
89// compile-command: "make install" //
90// End: //
Note: See TracBrowser for help on using the repository browser.