source: src/SymTab/Mangler.h @ 7cf8006

ADTast-experimental
Last change on this file since 7cf8006 was 0026d67, checked in by Andrew Beach <ajbeach@…>, 2 years 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
RevLine 
[0dd3a2f]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//
[25bd9074]7// Mangler.h --
[0dd3a2f]8//
9// Author           : Richard C. Bilson
10// Created On       : Sun May 17 21:44:03 2015
[0026d67]11// Last Modified By : Andrew Beach
12// Last Modified On : Thu Oct 27 11:58:00 2022
13// Update Count     : 16
[0dd3a2f]14//
15
[6b0b624]16#pragma once
[51b7345]17
[30f9072]18#include <map>                // for map, map<>::value_compare
19#include <sstream>            // for ostringstream
20#include <string>             // for string
21#include <utility>            // for pair
22
[d76c588]23#include "AST/Bitfield.hpp"
[30f9072]24#include "SynTree/SynTree.h"  // for Types
25#include "SynTree/Visitor.h"  // for Visitor, maybeAccept
[51b7345]26
[642bc83]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
[0026d67]34namespace ast {
35        class Node;
36}
[ff5caaf]37namespace ResolvExpr {
38        class TypeEnvironment;
39}
40
[51b7345]41namespace SymTab {
[d7d9a60]42        namespace Mangler {
[69911c11]43                /// Mangle syntax tree object; primary interface to clients
[6f096d2]44                std::string mangle( const BaseSyntaxNode * decl, bool mangleOverridable = true, bool typeMode = false, bool mangleGenericParams = true );
[d7d9a60]45
[69911c11]46                /// Mangle a type name; secondary interface
[6f096d2]47                std::string mangleType( const Type * ty );
[e35f30a]48                /// Mangle ignoring generic type parameters
[6f096d2]49                std::string mangleConcrete( const Type * ty );
[d1e0979]50
[642bc83]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
[7804e2a]56                        extern const std::string void_t;
[642bc83]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
[0e73845]67                        extern const std::string forall;
68                        extern const std::string typeVariables[];
69
[7804e2a]70                        extern const std::string struct_t;
71                        extern const std::string union_t;
72                        extern const std::string enum_t;
[d8cb7df]73                        extern const std::string type;
[7804e2a]74
[642bc83]75                        extern const std::string autogen;
76                        extern const std::string intrinsic;
77                };
[d7d9a60]78        } // Mangler
[ea3eb06]79} // SymTab
80
[d76c588]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
[0026d67]105        /// Mangle declaration name.
[d76c588]106        std::string mangle( const ast::Node * decl, Mode mode = {} );
107
[0026d67]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
[d76c588]113        namespace Encoding {
114                using namespace SymTab::Mangler::Encoding;
115        };
116}
117
[0dd3a2f]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.