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 "AST/Bitfield.hpp" |
---|
24 | #include "AST/Fwd.hpp" |
---|
25 | #include "SynTree/SynTree.h" // for Types |
---|
26 | #include "SynTree/Visitor.h" // for Visitor, maybeAccept |
---|
27 | |
---|
28 | // https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling |
---|
29 | // The CFA name mangling scheme is based closely on the itanium C++ name mangling scheme, with the following key differences: |
---|
30 | // * Variable names are also mangled to include type information, not just functions |
---|
31 | // * CFA does not have template expansion, so the rules for function specialization do not apply. |
---|
32 | // * CFA instead has to handle type parameters and assertion parameters. |
---|
33 | // * Currently name compression is not implemented. |
---|
34 | |
---|
35 | namespace ResolvExpr { |
---|
36 | class TypeEnvironment; |
---|
37 | } |
---|
38 | |
---|
39 | namespace SymTab { |
---|
40 | namespace Mangler { |
---|
41 | /// Mangle syntax tree object; primary interface to clients |
---|
42 | std::string mangle( const BaseSyntaxNode * decl, bool mangleOverridable = true, bool typeMode = false, bool mangleGenericParams = true ); |
---|
43 | |
---|
44 | /// Mangle a type name; secondary interface |
---|
45 | std::string mangleType( const Type * ty ); |
---|
46 | /// Mangle ignoring generic type parameters |
---|
47 | std::string mangleConcrete( const Type * ty ); |
---|
48 | |
---|
49 | namespace Encoding { |
---|
50 | extern const std::string manglePrefix; |
---|
51 | extern const std::string basicTypes[]; |
---|
52 | extern const std::map<int, std::string> qualifiers; |
---|
53 | |
---|
54 | extern const std::string void_t; |
---|
55 | extern const std::string zero; |
---|
56 | extern const std::string one; |
---|
57 | |
---|
58 | extern const std::string function; |
---|
59 | extern const std::string tuple; |
---|
60 | extern const std::string pointer; |
---|
61 | extern const std::string array; |
---|
62 | extern const std::string qualifiedTypeStart; |
---|
63 | extern const std::string qualifiedTypeEnd; |
---|
64 | |
---|
65 | extern const std::string forall; |
---|
66 | extern const std::string typeVariables[]; |
---|
67 | |
---|
68 | extern const std::string struct_t; |
---|
69 | extern const std::string union_t; |
---|
70 | extern const std::string enum_t; |
---|
71 | extern const std::string type; |
---|
72 | |
---|
73 | extern const std::string autogen; |
---|
74 | extern const std::string intrinsic; |
---|
75 | }; |
---|
76 | } // Mangler |
---|
77 | } // SymTab |
---|
78 | |
---|
79 | namespace Mangle { |
---|
80 | /// Bitflags for mangle modes |
---|
81 | enum { |
---|
82 | NoOverrideable = 1 << 0, |
---|
83 | Type = 1 << 1, |
---|
84 | NoGenericParams = 1 << 2 |
---|
85 | }; |
---|
86 | |
---|
87 | /// Bitflag type for mangler modes |
---|
88 | struct mangle_flags { |
---|
89 | union { |
---|
90 | unsigned int val; |
---|
91 | struct { |
---|
92 | bool no_overrideable : 1; |
---|
93 | bool type : 1; |
---|
94 | bool no_generic_params : 1; |
---|
95 | }; |
---|
96 | }; |
---|
97 | |
---|
98 | constexpr mangle_flags( unsigned int val ) : val(val) {} |
---|
99 | }; |
---|
100 | |
---|
101 | using Mode = bitfield<mangle_flags>; |
---|
102 | |
---|
103 | static inline Mode typeMode() { return NoOverrideable | Type; } |
---|
104 | |
---|
105 | /// Mangle declaration name |
---|
106 | std::string mangle( const ast::Node * decl, Mode mode = {} ); |
---|
107 | |
---|
108 | namespace Encoding { |
---|
109 | using namespace SymTab::Mangler::Encoding; |
---|
110 | }; |
---|
111 | } |
---|
112 | |
---|
113 | // Local Variables: // |
---|
114 | // tab-width: 4 // |
---|
115 | // mode: c++ // |
---|
116 | // compile-command: "make install" // |
---|
117 | // End: // |
---|