source: src/SymTab/Mangler.h@ 1ccae59

Last change on this file since 1ccae59 was c6b4432, checked in by Andrew Beach <ajbeach@…>, 23 months ago

Remove BaseSyntaxNode and clean-up.

  • Property mode set to 100644
File size: 2.9 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 : Andrew Beach
12// Last Modified On : Thu Oct 27 11:58:00 2022
13// Update Count : 16
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
25// https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling
26// The CFA name mangling scheme is based closely on the itanium C++ name mangling scheme, with the following key differences:
27// * Variable names are also mangled to include type information, not just functions
28// * CFA does not have template expansion, so the rules for function specialization do not apply.
29// * CFA instead has to handle type parameters and assertion parameters.
30// * Currently name compression is not implemented.
31
32namespace ast {
33 class Node;
34}
35
36namespace SymTab {
37 namespace Mangler {
38 namespace Encoding {
39 extern const std::string manglePrefix;
40 extern const std::string basicTypes[];
41 extern const std::map<int, std::string> qualifiers;
42
43 extern const std::string void_t;
44 extern const std::string zero;
45 extern const std::string one;
46
47 extern const std::string function;
48 extern const std::string tuple;
49 extern const std::string pointer;
50 extern const std::string array;
51 extern const std::string qualifiedTypeStart;
52 extern const std::string qualifiedTypeEnd;
53
54 extern const std::string forall;
55 extern const std::string typeVariables[];
56
57 extern const std::string struct_t;
58 extern const std::string union_t;
59 extern const std::string enum_t;
60 extern const std::string type;
61
62 extern const std::string autogen;
63 extern const std::string intrinsic;
64 };
65 } // Mangler
66} // SymTab
67
68namespace Mangle {
69 /// Bitflags for mangle modes
70 enum {
71 NoOverrideable = 1 << 0,
72 Type = 1 << 1,
73 NoGenericParams = 1 << 2
74 };
75
76 /// Bitflag type for mangler modes
77 struct mangle_flags {
78 union {
79 unsigned int val;
80 struct {
81 bool no_overrideable : 1;
82 bool type : 1;
83 bool no_generic_params : 1;
84 };
85 };
86
87 constexpr mangle_flags( unsigned int val ) : val(val) {}
88 };
89
90 using Mode = bitfield<mangle_flags>;
91
92 /// Mangle declaration name.
93 std::string mangle( const ast::Node * decl, Mode mode = {} );
94
95 /// Most common mangle configuration for types.
96 static inline std::string mangleType( const ast::Node * type ) {
97 return mangle( type, { NoOverrideable | Type } );
98 }
99
100 namespace Encoding {
101 using namespace SymTab::Mangler::Encoding;
102 };
103}
104
105// Local Variables: //
106// tab-width: 4 //
107// mode: c++ //
108// compile-command: "make install" //
109// End: //
Note: See TracBrowser for help on using the repository browser.