source: src/SymTab/Mangler.h

Last change on this file was b0845f9, checked in by Andrew Beach <ajbeach@…>, 3 months ago

Reformating and clean-up in SymTab? directory.

  • Property mode set to 100644
File size: 2.8 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 Mangle {
37
38/// Bitflags for mangle Mode:
39enum {
40        NoOverrideable  = 1 << 0,
41        Type            = 1 << 1,
42        NoGenericParams = 1 << 2
43};
44
45/// Bitflag type for mangle Mode:
46struct mangle_flags {
47        union {
48                unsigned int val;
49                struct {
50                        bool no_overrideable   : 1;
51                        bool type              : 1;
52                        bool no_generic_params : 1;
53                };
54        };
55
56        constexpr mangle_flags( unsigned int val ) : val(val) {}
57};
58
59using Mode = bitfield<mangle_flags>;
60
61/// Mangle declaration name.
62std::string mangle( const ast::Node * decl, Mode mode = {} );
63
64/// Most common mangle configuration for types.
65static inline std::string mangleType( const ast::Node * type ) {
66        return mangle( type, { NoOverrideable | Type } );
67}
68
69/// The substrings used in name mangling and demangling.
70namespace Encoding {
71        extern const std::string manglePrefix;
72        extern const std::string basicTypes[];
73        extern const std::map<int, std::string> qualifiers;
74
75        extern const std::string void_t;
76        extern const std::string zero;
77        extern const std::string one;
78
79        extern const std::string function;
80        extern const std::string tuple;
81        extern const std::string pointer;
82        extern const std::string array;
83        extern const std::string qualifiedTypeStart;
84        extern const std::string qualifiedTypeEnd;
85
86        extern const std::string forall;
87        extern const std::string typeVariables[];
88
89        extern const std::string struct_t;
90        extern const std::string union_t;
91        extern const std::string enum_t;
92        extern const std::string type;
93
94        extern const std::string autogen;
95        extern const std::string intrinsic;
96}
97
98}
99
100// Local Variables: //
101// tab-width: 4 //
102// mode: c++ //
103// compile-command: "make install" //
104// End: //
Note: See TracBrowser for help on using the repository browser.