overloading
本頁內容尚未翻譯。
cpp.Overloading.numbered
Section titled “cpp.Overloading.numbered”def Overloading.numbered (name : String) (k : Nat) : StringThe name of the k-th function of a name, when there is more than one.
cpp.Overloading.candidates
Section titled “cpp.Overloading.candidates”def Overloading.candidates (g : Globals Cpp.constructs) (name : String) : List StringThe functions an overloaded name stands for: the signatures named name#k.
cpp.Overloading.objectRank
Section titled “cpp.Overloading.objectRank”def Overloading.objectRank (objectConst : Bool) (this : Ty Cpp.constructs) : Option NatHow an object matches a member function’s implicit object parameter (its this): none when the object is const
and the function is not; 1 when only the function is const (a qualification added), else 0.
cpp.Overloading.ranks
Section titled “cpp.Overloading.ranks”def Overloading.ranks (k : Choosing) (g : Globals Cpp.constructs) (n : NodeId) (object : Option Bool) (args : List (TypedExpr Cpp.constructs)) (f : String) : Option (List Nat)A candidate’s ranks for the arguments (and the object, for a member function), if it is viable: the parameters after the arguments must all have defaults ([over.match.viable]p2.3).
cpp.Overloading.pick
Section titled “cpp.Overloading.pick”def Overloading.pick (k : Choosing) (g : Globals Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (display : String) (candidates : List String) (templated : List String) (object : Option Bool) (args : List Expr) : CheckResult Cpp.constructs StringThe function a call chooses among candidates (object: whether the object is const, for member functions); of two
as good for every argument, one that is not a template’s instance (templated) is better ([over.match.best]p2.4).
A library class’s member function with none viable or two as good is not provided (Mismatch).
cpp.Braced.items
Section titled “cpp.Braced.items”def Braced.items (i : Init) : List InitThe items of a braced list’s initializer i (none for any other initializer).
cpp.Braced.textForCharacters
Section titled “cpp.Braced.textForCharacters”def Braced.textForCharacters (element : TypeSyntax) (xs : List Init) : BoolWhether a list for elements of the written type element has a string literal for characters ({"abc"} of a
string: no element can be made from it, [over.ics.list]p6). This is the part of viability that needs no scope.
xs is the list.
cpp.Braced.listed
Section titled “cpp.Braced.listed”def Braced.listed (g : Globals Cpp.constructs) (name : String) (xs : List Init) : BoolWhether a braced list with items xs initializing the class named name (in the globals g) is its initializer-list
constructor’s list (Construction.listFor), not other constructors’ arguments ([over.match.list]p1).
cpp.Braced.target
Section titled “cpp.Braced.target”def Braced.target (t : Ty Cpp.constructs) : Ty Cpp.constructsThe type a parameter of type t initializes from a braced list: what a reference refers to, the class of a parameter
passed by value (which a call passes by its address, as Construction.rank reads it).
cpp.Braced.against
Section titled “cpp.Braced.against”def Braced.against (g : Globals Cpp.constructs) (t : Ty Cpp.constructs) (e : Expr) : ExprThe expression e, a braced list, as the object of the type t it initializes (in the globals g, [dcl.init.list]p3): a class’s T{a, b} (a constructor or
an aggregate), a scalar’s single element; any other expression, or a list this does not convert, as it is. A list for a
class with an initializer-list constructor stays as it is (unknown where it is checked): its backing array would have
to be declared before the expression, which a call’s argument cannot have without moving it out of its order.
cpp.Braced.isAggregate
Section titled “cpp.Braced.isAggregate”def Braced.isAggregate (cls : ClassMembers) : BoolWhether a class is an aggregate here: it has no constructors (its members are initialized from a list).
cpp.Braced.converts
Section titled “cpp.Braced.converts”def Braced.converts (g : Globals Cpp.constructs) (t : Ty Cpp.constructs) (e : Expr) : BoolWhether Braced.against converts e, a braced list, for a parameter of type t (in the globals g; it does not for a
class with an initializer-list constructor).
cpp.Overloading.isOverloaded
Section titled “cpp.Overloading.isOverloaded”def Overloading.isOverloaded (g : Globals Cpp.constructs) (name : String) : BoolWhether a name is overloaded here: no function has it, and functions name#k do.
cpp.Overloading.addressed
Section titled “cpp.Overloading.addressed”def Overloading.addressed (g : Globals Cpp.constructs) (e : Expr) : Option StringThe overloaded name an expression uses as a function (f or &f), if it is one.
cpp.Overloading.naming
Section titled “cpp.Overloading.naming”def Overloading.naming (chosen : String) (e : Expr) : ExprThe expression with the function it names replaced by the chosen one.
cpp.Overloading.ofType
Section titled “cpp.Overloading.ofType”def Overloading.ofType (k : Choosing) (g : Globals Cpp.constructs) (t : Ty Cpp.constructs) (name : String) : Option StringThe function of an overloaded name whose pointer has the target’s type ([over.over]p1), if there is one.
cpp.Overloading.against
Section titled “cpp.Overloading.against”def Overloading.against (k : Choosing) (g : Globals Cpp.constructs) (env : Env Cpp.constructs) (t : Ty Cpp.constructs) (e : Expr) : Option (CheckResult Cpp.constructs (Lifted Cpp.constructs))An overloaded name used as a function where a type is expected: the function of that type, checked.
cpp.Overloading.arguments
Section titled “cpp.Overloading.arguments”def Overloading.arguments (k : Choosing) (g : Globals Cpp.constructs) (f : String) (args : List Expr) : Option (List Expr)A call’s arguments with each overloaded name used as a function replaced by the one of its parameter’s type (the others as they are); none when no argument is such a name or the function is not one of the program’s.
cpp.Overloading.withTemplate
Section titled “cpp.Overloading.withTemplate”def Overloading.withTemplate (k : Choosing) (g : Globals Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (f : String) (args : List Expr) : Option (CheckResult Cpp.constructs String)A call (without template arguments) of a name both ordinary functions and function templates have ([temp.over]): the ordinary ones and, of every template of the name taking that many arguments, the instance for the deduced arguments are the candidates (an instance asked for first when the program does not have it yet, one at a time); templates whose deduction fails are left out. None for any other name.
cpp.Overloading.expression
Section titled “cpp.Overloading.expression”def Overloading.expression (k : Choosing) (g : Globals Cpp.constructs) (env : Env Cpp.constructs) (e : Expr) : Option (CheckResult Cpp.constructs (Lifted Cpp.constructs))A call of an overloaded free function: the chosen one’s call, as an expression.
cpp.Overloading.assignmentOf
Section titled “cpp.Overloading.assignmentOf”def Overloading.assignmentOf (n : NodeId) (m : NodeId) (lhs : Expr) (value : Expr) : StmtThe statement at n assigning value to lhs, the assignment at m.
cpp.Overloading.bracedValue
Section titled “cpp.Overloading.bracedValue”def Overloading.bracedValue (c : StatementContext Cpp.constructs) (t : Ty Cpp.constructs) (b : NodeId) (init : Init) : ExprThe braced list init (at b) as the value of type t (in the context c) it makes (Braced.against).
cpp.Overloading.assignedList
Section titled “cpp.Overloading.assignedList”def Overloading.assignedList (k : Choosing) (g : Globals Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (cls : ClassMembers) (xs : List Init) : Option (String * TypeSyntax)The std::initializer_list<E> an operator= of the class cls takes, with E, when the items xs can make one
([over.ics.rank]p3.1: a list converted to std::initializer_list is better than one converted to the class, so this
operator= is the one x = {…} calls, {} included).
k chooses, g and env are the declarations and the scope the items are checked in, n is the node of the list.
cpp.Overloading.listAssignment
Section titled “cpp.Overloading.listAssignment”def Overloading.listAssignment (statements : StatementChecker Cpp.constructs) (c : StatementContext Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (m : NodeId) (lhs : Expr) (b : NodeId) (xs : List Init) (list : String * TypeSyntax) : CheckResult Cpp.constructs (TypedStmt Cpp.constructs)The statement at n assigning the braced list xs (at b) to lhs through an operator= taking list
([over.ass], [dcl.init.list]p5): the backing array declared first (the right operand goes first, [expr.ass]p1), then the
call with the std::initializer_list over it, the block’s end destroying the array. An empty list has no array.
statements checks the statement it makes, in the context c and the scope env; m is the node of the assignment.
cpp.Overloading.choosesExplicit
Section titled “cpp.Overloading.choosesExplicit”def Overloading.choosesExplicit (k : Choosing) (g : Globals Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (cls : ClassMembers) (xs : List Init) : BoolWhether the constructor copy-list-initialization chooses for the items xs is explicit ([over.match.list]p1: then the
list initializes nothing; for x = {…}, no operator= can take it).
k chooses, g and env are the declarations and the scope the items are checked in, n is the node of the list,
cls the class.
cpp.Overloading.classAssignment
Section titled “cpp.Overloading.classAssignment”def Overloading.classAssignment (k : Choosing) (statements : StatementChecker Cpp.constructs) (c : StatementContext Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (m : NodeId) (lhs : Expr) (b : NodeId) (init : Init) (t : Ty Cpp.constructs) (cls : ClassMembers) : CheckResult Cpp.constructs (TypedStmt Cpp.constructs)The statement at n assigning the braced list init (at b) to lhs, of the class cls and type t: operator= taking
the list when there is one that can (Overloading.listAssignment); else x = T{…} ([expr.ass]p9): the list made into
a variable as a declaration of T would make it (an aggregate’s members, an initializer-list constructor) and moved
from, as the temporary T{…} would be; any other class is assigned T{…}, its constructors chosen as for a temporary.
k chooses, statements checks the statement it makes, in the context c and the scope env; m is the node of the
assignment.
cpp.Overloading.bracedAssignment
Section titled “cpp.Overloading.bracedAssignment”def Overloading.bracedAssignment (k : Choosing) (statements : StatementChecker Cpp.constructs) (c : StatementContext Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (m : NodeId) (lhs : Expr) (b : NodeId) (init : Init) : CheckResult Cpp.constructs (TypedStmt Cpp.constructs)The statement at n assigning the braced list init (at b) to lhs, the assignment at m ([expr.ass]p9), checked by k and
statements in the context c and the scope env: a scalar’s single element (not narrowed in C++), a class’s by
Overloading.classAssignment, a C struct’s members. The right operand is evaluated before the left ([expr.ass]p1).
cpp.Overloading.statement
Section titled “cpp.Overloading.statement”def Overloading.statement (k : Choosing) (statements : StatementChecker Cpp.constructs) (c : StatementContext Cpp.constructs) (env : Env Cpp.constructs) (s : Stmt) : Option (CheckResult Cpp.constructs (TypedStmt Cpp.constructs))A call of an overloaded free function as a statement: the chosen one’s call.
cpp.Overloading.parameterKey
Section titled “cpp.Overloading.parameterKey”def Overloading.parameterKey (aliases : List (String * TypeSyntax)) (t : TypeSyntax) : StringA parameter’s type t as a function’s signature has it ([dcl.fct]p5): an array or a function as the pointer it is
adjusted to, its own const dropped, the names of the typedefs aliases expanded (Classes.typeKey).
cpp.Overloading.resultKey
Section titled “cpp.Overloading.resultKey”def Overloading.resultKey (aliases : List (String * TypeSyntax)) (r : Option TypeSyntax) : StringA function’s return type r as a key (v for void), through the typedefs aliases.
cpp.Overloading.freeFunctions
Section titled “cpp.Overloading.freeFunctions”def Overloading.freeFunctions (qualifier : String) (items : List Item) : List (String * FunctionDefinition)The free functions of the items as written, with their names qualified by the namespaces they are in (qualifier:
the enclosing namespaces’ prefix).
cpp.Overloading.redefinition
Section titled “cpp.Overloading.redefinition”def Overloading.redefinition (aliases : List (String * TypeSyntax)) (seen : List (String * FunctionDefinition)) (fs : List (String * FunctionDefinition)) : Option (NodeId * Refusal)The first of the free functions fs defined again with the same parameter types as an earlier one of its name
(among seen): a redefinition, or one that differs only in its return type; the typedefs aliases expanded.
cpp.Overloading.redefined
Section titled “cpp.Overloading.redefined”def Overloading.redefined (p : Program) : Option (NodeId * Refusal)The first free function of the program p as written that is defined twice.
cpp.Overloading.renamed
Section titled “cpp.Overloading.renamed”def Overloading.renamed (items : List Item) : List ItemThe free functions of a name declared more than once, or a function template’s name too ([temp.over]: the
template’s instance is chosen among them), renamed f#k in order.
cpp.Overloading.prepare
Section titled “cpp.Overloading.prepare”def Overloading.prepare (p : Program) : ProgramA program with its overloaded free functions renamed.