跳到內容

construction

本頁內容尚未翻譯。

def Construction.rawArray : String

The internal functions a container’s generated code calls for its elements (as std::allocator and std::allocator_traits do): a block of elements allocated without constructing them (#rawArray(new T[n])), an object constructed at a pointer with arguments (placement new, #construct(p, args)), one destroyed there (#destroy(p), nothing for an element without a destructor), a block released without destroying its elements (#releaseRaw(p)), an object moved to a pointer as a whole (#relocate(to, from): the source is not destroyed afterwards, as a moved-from vector or string owns nothing).

def Construction.constructAt : String

Placement new (see Construction.rawArray).

def Construction.destroyAt : String

An object’s destruction at a pointer (see Construction.rawArray).

def Construction.releaseRaw : String

A block’s release without destroying its elements (see Construction.rawArray).

def Construction.valueConstructAt : String

The internal function value-initializing an object at a pointer (::new (p) T(), [dcl.init]p9): a scalar zero, an object of a class by its default constructor.

def Construction.relocate : String

An object moved as a whole (see Construction.rawArray).

def TypedCpp : Type

A typed statement of C++.

def Assigning : Type

How a value is converted for storing into an object of a type (the dialect’s assignment conversion).

record Choosing

What choosing a constructor uses: the types, the assignment conversion, and the checker of expressions.

record Constructing

What checking a construction as a statement uses: what choosing uses, and the checker of statements.

def Construction.resolve (types : TypeExtension Cpp.constructs) (g : Globals Cpp.constructs) (t : TypeSyntax) : Option (Ty Cpp.constructs)

A written type resolved and completed (a class’s struct with its members).

def Construction.promotes (p : Platform) (a : Ty Cpp.constructs) (b : Ty Cpp.constructs) : Bool

Whether a type converts to another by a promotion ([conv.prom], [conv.fpprom]): an integer type to its promoted type, float to double.

def Construction.rank (k : Choosing) (g : Globals Cpp.constructs) (n : NodeId) (parameter : Ty Cpp.constructs) (argument : TypedExpr Cpp.constructs) : Option Nat

How well an argument matches a parameter ([over.ics.rank]), if it can be passed at all: by the conversion, 0 the same type (or a reference bound to it), 1 a promotion, 2 any other standard conversion, 3 a pointer converted to void * or bool, 4 a user-defined conversion; four times that, two more for const added to a pointer’s pointee and one more for an rvalue bound to an lvalue reference (worse than to an rvalue reference, [over.ics.rank]p3.2.3).

def Construction.better (a : List Nat) (b : List Nat) : Bool

Whether one candidate’s ranks are no worse than another’s for every argument and better for one ([over.match.best]p2).

def Construction.ranks (k : Choosing) (g : Globals Cpp.constructs) (n : NodeId) (args : List (TypedExpr Cpp.constructs)) (f : Constructor) : Option (List Nat)

The ranks of a constructor’s parameters for the arguments, if every argument can be passed (the parameters after this, from the lowered function’s signature).

record Viable

A viable constructor for a construction’s arguments: the constructor (a constructor template’s with its instance as the function), its parameters’ ranks, and for a constructor template the template and the arguments deduced (its instance is asked for when the program does not have it yet).

def Construction.templateViable (k : Choosing) (g : Globals Cpp.constructs) (n : NodeId) (args : List (TypedExpr Cpp.constructs)) (f : Constructor) : Option Viable

The constructor template f’s instance for the arguments args, if viable ([temp.deduct.call], [over.match.funcs]p7; k checks, in the globals g, at the node n): the template arguments deduced from the arguments’ types (the function template f.function is the constructor lowered, this first, Classes.constructorTemplateItems; a default template argument whose substitution fails is no candidate), each argument ranked against its parameter with the deduced arguments in place.

def Construction.noWorse (a : List Nat) (b : List Nat) : Bool

Whether a candidate’s ranks a are no worse than another’s, b, for every argument.

def Viable.beats (c : Viable) (d : Viable) : Bool

Whether the viable constructor c is better than d ([over.match.best]p2): no worse for every argument, and better for one, or c is not a template’s instance and d is (p2.4).

def Viable.chosen (g : Globals Cpp.constructs) (v : Viable) : CheckResult Cpp.constructs Constructor

The chosen constructor v, its function the program’s (in the globals g): a constructor template’s instance the program does not have yet is asked for (the program is prepared and checked again with it, as a function template’s).

def Construction.choose (k : Choosing) (g : Globals Cpp.constructs) (n : NodeId) (cls : ClassMembers) (args : List (TypedExpr Cpp.constructs)) : CheckResult Cpp.constructs Constructor

The constructor for the arguments: among those taking as many (or more, with defaults), the ones every argument can be passed to, and of those the one better than every other ([over.match.best]); a constructor template is a candidate by the instance its deduction gives (Construction.templateViable); none is no match, several are ambiguous.

def Construction.trivialCopy (k : Constructing) (c : StatementContext Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (cls : ClassMembers) (object : Expr) (args : List Expr) : Option (CheckResult Cpp.constructs (TypedStmt Cpp.constructs))

A copy of an object of a class without a copy constructor (its implicit one is trivial, [class.copy.ctor]p12): the other object (of the class, or of one derived from it: its base subobject) stored bit for bit. None unless the one argument is such an object.

def Construction.constructorCall (k : Constructing) (c : StatementContext Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (cls : ClassMembers) (object : Expr) (args : List Expr) : CheckResult Cpp.constructs (TypedStmt Cpp.constructs)

The call of a class’s constructor on an object (its address and the arguments), checked as a statement: the constructor chosen for the arguments, accessible here.

def TypedExpr.isTemporary {L : Constructs} (e : TypedExpr L) : Bool

Whether an expression is a temporary the full expression ends (a call’s result, kept in a variable named for it).

def Construction.fromTemporary (k : Constructing) (c : StatementContext Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (x : DeclId) (name : String) (u : Ty Cpp.constructs) (args : List Expr) : Option (CheckResult Cpp.constructs (TypedStmt Cpp.constructs))

An object initialized by a temporary of its class (a call’s result): the temporary becomes the object, without a copy ([dcl.init]p17.6.1, C++17’s guaranteed elision); it is handed over, so the full expression’s end does not destroy it. None when the initializer is anything else.

def Construction.declareOf (k : Constructing) (c : StatementContext Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (x : DeclId) (name : String) (u : Ty Cpp.constructs) (cls : ClassMembers) (args : List Expr) : CheckResult Cpp.constructs (TypedStmt Cpp.constructs)

A declaration of an object of a class with constructors (its type resolved): initialized by a temporary of its class, else reserved, constructed with the arguments, and only then an object (a constructor that throws leaves none to destroy, [except.ctor]p3). A const object is not const while it is constructed ([class.ctor]p5).

def Construction.declareObject (k : Constructing) (c : StatementContext Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (x : DeclId) (name : String) (t : TypeSyntax) (cls : ClassMembers) (args : List Expr) : CheckResult Cpp.constructs (TypedStmt Cpp.constructs)

A declaration of an object of a class with constructors, by its written type.

def Construction.arguments (i : Option Init) : Option (List Expr)

The arguments of an initializer for a constructor: none, the expression, or the braced list’s expressions.

def Construction.classOf (g : Globals Cpp.constructs) (t : TypeSyntax) : Option ClassMembers

The class with constructors a declaration’s type names, if any.

def Construction.scalar (k : Constructing) (c : StatementContext Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (y : String) (args : List Expr) : CheckResult Cpp.constructs (TypedStmt Cpp.constructs)

A member that is not of a class with constructors initialized in a constructor: the value (zero for x()) converted to the member’s type and stored, even into a const member (an initialization, not an assignment).

def Construction.guarded (k : Constructing) (c : StatementContext Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (y : String) (call : TypedStmt Cpp.constructs) : CheckResult Cpp.constructs (TypedStmt Cpp.constructs)

A constructed member’s guard after its construction: a pointer to it, declared in the constructor’s scope (named, so it is no temporary of the full expression and lasts to the scope’s end), which destroys it when an exception leaves the constructor ([except.ctor]p3: the constructed members and bases, in reverse order).

def Construction.member (k : Constructing) (c : StatementContext Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (y : String) (args : List Expr) : CheckResult Cpp.constructs (TypedStmt Cpp.constructs)

A member initialized in a constructor: one of a class with constructors is constructed (this->y with the arguments), any other initialized by its value; guarded when its class has a destructor.

def Construction.defaulted (k : Constructing) (c : StatementContext Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (y : String) : CheckResult Cpp.constructs (TypedStmt Cpp.constructs)

A member of a class without constructors default-initialized in a constructor: nothing stored, but guarded (the member’s class has a destructor, so it is destroyed if a later member throws, [except.ctor]p3).

def Construction.declaredObject (k : Constructing) (c : StatementContext Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (x : DeclId) (name : String) (t : TypeSyntax) (cls : ClassMembers) (i : Option Init) : Option (CheckResult Cpp.constructs (TypedStmt Cpp.constructs))

A declaration of an object of a class with constructors (no initializer-list constructor taking its list).

def Construction.listTaken (g : Globals Cpp.constructs) (s : Signature Cpp.constructs) : Option (String * TypeSyntax)

The std::initializer_list<E> instance a member function of the signature s takes as its one parameter after this (by value or by reference, [dcl.init.list]p2), with E, if that is what it takes. g holds the declarations of the program.

def Construction.listParameter (g : Globals Cpp.constructs) (cls : ClassMembers) : Option (String * TypeSyntax)

The std::initializer_list<E> instance a class’s initializer-list constructor takes, with E, if it has one. g holds the declarations of the program, cls is the class.

def Construction.itemFits (k : Choosing) (g : Globals Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (t : Ty Cpp.constructs) (i : Init) : Bool

Whether one item of a braced list can initialize an element of type t ([over.ics.list]p6: an initializer-list function is viable only when every item converts to the element type; narrowing is not part of that, it is an error once the function is chosen). An item that does not check is left to the declaration of the list, which reports it. k checks the item and ranks its conversion, g and env are the declarations and the scope it is checked in, n is the node of the list, i the item.

def Construction.listFits (k : Choosing) (g : Globals Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (element : TypeSyntax) (xs : List Init) : Bool

Whether every item of the braced list xs can initialize an element of the written type element. k checks the items and ranks their conversions, g and env are the declarations and the scope they are checked in, n is the node of the list.

def Construction.fromList (k : Constructing) (c : StatementContext Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (place : Expr) (cls : ClassMembers) (list : String * TypeSyntax) (xs : List Init) (after : List (TypedStmt Cpp.constructs)) : CheckResult Cpp.constructs (TypedStmt Cpp.constructs)

An object of the class cls (with an initializer-list constructor taking list) constructed at place from the braced list’s items xs ([dcl.init.list]p3.6, p5): in a block of its own, the backing array const E[n] initialized from them (each copy-initialized), then the constructor called with std::initializer_list<E>(array, n), then after; the block’s end destroys the array. The array and the list object are named for n, the list’s node; k checks the statements in the context c and the scope env.

def Construction.listFor (g : Globals Cpp.constructs) (cls : ClassMembers) (xs : List Init) : Option (String * TypeSyntax)

The initializer-list constructor’s list type a braced list with items xs initializes an object of the class cls by (in the globals g), if any: none for an empty list when the class has a default constructor, which value-initializes it ([dcl.init.list]p3.4, before p3.6: vector<vector<int>> d = {{4, 1}, {}}’s second element is empty, not built from a list of none).

def Construction.listAt (k : Choosing) (g : Globals Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (cls : ClassMembers) (xs : List Init) : Option (String * TypeSyntax)

Construction.listFor, the list also viable for the items as checked in the scope env ([over.match.list]p1: when no initializer-list constructor is viable, the other constructors are tried with the items as arguments: vector<string> v{2, "x"}, string s{name}). k chooses, g holds the declarations of the program, n is the node of the list, cls the class, xs the items.

def Construction.listed (k : Constructing) (c : StatementContext Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (x : DeclId) (name : String) (u : Ty Cpp.constructs) (cls : ClassMembers) (list : String * TypeSyntax) (xs : List Init) : CheckResult Cpp.constructs (TypedStmt Cpp.constructs)

C x = {a, b…} (the declaration n of x, shown as name, of type u, items xs) for a class cls with an initializer-list constructor taking list: x reserved, then constructed from the list (Construction.fromList, with k, c and env) and marked constructed in the list’s block.

def Construction.directScalar (k : Constructing) (c : StatementContext Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (x : DeclId) (name : String) (t : TypeSyntax) (args : List Expr) : CheckResult Cpp.constructs (TypedStmt Cpp.constructs)

T x(args); of a type that is not a class: a scalar’s is its initialization by the one argument (int z(7);, [dcl.init]p17.8), none is default initialization (as T x;), more is excess elements in scalar initializer (clang’s words); any other type takes no constructor’s arguments.

def Construction.statement (k : Constructing) (c : StatementContext Cpp.constructs) (env : Env Cpp.constructs) (s : Stmt) : Option (CheckResult Cpp.constructs (TypedStmt Cpp.constructs))

C++’s statements that construct objects.

def Construction.defaultDeleted (g : Globals Cpp.constructs) (t : TypeSyntax) (i : Option Init) : Bool

Whether a declaration default-initializes an object (or an array of them) of a class that cannot be ([class.default.ctor]p2: its implicit default constructor deleted, or no constructor callable without arguments).

def Construction.noDefault (g : Globals Cpp.constructs) (t : TypeSyntax) : Refusal

Why an object of a class cannot be default-initialized.

def Construction.declared (types : TypeExtension Cpp.constructs) (g : Globals Cpp.constructs) (s : Stmt) : Option (DeclId * Ty Cpp.constructs)

What a statement of C++ declares: C x(args); declares x.

def Construction.destroying (functions : List (CheckedFunction Cpp.constructs)) (t : Ty Cpp.constructs) (pointer : TypedExpr Cpp.constructs) : List (TypedStmt Cpp.constructs)

The call of an object’s class’s destructor (given a pointer to it), if the program has one.

def Construction.ending (functions : List (CheckedFunction Cpp.constructs)) (s : State Cpp.constructs) (x : DeclId) (c : Block Cpp.constructs) (unwinding : Bool) : List (TypedStmt Cpp.constructs)

What runs before an object ends: its class’s destructor, if the program has one; for a member’s guard, the member’s destructor when an exception leaves the scope, else nothing.