source: src/SymTab/Mangler.h @ 25bd9074

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since 25bd9074 was 25bd9074, checked in by Rob Schluntz <rschlunt@…>, 4 years ago

Add name mangling for reference types

  • Property mode set to 100644
File size: 3.0 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//
[25bd9074]7// Mangler.h --
[0dd3a2f]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:
[69911c11]27                /// Mangle syntax tree object; primary interface to clients
[0dd3a2f]28                template< typename SynTreeClass >
[0270824]29            static std::string mangle( SynTreeClass *decl, bool mangleOverridable = true, bool typeMode = false );
[69911c11]30                /// Mangle a type name; secondary interface
31                static std::string mangleType( Type* ty );
[51b7345]32
[0dd3a2f]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 );
[25bd9074]41                virtual void visit( ReferenceType *refType );
[0dd3a2f]42                virtual void visit( FunctionType *functionType );
43                virtual void visit( StructInstType *aggregateUseType );
44                virtual void visit( UnionInstType *aggregateUseType );
45                virtual void visit( EnumInstType *aggregateUseType );
46                virtual void visit( TypeInstType *aggregateUseType );
47                virtual void visit( TupleType *tupleType );
[44b7088]48                virtual void visit( VarArgsType *varArgsType );
[89e6ffc]49                virtual void visit( ZeroType *zeroType );
50                virtual void visit( OneType *oneType );
[25bd9074]51
[5f2f2d7]52                std::string get_mangleName() { return mangleName.str(); }
[a08ba92]53          private:
[78dd0da]54                std::ostringstream mangleName;  ///< Mangled name being constructed
[0dd3a2f]55                typedef std::map< std::string, std::pair< int, int > > VarMapType;
[78dd0da]56                VarMapType varNums;             ///< Map of type variables to indices
57                int nextVarNum;                 ///< Next type variable index
58                bool isTopLevel;                ///< Is the Mangler at the top level
59                bool mangleOverridable;         ///< Specially mangle overridable built-in methods
[69911c11]60                bool typeMode;                  ///< Produce a unique mangled name for a type
[25bd9074]61
[69911c11]62                Mangler( bool mangleOverridable, bool typeMode );
[0dd3a2f]63                Mangler( const Mangler & );
[25bd9074]64
[0dd3a2f]65                void mangleDecl( DeclarationWithType *declaration );
66                void mangleRef( ReferenceToType *refType, std::string prefix );
[8360977]67                void mangleGenericRef( ReferenceToType *refType, std::string prefix );
[25bd9074]68
[0dd3a2f]69                void printQualifiers( Type *type );
[a08ba92]70        }; // Mangler
[ea3eb06]71
[a08ba92]72        template< typename SynTreeClass >
[0270824]73        std::string Mangler::mangle( SynTreeClass *decl, bool mangleOverridable, bool typeMode ) {
74                Mangler mangler( mangleOverridable, typeMode );
[0dd3a2f]75                maybeAccept( decl, mangler );
76                return mangler.get_mangleName();
[a08ba92]77        }
[ea3eb06]78} // SymTab
79
[0dd3a2f]80#endif // MANGLER_H
81
82// Local Variables: //
83// tab-width: 4 //
84// mode: c++ //
85// compile-command: "make install" //
86// End: //
Note: See TracBrowser for help on using the repository browser.