Skip to content

Commit c64ee53

Browse files
committed
WLS: Adds description of field access.
Also tidies up the issue of indirect invocation.
1 parent aff038c commit c64ee53

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

WhileyLanguageSpecification/examples/ch6/eg_14.whiley

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ method length(LinkedList l) -> int:
55
if l is null:
66
return 0
77
else:
8-
return 1 + length((*l).next)
8+
return 1 + length(l->next)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type Vec is {int x, int y, int z}
2+
3+
function dotProduct(Vec v1, Vec v2) -> Vec:
4+
return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z)
Binary file not shown.

WhileyLanguageSpecification/src/expressions.tex

+13-16
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,13 @@ \section{Equality Expressions}
251251

252252
\section{Invoke Expressions}
253253
\label{c_expr_invoke}
254-
An {\em function or method invocation} executes a named function or method declared in a given source file. An invocation passes arguments of appropriate number and type to the executed function or method. An invocation may also return one or more values which can be subsequently used.
254+
An {\em function or method invocation} executes a named function or method declared in a given source file. An {\em indirection function or method invocation} executes a function determined by a given expression. An invocation passes arguments of appropriate number and type to the executed function or method. An invocation may also return one or more values which can be subsequently used.
255255

256256
% Could also discuss function or method lookup; this is really part of typing.
257257

258258
\begin{syntax}
259259
\verb+InvokeExpr+ & $::=$ & \verb+Name+ \token{(} \verb+ArgsList+ \token{)}\\
260+
\verb+IndirectInvokeExpr+ & $::=$ & \verb+UnitExpr+\ \token{(}\ \verb+ArgsList+\ \token{)}\\
260261
&&\\
261262
\verb+ArgsList+ & $::=$ & \big[\ \verb+UnitExpr+\ \big(\ \token{,}\ \verb+UnitExpr+\ \big)$^*$\ \big]\\
262263
\end{syntax}
@@ -490,7 +491,6 @@ \subsection{List Constructors}
490491
\section{Record Expressions}
491492
\label{c_expr_record}
492493

493-
494494
Record expressions operate on values of record type (e.g. \lstinline|{int x, int y}|, etc).
495495

496496
% =======================================================================
@@ -500,21 +500,17 @@ \section{Record Expressions}
500500
\subsection{Field Access Expressions}
501501
\label{c_expr_field_access}
502502

503+
The field access operator accepts a value of record type and returns the value held in a given field.
504+
503505
\begin{syntax}
504-
\verb+FieldAccessExpr+ & $::=$ & \verb+UnitExpr+\\
505-
& \big( &\token{.}\ \verb+Ident+\ \big[\ \token{(}\ \verb+ArgsList+\ \token{)}\ \big]\\
506-
& $|$ & \token{->}\ \verb+Ident+\ \big[\ \token{(}\ \verb+ArgsList+\ \token{)}\ \big]\\
507-
& \big)$^+$&\\
506+
\verb+FieldAccessExpr+ & $::=$ & \verb+UnitExpr+\ \token{.}\ \verb+Ident+\\
508507
\end{syntax}
509508

510-
\paragraph{Description.}
511-
512-
The {\em arrow operator} returns a field of the value referenced by the argument.
509+
\paragraph{Examples.} The following example illustrates a field access expression constructor:
513510

514-
\paragraph{Examples.}
515-
516-
\paragraph{Notes.} The arrow operation ``\lstinline{e->f}'' is a short-hand notation for ``\lstinline{(*e).f}'' and can be used when \lstinline{e} has effective record type (\S\ref{c_types_effective_records}).
511+
\lstinputlisting{../examples/ch6/eg_23.whiley}
517512

513+
The above function computes the so-called {\em dot product} of two vectors. The field access operator is used to access the three fields of each vector.
518514

519515
% =======================================================================
520516
% Record Expression
@@ -563,11 +559,11 @@ \subsection{New Expressions}
563559
\subsection{Dereference Expressions}
564560
\label{c_expr_dereference}
565561

566-
A {\em dereference expression} accepts an argument of reference type and returns a value (or element) of the reference's target type. The {\em dereference operator} returns the value referenced by the argument.
562+
A dereference expression accepts an argument of reference type and returns a value (or element) of the reference's target type. The {\em dereference operator} returns the value referenced by the argument. The {\em arrow operator} returns a field of the value referenced by the argument.
567563

568564
\begin{syntax}
569-
\verb+DereferenceExpr+ & $::=$ & \token{*}\ \verb+TermExpr+\\\
570-
& $|$ & \verb+TermExpr+\ \token{->}\ \verb+Identifier+\\
565+
\verb+DereferenceExpr+ & $::=$ & \token{*}\ \verb+TermExpr+\\
566+
& $|$ & \verb+UnitExpr+\ \token{->}\ \verb+Ident+\ \big[\ \token{(}\ \verb+ArgsList+\ \token{)}\ \big]\\
571567
\end{syntax}
572568

573569
\paragraph{Example.} The following illustrates the dereference operator:
@@ -576,7 +572,8 @@ \subsection{Dereference Expressions}
576572

577573
This function traverses a linked list counting the number of links it contains. The arrow operator is used to access the next link in the chain.
578574

579-
\paragraph{Notes.}
575+
\paragraph{Notes.} The arrow operation ``\lstinline{e->f}'' is a short-hand notation for ``\lstinline{(*e).f}'' and can be used when \lstinline{*e} has effective record type (\S\ref{c_types_effective_records}).
576+
580577

581578
% =======================================================================
582579
% Term Expressions

0 commit comments

Comments
 (0)