Ignore:
Timestamp:
Aug 27, 2018, 4:40:34 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
b7c89aa
Parents:
f9feab8 (diff), 305581d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into cleanup-dtors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Mangler.h

    rf9feab8 r90152a4  
    2424#include "SynTree/Visitor.h"  // for Visitor, maybeAccept
    2525
     26// https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling
     27// The CFA name mangling scheme is based closely on the itanium C++ name mangling scheme, with the following key differences:
     28// * Variable names are also mangled to include type information, not just functions
     29// * CFA does not have template expansion, so the rules for function specialization do not apply.
     30// * CFA instead has to handle type parameters and assertion parameters.
     31// * Currently name compression is not implemented.
     32
    2633namespace SymTab {
    27         /// Mangles names to a unique C identifier
    28         class Mangler : public Visitor {
    29           public:
     34        namespace Mangler {
    3035                /// 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 );
     36                std::string mangle( BaseSyntaxNode * decl, bool mangleOverridable = true, bool typeMode = false, bool mangleGenericParams = true );
     37
    3338                /// Mangle a type name; secondary interface
    34                 static std::string mangleType( Type* ty );
     39                std::string mangleType( Type* ty );
    3540                /// Mangle ignoring generic type parameters
    36                 static std::string mangleConcrete( Type* ty );
     41                std::string mangleConcrete( Type* ty );
    3742
     43                namespace Encoding {
     44                        extern const std::string manglePrefix;
     45                        extern const std::string basicTypes[];
     46                        extern const std::map<int, std::string> qualifiers;
    3847
    39                 virtual void visit( ObjectDecl *declaration );
    40                 virtual void visit( FunctionDecl *declaration );
    41                 virtual void visit( TypeDecl *declaration );
     48                        extern const std::string void_t;
     49                        extern const std::string zero;
     50                        extern const std::string one;
    4251
    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 );
     52                        extern const std::string function;
     53                        extern const std::string tuple;
     54                        extern const std::string pointer;
     55                        extern const std::string array;
     56                        extern const std::string qualifiedTypeStart;
     57                        extern const std::string qualifiedTypeEnd;
    5758
    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
     59                        extern const std::string forall;
     60                        extern const std::string typeVariables[];
    6861
    69                 Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams );
    70                 Mangler( const Mangler & );
     62                        extern const std::string struct_t;
     63                        extern const std::string union_t;
     64                        extern const std::string enum_t;
     65                        extern const std::string type;
    7166
    72                 void mangleDecl( DeclarationWithType *declaration );
    73                 void mangleRef( ReferenceToType *refType, std::string prefix );
     67                        extern const std::string autogen;
     68                        extern const std::string intrinsic;
     69                };
     70        } // Mangler
     71} // SymTab
    7472
    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
     73extern "C" {
     74        char * cforall_demangle(const char *, int);
     75}
    8576
    8677// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.