Skip to content

copies

def Copies.classOf (g : Globals Cpp.constructs) (t : Ty Cpp.constructs) : Option ClassMembers

The class of a type, if it is one the program defines.

def ClassMembers.passedByAddress (c : ClassMembers) : Bool

Whether a class is passed by the address of a copy: it has a copy or move constructor or a destructor.

def ClassMembers.copyDeleted (c : ClassMembers) (e : TypedExpr Cpp.constructs) : Bool

Whether copying an object of a class from a value is not allowed: the class declares a move and so its implicit copy constructor is deleted, and the value is an lvalue (an rvalue is moved).

def ClassMembers.deletedCopy (n : NodeId) (c : ClassMembers) : CheckResult Cpp.constructs (Lifted Cpp.constructs)

The rejection of copying an object of a class whose copy constructor is deleted.

def Copies.parameterType (g : Globals Cpp.constructs) (t : Ty Cpp.constructs) : Ty Cpp.constructs

How a parameter of a type is passed: a class passed by address as passedByAddress, any other as it is.

def Copies.constructorFor (g : Globals Cpp.constructs) (u : Ty Cpp.constructs) (moving : Bool) : Option String

The constructor a copy of an object of a class is made by, if it has one: the move constructor for an xvalue (or a value that may be moved from, moving) when the class has one, else the copy constructor.

def Copies.constructorCall (g : Globals Cpp.constructs) (n : NodeId) (f : String) (target : TypedExpr Cpp.constructs) (source : TypedExpr Cpp.constructs) : List (TypedStmt Cpp.constructs)

The call at the node n of the copy or move constructor f (its signature among the globals g) on the object at target from the object at source: the parameters after those take their defaults ([class.copy.ctor]p1), whose statements come first.

def Copies.argument (g : Globals Cpp.constructs) (n : NodeId) (u : Ty Cpp.constructs) (e : TypedExpr Cpp.constructs) : Lifted Cpp.constructs

An argument for a parameter passed by address: the address of the caller’s copy (made by the move constructor for an xvalue, else the copy constructor, else bit for bit), or of the temporary itself.

def Copies.conversion (g : Globals Cpp.constructs) (n : NodeId) (t : Ty Cpp.constructs) (e : TypedExpr Cpp.constructs) : Option (CheckResult Cpp.constructs (Lifted Cpp.constructs))

C++’s conversion for a parameter passed by address.

def Copies.assignmentName (op : Option BinaryOp) : String

The member function an assignment calls on an object of a class: operator=, or operator+= and the others for a compound assignment.

def Copies.keptRight (checker : Checker Cpp.constructs) (g : Globals Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (rhs : Expr) (l : Lifted Cpp.constructs) : Option Kept

The right operand rhs of an assignment to an object of a class, checked by checker with the globals g in the scope env, kept before the left one (Classes.kept, at the node n), when the left one, checked as l, has statements of its own and the right one makes an access: C++17 sequences the right operand before the left ([expr.ass]p1), and an operator function’s operands as the built-in operator’s ([over.match.oper]p2). Else none: the operands as written.

def Copies.assignment (checker : Checker Cpp.constructs) (g : Globals Cpp.constructs) (env : Env Cpp.constructs) (asLvalue : Bool) (e : Expr) : Option (CheckResult Cpp.constructs (Lifted Cpp.constructs))

An assignment to an object of a class with a copy assignment operator (or compound, += and the others): a call of it, a.operator=(b) ([over.ass]), an lvalue when the operator returns a reference (&(a = b)); its access and constness are checked as a member function call’s. The right operand goes first (Copies.keptRight).

def Copies.isGlobal (g : Globals Cpp.constructs) (x : DeclId) : Bool

Whether a variable is a global one.

def Copies.otherReturned (y : DeclId) (s : Stmt) : Bool

Whether a statement is a return of something other than the variable y.

def Copies.declares (y : DeclId) (s : Stmt) : Bool

Whether a statement declares the variable y.

def Copies.after (y : DeclId) (ss : List Stmt) : Option (List Stmt)

The statements after the declaration of y among statements (its scope in their block), if they declare it.

def Copies.otherInScope (y : DeclId) (s : Stmt) : Bool

Whether a statement is a block declaring y in which a return after the declaration returns something else.

def Copies.ofLibrary (g : Globals Cpp.constructs) (x : String) : Bool

Whether a class is a library’s: std’s, or one a library written in C++ defines (a function of it is the library’s, CppTables.library). A library’s copies, moves and destruction write nothing the program sees (the libraries keep to that: the Arduino String’s are malloc and free), so whether a return elides one does not change the output.

def Copies.onlyReturned (g : Globals Cpp.constructs) (y : DeclId) : Bool

Whether every return in the scope of the variable y returns it (when clang elides its copy, as its NRVO does: another return in the function, outside y’s scope, does not matter).

def Copies.returnValue (assign : Globals Cpp.constructs -> NodeId -> Ty Cpp.constructs -> TypedExpr Cpp.constructs -> CheckResult Cpp.constructs (Lifted Cpp.constructs)) (checker : Checker Cpp.constructs) (c : StatementContext Cpp.constructs) (env : Env Cpp.constructs) (n : NodeId) (t : Ty Cpp.constructs) (x : Expr) : Option (CheckResult Cpp.constructs (TypedStmt Cpp.constructs))

How a value of a class passed by address is returned ([stmt.return], [class.copy.elision]): a temporary (a call’s result) is handed over as it is; a local object every return in its scope returns is handed over without a copy, as clang does, noting that the standard also allows copying it; anything else (a parameter, a member, a global, one of several local objects returned) is copied first by the copy constructor (else bit for bit) and the copy handed over; a local object or a parameter named alone is moved instead when the class has a move constructor ([class.copy.elision]p3), as is an xvalue. Handing over keeps the object from being destroyed when its scope ends: the caller has it now.