Skip to content

Commit 5f7b0c4

Browse files
Add ipr::FunctionTraits (#309)
And support for _explicit object parameter_ description in the IR.
1 parent ac9dd5e commit 5f7b0c4

File tree

6 files changed

+73
-7
lines changed

6 files changed

+73
-7
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(
2-
VERSION 3.28
2+
VERSION 3.31
33
)
44
include(CheckIPOSupported)
55

@@ -59,7 +59,7 @@ target_sources(${PROJECT_NAME}
5959

6060
set_target_properties(${PROJECT_NAME}
6161
PROPERTIES
62-
CXX_STANDARD 20
62+
CXX_STANDARD 23
6363
CXX_STANDARD_REQUIRED ON
6464
CXX_EXTENSIONS OFF
6565
)

include/ipr/impl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,11 +1965,21 @@ namespace ipr::impl {
19651965
const ipr::Region& lexical_region() const final { return lexreg.get(); }
19661966
};
19671967

1968+
struct Concept : impl::Decl<ipr::Concept> {
1969+
impl::Parameter_list inputs;
1970+
util::ref<const ipr::Expr> init;
1971+
explicit Concept(const ipr::Region& r) : inputs{r, { }} { }
1972+
const ipr::Parameter_list& parameters() const final { return inputs; }
1973+
const ipr::Expr& result() const final { return init.get(); }
1974+
Optional<ipr::Expr> initializer() const final { return { *this }; }
1975+
};
1976+
19681977
// For a non-defining function declaration, the parameters - if any is named
19691978
// or has a default argument - are stored with that particular declaration.
19701979
// A function definition is one that specifies the initializer (Mapping) which
19711980
// already has room for the named parameters or the default arguments.
19721981
struct fundecl_data : std::variant<impl::Parameter_list*, impl::Mapping*> {
1982+
ipr::FunctionTraits traits { };
19731983
impl::Parameter_list* parameters() const { return std::get<0>(*this); }
19741984
impl::Mapping* mapping() const { return std::get<1>(*this); }
19751985
};
@@ -1980,6 +1990,7 @@ namespace ipr::impl {
19801990

19811991
Fundecl();
19821992

1993+
ipr::FunctionTraits traits() const final { return data.traits; }
19831994
const ipr::Parameter_list& parameters() const final;
19841995
Optional<ipr::Mapping> mapping() const final;
19851996
Optional<ipr::Expr> initializer() const final;

include/ipr/interface

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ namespace ipr {
8181
#include <ipr/node-category>
8282
};
8383

84-
// -- General structural utility types.
84+
// -- General structural utility types and functions.
8585

86+
// -- General node category class.
8687
template<Category_code Cat, class T = Expr>
8788
struct Category : T {
8889
protected:
@@ -102,6 +103,33 @@ namespace ipr {
102103
virtual const T& result() const = 0;
103104
};
104105

106+
// -- DeclSpecifiers --
107+
enum class DeclSpecifiers : std::uint32_t {
108+
None = 0,
109+
Register = 1 << 0, // Banned from C++17.
110+
Static = 1 << 1,
111+
Extern = 1 << 2,
112+
Mutable = 1 << 3,
113+
Thread = 1 << 4,
114+
StorageClass = Register | Static | Extern | Mutable | Thread,
115+
116+
Inline = 1 << 5,
117+
Virtual = 1 << 6, // also used as storage class specifier
118+
// for virtual base subobjects
119+
Explicit = 1 << 7,
120+
121+
Friend = 1 << 9,
122+
Typedef = 1 << 10,
123+
124+
Public = 1 << 11,
125+
Protected = 1 << 12,
126+
Private = 1 << 13,
127+
AccessProtection = Public | Protected | Private,
128+
129+
Export = 1 << 14, // For exported declarations.
130+
Constexpr = 1 << 15, // C++ 11
131+
};
132+
105133
// -- Logogram --
106134
// A class of words (from a C++ input source) standing for themselves, with no particular elaboration.
107135
struct Logogram : Basic_unary<const String&> {
@@ -245,12 +273,13 @@ namespace ipr {
245273
}
246274

247275
// -- Lambda_specifiers --
248-
// Declaration specifiers that can appear on a lambda expression.
276+
// Declaration specifiers that can appear in a lambda expression.
249277
enum class Lambda_specifiers : std::uint32_t {
250278
None = 0,
251-
Mutable = 1 << 0,
252-
Constexpr = 1 << 1,
253-
Consteval = 1 << 2,
279+
Mutable = 1 << 0, // `mutable` lambda
280+
Constexpr = 1 << 1, // `constexpr` lambda
281+
Consteval = 1 << 2, // `consteval` lambda
282+
ExplicitObject = 1 << 3, // explicit object parameter `this`.
254283
};
255284

256285
// -- Module_name --
@@ -1841,15 +1870,33 @@ namespace ipr {
18411870
Optional<Expr> initializer() const final { return { }; }
18421871
};
18431872

1873+
// -- Semantic traits of a function declaration.
1874+
enum class FunctionTraits : std::uint32_t {
1875+
Nothing = 0x0, // No particular traits
1876+
Pure = 1 << 0, // pure virtual function
1877+
Virtual = 1 << 1, // virtual function
1878+
Static = 1 << 2, // static member-function, NOT linkage
1879+
Inline = 1 << 3, // inline function
1880+
Explicit = 1 << 4, // function declared `explicit`
1881+
Constexpr = 1 << 5, // constexpr function
1882+
Consteval = 1 << 6, // consteval function
1883+
ExplicitObject = 1 << 7, // function with explicit object parameter.
1884+
};
1885+
18441886
// -- Fundecl --
18451887
// This node represents a function declaration. Notice that the
18461888
// exception specification is actually made part of the function type.
18471889
struct Fundecl : Category<Category_code::Fundecl, Decl> {
1890+
virtual FunctionTraits traits() const = 0;
18481891
virtual Optional<Mapping> mapping() const = 0;
18491892
virtual const Parameter_list& parameters() const = 0;
18501893
virtual Optional<Fundecl> definition() const = 0;
18511894
};
18521895

1896+
// -- Concept --
1897+
struct Concept : Category<Category_code::Concept, Decl>, Parameterization<Expr> {
1898+
};
1899+
18531900
// -- Var --
18541901
// This represents a variable declaration. It is also used to
18551902
// represent a static data member.
@@ -2152,6 +2199,7 @@ namespace ipr {
21522199
virtual void visit(const Field&);
21532200
virtual void visit(const Fundecl&);
21542201
virtual void visit(const Template&);
2202+
virtual void visit(const Concept&);
21552203
virtual void visit(const Parameter&);
21562204
virtual void visit(const Parameter_list&);
21572205
virtual void visit(const Typedecl&);

include/ipr/node-category

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ Field, // ipr::Field
177177
Bitfield, // ipr::Bitfield
178178
Fundecl, // ipr::Fundecl
179179
Template, // ipr::Template
180+
Concept, // ipr::Concept
180181
Parameter, // ipr::Parameter
181182
Typedecl, // ipr::Typedecl
182183
Var, // ipr::Var

include/ipr/synopsis

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ namespace ipr {
220220
struct Bitfield; // bitfield
221221
struct Fundecl; // function-declaration
222222
struct Template; // template-declaration
223+
struct Concept; // concept definition
223224
struct Parameter; // function or template parameter
224225
struct Typedecl; // declaration for a type
225226
struct Var; // variable declaration

src/traversal.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,11 @@ ipr::Visitor::visit(const Fundecl& d)
979979
visit(as<Decl>(d));
980980
}
981981

982+
void ipr::Visitor::visit(const Concept& d)
983+
{
984+
visit(as<Decl>(d));
985+
}
986+
982987
void
983988
ipr::Visitor::visit(const Parameter& d)
984989
{

0 commit comments

Comments
 (0)