source: src/SymTab/Mangler.h@ be9288a

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since be9288a was 33218c6, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

  • Property mode set to 100644
File size: 3.1 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 );
33 /// Mangle a type name; secondary interface
34 static std::string mangleType( Type* ty );
35
36 virtual void visit( ObjectDecl *declaration );
37 virtual void visit( FunctionDecl *declaration );
38 virtual void visit( TypeDecl *declaration );
39
40 virtual void visit( VoidType *voidType );
41 virtual void visit( BasicType *basicType );
42 virtual void visit( PointerType *pointerType );
43 virtual void visit( ArrayType *arrayType );
44 virtual void visit( FunctionType *functionType );
45 virtual void visit( StructInstType *aggregateUseType );
46 virtual void visit( UnionInstType *aggregateUseType );
47 virtual void visit( EnumInstType *aggregateUseType );
48 virtual void visit( TypeInstType *aggregateUseType );
49 virtual void visit( TupleType *tupleType );
50 virtual void visit( VarArgsType *varArgsType );
51 virtual void visit( ZeroType *zeroType );
52 virtual void visit( OneType *oneType );
53
54 std::string get_mangleName() { return mangleName.str(); }
55 private:
56 std::ostringstream mangleName; ///< Mangled name being constructed
57 typedef std::map< std::string, std::pair< int, int > > VarMapType;
58 VarMapType varNums; ///< Map of type variables to indices
59 int nextVarNum; ///< Next type variable index
60 bool isTopLevel; ///< Is the Mangler at the top level
61 bool mangleOverridable; ///< Specially mangle overridable built-in methods
62 bool typeMode; ///< Produce a unique mangled name for a type
63
64 Mangler( bool mangleOverridable, bool typeMode );
65 Mangler( const Mangler & );
66
67 void mangleDecl( DeclarationWithType *declaration );
68 void mangleRef( ReferenceToType *refType, std::string prefix );
69 void mangleGenericRef( ReferenceToType *refType, std::string prefix );
70
71 void printQualifiers( Type *type );
72 }; // Mangler
73
74 template< typename SynTreeClass >
75 std::string Mangler::mangle( SynTreeClass *decl, bool mangleOverridable, bool typeMode ) {
76 Mangler mangler( mangleOverridable, typeMode );
77 maybeAccept( decl, mangler );
78 return mangler.get_mangleName();
79 }
80} // SymTab
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.