Changeset 7ad6b6d


Ignore:
Timestamp:
Feb 6, 2018, 11:42:48 AM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
69ce455
Parents:
cbe477e
Message:

Add discussion of reference initialization to the paper, start reference conversions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/general/Paper.tex

    rcbe477e r7ad6b6d  
    12091209The result of this rule is that any reference can be rebound using the existing pointer assignment semantics by assigning a compatible pointer into the address of the reference, \eg @&r1 = &x;@ above.
    12101210This rebinding can occur to an arbitrary depth of reference nesting; $n$ address-of operators applied to a reference nested $m$ times will produce an lvalue pointer nested $n$ times if $n \le m$ (note that $n = m+1$ is simply the usual C rvalue address-of operator applied to the $n = m$ case).
    1211 The explicit address-of operators can be thought of as ``cancelling out'' the implicit dereference operators, \eg @(&`*`)r1 = &x;@ or @(&(&`*`)`*`)r3 = &(&`*`)r1;@ or even @(&`*`)r2 = (&`*`)`*`r3;@ for @&r2 = &r3;@.
     1211The explicit address-of operators can be thought of as ``cancelling out'' the implicit dereference operators, \eg @(&`*`)r1 = &x@ or @(&(&`*`)`*`)r3 = &(&`*`)r1@ or even @(&`*`)r2 = (&`*`)`*`r3@ for @&r2 = &r3@.
    12121212
    12131213Since pointers and references share the same internal representation, code using either is equally performant; in fact the \CFA compiler converts references to pointers internally, and the choice between them in user code can be made based solely on convenience.
     
    12241224\end{cfa}
    12251225
    1226 \TODO{Pull more draft text from user manual; make sure to discuss initialization and reference conversions}
     1226Given that a reference is meant to represent a lvalue, \CFA provides some syntactic shortcuts when initializing references.
     1227There are three initialization contexts in \CFA: declaration initialization, argument/parameter binding, and return/temporary binding.
     1228In each of these contexts, the address-of operator on the target lvalue may (in fact, must) be elided.
     1229The syntactic motivation for this is clearest when considering overloaded operator-assignment, \eg @int ?+=?(int &, int)@; given @int x, y@, the expected call syntax is @x += y@, not @&x += y@.
     1230
     1231This initialization of references from lvalues rather than pointers can be considered a ``lvalue-to-reference'' conversion rather than an elision of the address-of operator; similarly, use of a the value pointed to by a reference in an rvalue context can be thought of as a ``reference-to-rvalue'' conversion.
     1232\CFA includes one more reference conversion, an ``rvalue-to-reference'' conversion.
     1233
     1234\TODO{finish reference conversions; look at user manual}
    12271235
    12281236\subsection{Constructors and Destructors}
Note: See TracChangeset for help on using the changeset viewer.