From 9e605416aa8f5314eb238c7bf83d8cbaa6a4f429 Mon Sep 17 00:00:00 2001 From: Gabriel Dos Reis Date: Thu, 18 Feb 2021 20:22:36 -0800 Subject: [PATCH] Rename ipr::Datum to ipr::Construction (#128) --- include/ipr/impl | 25 +++++++++------------- include/ipr/interface | 45 +++++++++++++++++++++++---------------- include/ipr/node-category | 2 +- src/impl.cxx | 28 +++++++++++------------- src/io.cxx | 12 ++++------- src/traversal.cxx | 2 +- 6 files changed, 55 insertions(+), 59 deletions(-) diff --git a/include/ipr/impl b/include/ipr/impl index 6a10a64..f34eaed 100644 --- a/include/ipr/impl +++ b/include/ipr/impl @@ -1070,6 +1070,7 @@ namespace ipr { using Unary_minus = Classic_unary_expr; using Unary_plus = Classic_unary_expr; using Expansion = Classic_unary_expr; + using Construction = Classic_unary_expr; using And = Classic_binary_expr; using Annotation = Binary_node; @@ -1088,7 +1089,6 @@ namespace ipr { using Coerce = Classic_binary_expr; using Comma = Classic_binary_expr; using Const_cast = Conversion_expr; - using Datum = Conversion_expr; using Div = Classic_binary_expr; using Div_assign = Classic_binary_expr; using Dot = Classic_binary_expr; @@ -1144,19 +1144,15 @@ namespace ipr { Category_code operation() const final; }; - using Conditional = Ternary>>; - - struct New : Classic> { - Optional where; - const ipr::Type& what; - Optional args; + struct New : impl::Classic_binary_expr { + bool global = false; - New(Optional, const ipr::Type&, Optional); - Optional placement() const final; - const ipr::Type& allocated_type() const final; - Optional initializer() const final; + New(Optional, const ipr::Construction&); + bool global_requested() const final; }; + using Conditional = Ternary>>; + struct expr_factory { // Returns an IPR node for unified string literals. const ipr::String& get_string(const char*); @@ -1224,6 +1220,7 @@ namespace ipr { Unary_minus* make_unary_minus(const ipr::Expr&, Optional = {}); Unary_plus* make_unary_plus(const ipr::Expr&, Optional = {}); Expansion* make_expansion(const ipr::Expr&, Optional = {}); + Construction* make_construction(const ipr::Type&, const ipr::Enclosure&); And* make_and(const ipr::Expr&, const ipr::Expr&, Optional = {}); Array_ref* make_array_ref(const ipr::Expr&, const ipr::Expr&, Optional = {}); @@ -1241,7 +1238,6 @@ namespace ipr { Coerce* make_coerce(const ipr::Expr&, const ipr::Type&, const ipr::Type&); Comma* make_comma(const ipr::Expr&, const ipr::Expr&, Optional = {}); Const_cast* make_const_cast(const ipr::Type&, const ipr::Expr&); - Datum* make_datum(const ipr::Type&, const ipr::Enclosure&); Div* make_div(const ipr::Expr&, const ipr::Expr&, Optional = {}); Div_assign* make_div_assign(const ipr::Expr&, const ipr::Expr&, Optional = {}); Dot* make_dot(const ipr::Expr&, const ipr::Expr&, Optional = {}); @@ -1275,8 +1271,7 @@ namespace ipr { Static_cast* make_static_cast(const ipr::Type&, const ipr::Expr&); Qualification* make_qualification(const ipr::Expr&, ipr::Type_qualifier, const ipr::Type&); Binary_fold* make_binary_fold(Category_code, const ipr::Expr&, const ipr::Expr&, Optional = {}); - New* make_new(const ipr::Type& allocated, Optional init = {}, - Optional placement = {}, Optional result = {}); + New* make_new(Optional, const ipr::Construction&, Optional = {}); Conditional* make_conditional(const ipr::Expr&, const ipr::Expr&, const ipr::Expr&, Optional = {}); @@ -1331,6 +1326,7 @@ namespace ipr { stable_farm unary_minuses; stable_farm unary_pluses; stable_farm expansions; + stable_farm constructions; stable_farm scope_refs; stable_farm ands; @@ -1348,7 +1344,6 @@ namespace ipr { stable_farm calls; stable_farm commas; stable_farm ccasts; - stable_farm data; stable_farm divs; stable_farm div_assigns; stable_farm dots; diff --git a/include/ipr/interface b/include/ipr/interface index 861770c..65096af 100644 --- a/include/ipr/interface +++ b/include/ipr/interface @@ -179,7 +179,7 @@ namespace ipr { struct Coerce; // generalized type conversion -- implicit conversion struct Comma; // comma-operator a, b struct Const_cast; // const-cast const_cast(v) - struct Datum; // object construction T(v) + struct Construction; // object construction T(v) struct Div; // division a / b struct Div_assign; // in-place division a /= b struct Dot; // direct member selection x.m @@ -1269,6 +1269,19 @@ namespace ipr { // Integral or floating point promotion -- "(int)'2'" struct Promote : Unary> { }; + // -- Construction -- + // An expression of the form "T(e1, e2, .. en)" or "T{e1, e2, .. en}" + // where "T" is a type and "ei"s are expressions. This is not a function + // call -- although syntactically it looks like so. "T" will + // be the `type()' of this expression. + // The contructor selected for the construction operation is indicated + // by implementation, which is inherited from Classic. + struct Construction : Unary, + const Enclosure&> { + // The sequence of arguments used for this construction + Arg_type arguments() const { return operand(); } + }; + // -- Read -- // Lvalue-to-rvalue conversion -- "= var" struct Read : Unary> { }; @@ -1417,18 +1430,6 @@ namespace ipr { // const_cast-expression -- "const_cast(expr)". struct Const_cast : Cast_expr { }; - // -- Datum -- - // An expression of the form "T(e1, e2, .. en)" where "T" - // is a type and "ei"s are expressions. This is not a function - // call -- although syntactically it looks like so. "T" will - // be the `type()' of this expression. - struct Datum : Binary, - const Type&, const Enclosure&> { - // See comments for the various cast operators regarding type(). - - Arg2_type args() const { return second(); } - }; - // -- Div -- // Division-expression -- "a / b" struct Div : Binary> { }; @@ -1580,10 +1581,18 @@ namespace ipr { // This node represents a new-expression: // ::_opt new new-placement_opt new-type-id new-initializer_opt // ::_opt new new-placement_opt ( type-id ) new-initializer_opt - struct New : Category { - virtual Optional placement() const = 0; - virtual const Type& allocated_type() const = 0; - virtual Optional initializer() const = 0; + // Semantically, this has a binary structure where the first operand + // is the placement-list, and the second operand is a construction expression + // that indicates the new-type-id or the type-id coupled with the new-initializer if any. + // When the new-initializer is missing, the Enclosure of the Contruction has no delimiter + // and the arguments of the Enclosure is a Phantom node. + // The allocator function is indicated by the implementation(). + struct New : Binary, + Optional, const Construction&> { + // This predicate holds if the new-expression explicitly requested a global allocator. + virtual bool global_requested() const = 0; + Optional placement() const { return first(); } + const Construction& initializer() const { return second(); } }; // -- Conditional -- @@ -2178,7 +2187,7 @@ namespace ipr { virtual void visit(const Coerce&); virtual void visit(const Comma&); virtual void visit(const Const_cast&); - virtual void visit(const Datum&); + virtual void visit(const Construction&); virtual void visit(const Div&); virtual void visit(const Div_assign&); virtual void visit(const Dot&); diff --git a/include/ipr/node-category b/include/ipr/node-category index 8457607..1ebff84 100644 --- a/include/ipr/node-category +++ b/include/ipr/node-category @@ -96,7 +96,7 @@ Cast, // ipr::Cast Coerce, // ipr::Coerce Comma, // ipr::Comma Const_cast, // ipr::Const_cast -Datum, // ipr::Datum +Construction, // ipr::Construction Div, // ipr::Div Div_assign, // ipr::Div_assign Dot, // ipr::Dot diff --git a/src/impl.cxx b/src/impl.cxx index d812a11..eec5e1a 100644 --- a/src/impl.cxx +++ b/src/impl.cxx @@ -58,16 +58,11 @@ namespace ipr { }; // -- impl::New -- - New::New(Optional where, const ipr::Type& what, - Optional args) - : where{ where }, what{ what }, args{ args } + New::New(Optional where, const ipr::Construction& expr) + : Classic_binary_expr{ where, expr } { } - Optional New::placement() const { return where; } - - const ipr::Type& New::allocated_type() const { return what; } - - Optional New::initializer() const { return args; } + bool New::global_requested() const { return global; } // ------------------------------------- // -- master_decl_data -- @@ -1677,6 +1672,13 @@ namespace ipr { return expansion; } + impl::Construction* + expr_factory::make_construction(const ipr::Type& t, const ipr::Enclosure& e) { + auto x = constructions.make(e); + x->constraint = &t; + return x; + } + impl::And* expr_factory::make_and(const ipr::Expr& l, const ipr::Expr& r, Optional result) { impl::And* and_expr = ands.make(l, r); @@ -1788,11 +1790,6 @@ namespace ipr { return ccasts.make(t, e); } - impl::Datum* - expr_factory::make_datum(const ipr::Type& t, const ipr::Enclosure& e) { - return data.make(t, e); - } - impl::Div* expr_factory::make_div(const ipr::Expr& l, const ipr::Expr& r, Optional result) { impl::Div* div = divs.make(l, r); @@ -2032,9 +2029,8 @@ namespace ipr { } impl::New* - expr_factory::make_new(const ipr::Type& allocated, Optional init, - Optional placement, Optional result) { - impl::New* new_expr = news.make(placement, allocated, init); + expr_factory::make_new(Optional placement, const ipr::Construction& expr, Optional result) { + impl::New* new_expr = news.make(placement, expr); new_expr->constraint = result; return new_expr; } diff --git a/src/io.cxx b/src/io.cxx index b219710..6a50989 100644 --- a/src/io.cxx +++ b/src/io.cxx @@ -519,10 +519,10 @@ namespace ipr << token('(') << e.args() << token(')'); } - void visit(const Datum& e) override + void visit(const Construction& e) override { pp << xpr_type(e.type()) - << xpr_primary_expr(e.args()); + << xpr_primary_expr(e.arguments()); } // postfix-expression -- @@ -624,14 +624,10 @@ namespace ipr void visit(const New& e) override { pp << xpr_identifier("new") << token(' '); - if (auto p = e.placement()) pp << token('(') << p.get() << token(") "); - - pp << xpr_type(e.allocated_type()); - - if (auto init = e.initializer()) - pp << token(" (") << init.get() << token(')'); + // Note: The following does not exactly conform to the ISO C++ grammar (because of ambiguity). + pp << xpr_expr(e.initializer()); } void visit(const Delete& e) override diff --git a/src/traversal.cxx b/src/traversal.cxx index b4dc2ca..f371614 100644 --- a/src/traversal.cxx +++ b/src/traversal.cxx @@ -643,7 +643,7 @@ ipr::Visitor::visit(const Not_equal& e) } void -ipr::Visitor::visit(const Datum& e) +ipr::Visitor::visit(const Construction& e) { visit(as(e)); }