OLD | NEW |
1 \documentclass{article} | 1 \documentclass{article} |
2 \usepackage{epsfig} | 2 \usepackage{epsfig} |
3 \usepackage{dart} | 3 \usepackage{dart} |
4 \usepackage{bnf} | 4 \usepackage{bnf} |
5 \usepackage{hyperref} | 5 \usepackage{hyperref} |
6 \newcommand{\code}[1]{{\sf #1}} | 6 \newcommand{\code}[1]{{\sf #1}} |
7 \title{Dart Programming Language Specification \\ | 7 \title{Dart Programming Language Specification \\ |
8 {\large Version 1.2}} | 8 {\large Version 1.2}} |
9 \author{The Dart Team} | 9 \author{The Dart Team} |
10 \begin{document} | 10 \begin{document} |
(...skipping 3354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3365 | 3365 |
3366 \begin{grammar} | 3366 \begin{grammar} |
3367 {\bf assignmentOperator:}`=' ; | 3367 {\bf assignmentOperator:}`=' ; |
3368 compoundAssignmentOperator | 3368 compoundAssignmentOperator |
3369 . | 3369 . |
3370 \end{grammar} | 3370 \end{grammar} |
3371 | 3371 |
3372 Evaluation of an assignment $a$ of the form $v$ \code{=} $e$ proceeds as follows
: | 3372 Evaluation of an assignment $a$ of the form $v$ \code{=} $e$ proceeds as follows
: |
3373 | 3373 |
3374 | 3374 |
3375 If there is neither a local variable declaration with name $v$ nor a setter decl
aration with name $v=$ in the lexical scope enclosing $a$, then: | 3375 %If there is neither a local variable declaration with name $v$ nor a setter dec
laration with name $v=$ in the lexical scope enclosing $a$, then: |
3376 \begin{itemize} | 3376 %\begin{itemize} |
3377 \item If $a$ occurs inside a top level or static function (be it function, met
hod, getter, or setter) or variable initializer, evaluation of $a$ causes $e$ t
o be evaluated, after which a \code{NoSuchMethodError} is thrown. | 3377 % \item If $a$ occurs inside a top level or static function (be it function, me
thod, getter, or setter) or variable initializer, evaluation of $a$ causes $e$
to be evaluated, after which a \code{NoSuchMethodError} is thrown. |
3378 \item Otherwise, the assignment is equivalent to the assignment \code{ \THIS{}.
$v$ = $e$}. | 3378 % \item Otherwise, the assignment is equivalent to the assignment \code{ \THIS{}
.$v$ = $e$}. |
3379 \end{itemize} | 3379 % \end{itemize} |
3380 | 3380 |
3381 Otherwise, let $d$ be the innermost declaration whose name is $v$, if it exist
s. | 3381 %Otherwise, |
3382 | 3382 |
3383 If $d$ is the declaration of a local variable, the expression $e$ is evaluated t
o an object $o$. Then, the variable $v$ is bound to $o$. | 3383 Let $d$ be the innermost declaration whose name is $v$ or $v=$, if it exists. |
3384 % unless $v$ is \FINAL{}, in which case a \code{NoSuchMethodError} is thrown (ev
en if there is a noSuchMethod). | |
3385 The value of the assignment expression is $o$. | |
3386 | 3384 |
3387 If $d$ is the declaration of a library variable, the expression $e$ is evaluated
to an object $o$. Then the setter $v=$ is invoked with its formal parameter bou
nd to $o$. The value of the assignment expression is $o$. | 3385 If $d$ is the declaration of a local variable, the expression $e$ is evaluated t
o an object $o$. Then, the variable $v$ is bound to $o$ unless $v$ is \FINAL{} o
r \CONST{}, in which case a dynamic error occurs. |
| 3386 If no error occurs, the value of the assignment expression is $o$. |
3388 | 3387 |
3389 Otherwise, if $d$ is the declaration of a static variable in class $C$, then the
assignment is equivalent to the assignment \code{$C.v$ = $e$}. | 3388 If $d$ is the declaration of a library variable, top level getter or top level s
etter, the expression $e$ is evaluated to an object $o$. Then the setter $v=$ is
invoked with its formal parameter bound to $o$. The value of the assignment exp
ression is $o$. |
| 3389 |
| 3390 Otherwise, if $d$ is the declaration of a static variable, static getter or stat
ic setter in class $C$, then the assignment is equivalent to the assignment \cod
e{$C.v$ = $e$}. |
| 3391 |
| 3392 Otherwise, If $a$ occurs inside a top level or static function (be it function,
method, getter, or setter) or variable initializer, evaluation of $a$ causes $
e$ to be evaluated, after which a \code{NoSuchMethodError} is thrown. |
3390 | 3393 |
3391 Otherwise, the assignment is equivalent to the assignment \code{ \THIS{}.$v$ = $
e$}. | 3394 Otherwise, the assignment is equivalent to the assignment \code{ \THIS{}.$v$ = $
e$}. |
3392 | 3395 |
3393 In checked mode, it is a dynamic type error if $o$ is not \NULL{} and the interf
ace of the class of $o$ is not a subtype of the actual type (\ref{actualTypeOfAD
eclaration}) of $v$. | 3396 In checked mode, it is a dynamic type error if $o$ is not \NULL{} and the interf
ace of the class of $o$ is not a subtype of the actual type (\ref{actualTypeOfAD
eclaration}) of $v$. |
3394 | 3397 |
3395 It is a static type warning if the static type of $e$ may not be assigned to the
static type of $v$. The static type of the expression $v$ \code{=} $e$ is the s
tatic type of $e$. | 3398 It is a static type warning if the static type of $e$ may not be assigned to the
static type of $v$. The static type of the expression $v$ \code{=} $e$ is the s
tatic type of $e$. |
3396 | 3399 |
3397 Evaluation of an assignment of the form $C.v$ \code{=} $e$ proceeds as follows: | 3400 Evaluation of an assignment of the form $C.v$ \code{=} $e$ proceeds as follows: |
3398 | 3401 |
3399 If $C$ does not denote a class available in the current scope, the assignment is
treated as an assignment $e_1.v= e$, where $e_1$ is the expression $C$. Otherw
ise, | 3402 If $C$ does not denote a class available in the current scope, the assignment is
treated as an assignment $e_1.v= e$, where $e_1$ is the expression $C$. Otherw
ise, |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3920 \end{grammar} | 3923 \end{grammar} |
3921 | 3924 |
3922 A built-in identifier is one of the identifiers produced by the production {\em
BUILT\_IN\_IDENTIFIER}. It is a compile-time error if a built-in identifier is u
sed as the declared name of a class, type parameter or type alias. It is a compi
le-time error to use a built-in identifier other than \DYNAMIC{} as a type annot
ation. | 3925 A built-in identifier is one of the identifiers produced by the production {\em
BUILT\_IN\_IDENTIFIER}. It is a compile-time error if a built-in identifier is u
sed as the declared name of a class, type parameter or type alias. It is a compi
le-time error to use a built-in identifier other than \DYNAMIC{} as a type annot
ation. |
3923 | 3926 |
3924 \rationale{ | 3927 \rationale{ |
3925 Built-in identifiers are identifiers that are used as keywords in Dart, but are
not reserved words in Javascript. To minimize incompatibilities when porting Jav
ascript code to Dart, we do not make these into reserved words. A built-in ident
ifier may not be used to name a class or type. In other words, they are treated
as reserved words when used as types. This eliminates many confusing situations
without causing compatibility problems. After all, a Javascript program has no
type declarations or annotations so no clash can occur. Furthermore, types shou
ld begin with an uppercase letter (see the appendix) and so no clash should occu
r in any Dart user program anyway. | 3928 Built-in identifiers are identifiers that are used as keywords in Dart, but are
not reserved words in Javascript. To minimize incompatibilities when porting Jav
ascript code to Dart, we do not make these into reserved words. A built-in ident
ifier may not be used to name a class or type. In other words, they are treated
as reserved words when used as types. This eliminates many confusing situations
without causing compatibility problems. After all, a Javascript program has no
type declarations or annotations so no clash can occur. Furthermore, types shou
ld begin with an uppercase letter (see the appendix) and so no clash should occu
r in any Dart user program anyway. |
3926 } | 3929 } |
3927 | 3930 |
3928 Evaluation of an identifier expression $e$ of the form $id$ proceeds as follows: | 3931 Evaluation of an identifier expression $e$ of the form $id$ proceeds as follows: |
3929 | 3932 |
3930 Let $d$ be the innermost declaration in the enclosing lexical scope whose name i
s $id$. If no such declaration exists in the lexical scope, let $d$ be the decl
aration of the inherited member named $id$ if it exists. | 3933 |
| 3934 Let $d$ be the innermost declaration in the enclosing lexical scope whose name i
s $id$ or $id=$. If no such declaration exists in the lexical scope, let $d$ be
the declaration of the inherited member named $id$ if it exists. |
3931 %If no such member exists, let $d$ be the declaration of the static member name
$id$ declared in a superclass of the current class, if it exists. | 3935 %If no such member exists, let $d$ be the declaration of the static member name
$id$ declared in a superclass of the current class, if it exists. |
3932 | 3936 |
3933 \begin{itemize} | 3937 \begin{itemize} |
3934 \item If $d$ is a class or type alias $T$, the value of $e$ is an instance of cl
ass \code{Type} reifying $T$. | 3938 \item If $d$ is a class or type alias $T$, the value of $e$ is an instance of cl
ass \code{Type} reifying $T$. |
3935 \item If $d$ is a type parameter $T$, then the value of $e$ is the value of the
actual type argument corresponding to $T$ that was passed to the generative con
structor that created the current binding of \THIS{}. If, however, $e$ occurs in
side a static member, a compile-time error occurs. | 3939 \item If $d$ is a type parameter $T$, then the value of $e$ is the value of the
actual type argument corresponding to $T$ that was passed to the generative con
structor that created the current binding of \THIS{}. If, however, $e$ occurs in
side a static member, a compile-time error occurs. |
3936 | 3940 |
3937 %\commentary{ We are assured that \THIS{} is well defined, because if we were in
a static member the reference to $T$ is a compile-time error (\ref{generics}.)} | 3941 %\commentary{ We are assured that \THIS{} is well defined, because if we were in
a static member the reference to $T$ is a compile-time error (\ref{generics}.)} |
3938 %\item If $d$ is a library variable then: | 3942 %\item If $d$ is a library variable then: |
3939 % \begin{itemize} | 3943 % \begin{itemize} |
3940 % \item If $d$ is of one of the forms \code{\VAR{} $v$ = $e_i$;} , \code{$T$ $v
$ = $e_i$;} , \code{\FINAL{} $v$ = $e_i$;} or \code{\FINAL{} $T$ $v$ = $e_i$;}
and no value has yet been stored into $v$ then the initializer expression $e_i$
is evaluated. If, during the evaluation of $e_i$, the getter for $v$ is referenc
ed, a \code{CyclicInitializationError} is thrown. If the evaluation succeeded yi
elding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In any case, $r$
is stored into $v$. The value of $e$ is $r$. | 3944 % \item If $d$ is of one of the forms \code{\VAR{} $v$ = $e_i$;} , \code{$T$ $v
$ = $e_i$;} , \code{\FINAL{} $v$ = $e_i$;} or \code{\FINAL{} $T$ $v$ = $e_i$;}
and no value has yet been stored into $v$ then the initializer expression $e_i$
is evaluated. If, during the evaluation of $e_i$, the getter for $v$ is referenc
ed, a \code{CyclicInitializationError} is thrown. If the evaluation succeeded yi
elding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In any case, $r$
is stored into $v$. The value of $e$ is $r$. |
3941 \item If $d$ is a constant variable of one of the forms \code{\CONST{} $v$ =
$e$;} or \code{\CONST{} $T$ $v$ = $e$;} then the value $id$ is the value of the
compile-time constant $e$. | 3945 \item If $d$ is a constant variable of one of the forms \code{\CONST{} $v$ =
$e$;} or \code{\CONST{} $T$ $v$ = $e$;} then the value $id$ is the value of the
compile-time constant $e$. |
3942 % Otherwise | 3946 % Otherwise |
3943 % \item $e$ evaluates to the current binding of $id$. | 3947 % \item $e$ evaluates to the current binding of $id$. |
3944 % \end{itemize} | 3948 % \end{itemize} |
3945 \item If $d$ is a local variable or formal parameter then $e$ evaluates to the c
urrent binding of $id$. | 3949 \item If $d$ is a local variable or formal parameter then $e$ evaluates to the c
urrent binding of $id$. |
3946 %\item If $d$ is a library variable, local variable, or formal parameter, then $
e$ evaluates to the current binding of $id$. \commentary{This case also applies
if d is a library or local function declaration, as these are equivalent to func
tion-valued variable declarations.} | 3950 %\item If $d$ is a library variable, local variable, or formal parameter, then $
e$ evaluates to the current binding of $id$. \commentary{This case also applies
if d is a library or local function declaration, as these are equivalent to func
tion-valued variable declarations.} |
3947 \item If $d$ is a static method, top-level function or local function then $e$ e
valuates to the function defined by $d$. | 3951 \item If $d$ is a static method, top-level function or local function then $e$ e
valuates to the function defined by $d$. |
3948 \item If $d$ is the declaration of a static variable or static getter declared i
n class $C$, then $e$ is equivalent to the getter invocation (\ref{getterInvocat
ion}) $C.id$. | 3952 \item If $d$ is the declaration of a static variable, static getter or static se
tter declared in class $C$, then $e$ is equivalent to the getter invocation (\re
f{getterInvocation}) $C.id$. |
3949 \item If $d$ is the declaration of a library variable or top-level getter, then
$e$ is equivalent to the getter invocation $id$. | 3953 \item If $d$ is the declaration of a library variable, top-level getter or top-l
evel setter, then $e$ is equivalent to the getter invocation $id$. |
3950 \item Otherwise, if $e$ occurs inside a top level or static function (be it func
tion, method, getter, or setter) or variable initializer, evaluation of $e$ cau
ses a\code{NoSuchMethod} to be thrown. | 3954 \item Otherwise, if $e$ occurs inside a top level or static function (be it func
tion, method, getter, or setter) or variable initializer, evaluation of $e$ cau
ses a\code{NoSuchMethod} to be thrown. |
3951 \item Otherwise, $e$ is equivalent to the property extraction (\ref{propertyExtr
action}) \THIS{}.$id$. | 3955 \item Otherwise, $e$ is equivalent to the property extraction (\ref{propertyExtr
action}) \THIS{}.$id$. |
3952 % This implies that referring to an undefined static getter by simple name is an
error, whereas doing so by qualified name is only a warning. Same with assignme
nts. Revise? | 3956 % This implies that referring to an undefined static getter by simple name is an
error, whereas doing so by qualified name is only a warning. Same with assignme
nts. Revise? |
3953 \end{itemize} | 3957 \end{itemize} |
3954 | 3958 |
3955 The static type of $e$ is determined as follows: | 3959 The static type of $e$ is determined as follows: |
3956 | 3960 |
3957 \begin{itemize} | 3961 \begin{itemize} |
3958 \item If $d$ is a class, type alias or type parameter the static type of $e$ is
\code{Type}. | 3962 \item If $d$ is a class, type alias or type parameter the static type of $e$ is
\code{Type}. |
3959 \item If $d$ is a local variable or formal parameter the static type of $e$ is t
he type of the variable $id$, unless $id$ is known to have some type $T$, in whi
ch case the static type of $e$ is $T$, provided that $T$ is more specific than a
ny other type $S$ such that $v$ is known to have type $S$. | 3963 \item If $d$ is a local variable or formal parameter the static type of $e$ is t
he type of the variable $id$, unless $id$ is known to have some type $T$, in whi
ch case the static type of $e$ is $T$, provided that $T$ is more specific than a
ny other type $S$ such that $v$ is known to have type $S$. |
3960 \item If $d$ is a static method, top-level function or local function the static
type of $e$ the function type defined by $d$. | 3964 \item If $d$ is a static method, top-level function or local function the static
type of $e$ the function type defined by $d$. |
3961 \item If $d$ is the declaration of a static variable or static getter declared i
n class $C$, the static type of $e$ the static type of the getter invocation (\r
ef{getterInvocation}) $C.id$. | 3965 \item If $d$ is the declaration of a static variable or static getter declared i
n class $C$, the static type of $e$ the static type of the getter invocation (\r
ef{getterInvocation}) $C.id$. |
3962 \item If $d$ is the declaration of a library variable or top-level getter, the s
tatic type of $e$ is the static type of the getter invocation $id$. | 3966 \item If $d$ is the declaration of a library variable or top-level getter, the s
tatic type of $e$ is the static type of the getter invocation $id$. |
3963 \item Otherwise, if $e$ occurs inside a top level or static function (be it func
tion, method, getter, or setter) or variable initializer, the static type of $e
$ is \DYNAMIC{}. | 3967 \item Otherwise, if $e$ occurs inside a top level or static function (be it func
tion, method, getter, or setter) or variable initializer, the static type of $e
$ is \DYNAMIC{}. |
3964 \item Otherwise, the static type of $e$ is the type of the property extraction (
\ref{propertyExtraction}) \THIS{}.$id$. | 3968 \item Otherwise, the static type of $e$ is the type of the property extraction (
\ref{propertyExtraction}) \THIS{}.$id$. |
3965 \end{itemize} | 3969 \end{itemize} |
3966 | 3970 |
| 3971 \commentary{Note that if one declares a setter, we bind to the corresponding ge
tter even if it does not exist.} |
| 3972 |
| 3973 \rationale{ |
| 3974 This prevents situations where one uses uncorrelated setters and getters. The i
ntent is to prevent errors when a getter in a surrounding scope is used acciden
tally. |
| 3975 } |
| 3976 |
3967 It is a static warning if an identifier expression $id$ occurs inside a top leve
l or static function (be it function, method, getter, or setter) or variable ini
tializer and there is no declaration $d$ with name $id$ in the lexical scope enc
losing the expression. | 3977 It is a static warning if an identifier expression $id$ occurs inside a top leve
l or static function (be it function, method, getter, or setter) or variable ini
tializer and there is no declaration $d$ with name $id$ in the lexical scope enc
losing the expression. |
3968 | 3978 |
3969 \subsection{ Type Test} | 3979 \subsection{ Type Test} |
3970 \label{typeTest} | 3980 \label{typeTest} |
3971 | 3981 |
3972 The {\em is-expression} tests if an object is a member of a type. | 3982 The {\em is-expression} tests if an object is a member of a type. |
3973 | 3983 |
3974 \begin{grammar} | 3984 \begin{grammar} |
3975 {\bf typeTest:} | 3985 {\bf typeTest:} |
3976 isOperator type | 3986 isOperator type |
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4826 | 4836 |
4827 %\end{dartCode} | 4837 %\end{dartCode} |
4828 | 4838 |
4829 %\rationale{therefore, we opt for the second option. Alternately, one could insi
st that assert be a reserved word, which may have an undesirable effect with res
pect to compatibility of Javascript code ported to Dart.} | 4839 %\rationale{therefore, we opt for the second option. Alternately, one could insi
st that assert be a reserved word, which may have an undesirable effect with res
pect to compatibility of Javascript code ported to Dart.} |
4830 | 4840 |
4831 \section{Libraries and Scripts} | 4841 \section{Libraries and Scripts} |
4832 \label{librariesAndScripts} | 4842 \label{librariesAndScripts} |
4833 | 4843 |
4834 A Dart program consists of one or more libraries, and may be built out of one or
more {\em compilation units}. A compilation unit may be a library or a part (\r
ef{parts}). | 4844 A Dart program consists of one or more libraries, and may be built out of one or
more {\em compilation units}. A compilation unit may be a library or a part (\r
ef{parts}). |
4835 | 4845 |
4836 A library consists of (a possibly empty) set of imports, a set of exports, and
a set of top-level declarations. A top-level declaration is either a class (\ref
{classes}), a type alias declaration (\ref{typedef}), a function (\ref{functions
}) or a variable declaration (\ref{variables}). The members of a library $L$ are
those top level declarations given within a $L$. | 4846 A library consists of (a possibly empty) set of imports, a set of exports, and
a set of top-level declarations. A top-level declaration is either a class (\ref
{classes}), a type alias declaration (\ref{typedef}), a function (\ref{functions
}) or a variable declaration (\ref{variables}). The members of a library $L$ are
those top level declarations given within $L$. |
4837 | 4847 |
4838 \begin{grammar} | 4848 \begin{grammar} |
4839 {\bf topLevelDefinition:}classDefinition; | 4849 {\bf topLevelDefinition:}classDefinition; |
4840 % classDefinitionOrInterfaceInjection; | 4850 % classDefinitionOrInterfaceInjection; |
4841 % interfaceDefinitionOrInterfaceInjection; | 4851 % interfaceDefinitionOrInterfaceInjection; |
4842 % mixinApplication; | 4852 % mixinApplication; |
4843 typeAlias; | 4853 typeAlias; |
4844 \EXTERNAL{}? functionSignature `{\escapegrammar ;}'; | 4854 \EXTERNAL{}? functionSignature `{\escapegrammar ;}'; |
4845 \EXTERNAL{}? getterSignature `{\escapegrammar ;}'; | 4855 \EXTERNAL{}? getterSignature `{\escapegrammar ;}'; |
4846 \EXTERNAL{}? setterSignature `{\escapegrammar ;}'; | 4856 \EXTERNAL{}? setterSignature `{\escapegrammar ;}'; |
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5831 \item The names of compile time constant variables never use lower case letters.
If they consist of multiple words, those words are separated by underscores. Ex
amples: PI, I\_AM\_A\_CONSTANT. | 5841 \item The names of compile time constant variables never use lower case letters.
If they consist of multiple words, those words are separated by underscores. Ex
amples: PI, I\_AM\_A\_CONSTANT. |
5832 \item The names of functions (including getters, setters, methods and local or l
ibrary functions) and non-constant variables begin with a lowercase letter. If t
he name consists of multiple words, each word (except the first) begins with an
uppercase letter. No other uppercase letters are used. Examples: camlCase, dar
t4TheWorld | 5842 \item The names of functions (including getters, setters, methods and local or l
ibrary functions) and non-constant variables begin with a lowercase letter. If t
he name consists of multiple words, each word (except the first) begins with an
uppercase letter. No other uppercase letters are used. Examples: camlCase, dar
t4TheWorld |
5833 \item The names of types (including classes and type aliases) begin with an uppe
r case letter. If the name consists of multiple words, each word begins with
an uppercase letter. No other uppercase letters are used. Examples: CamlCase, D
art4TheWorld. | 5843 \item The names of types (including classes and type aliases) begin with an uppe
r case letter. If the name consists of multiple words, each word begins with
an uppercase letter. No other uppercase letters are used. Examples: CamlCase, D
art4TheWorld. |
5834 \item The names of type variables are short (preferably single letter). Examples
: T, S, K, V , E. | 5844 \item The names of type variables are short (preferably single letter). Examples
: T, S, K, V , E. |
5835 \item The names of libraries or library prefixes never use upper case letters. I
f they consist of multiple words, those words are separated by underscores. Exam
ple: my\_favorite\_library. | 5845 \item The names of libraries or library prefixes never use upper case letters. I
f they consist of multiple words, those words are separated by underscores. Exam
ple: my\_favorite\_library. |
5836 \end{itemize} | 5846 \end{itemize} |
5837 } | 5847 } |
5838 | 5848 |
5839 | 5849 |
5840 \end{document} | 5850 \end{document} |
OLD | NEW |