source: src/SymTab/Mangler.h @ 22a0e87

ADTast-experimental
Last change on this file since 22a0e87 was 0026d67, checked in by Andrew Beach <ajbeach@…>, 18 months ago

Replaced Mangle::typeMode() with Mangle::mangleType(...), as it is how typeMode() was always used and it is shorter. Various other clean-up in the Mangler files.

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