Changeset ec8bcc4


Ignore:
Timestamp:
Feb 17, 2018, 7:17:15 PM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
29f47139
Parents:
d4933b3
Message:

update alternate declaration syntax

File:
1 edited

Legend:

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

    rd4933b3 rec8bcc4  
    9090\newcommand*{\etc}{%
    9191        \@ifnextchar{.}{\ETC}%
    92         {\ETC\xspace}%
     92        {\ETC.\xspace}%
    9393}%
    94 \newcommand{\ETAL}{\abbrevFont{et}\hspace{2pt}\abbrevFont{al}}
     94\newcommand{\ETAL}{\abbrevFont{et}~\abbrevFont{al}}
    9595\newcommand*{\etal}{%
    9696        \@ifnextchar{.}{\protect\ETAL}%
    97                 {\abbrevFont{\protect\ETAL}.\xspace}%
     97                {\protect\ETAL.\xspace}%
    9898}%
    9999\newcommand{\VIZ}{\abbrevFont{viz}}
    100100\newcommand*{\viz}{%
    101101        \@ifnextchar{.}{\VIZ}%
    102                 {\abbrevFont{\VIZ}.\xspace}%
     102                {\VIZ.\xspace}%
    103103}%
    104104\makeatother
     
    120120                otype, restrict, _Static_assert, throw, throwResume, trait, try, ttype, typeof, __typeof,
    121121                __typeof__, virtual, with, zero_t},
     122        morekeywords=[2]{
     123                _Atomic, coroutine, is_coroutine, is_monitor, is_thread, monitor, mutex, nomutex, or,
     124                resume, suspend, thread, _Thread_local, waitfor, when, yield},
    122125        moredirectives={defined,include_next}%
    123 }%
     126}
    124127
    125128\lstset{
     
    13611364\section{Declarations}
    13621365
    1363 It is important to the design team that \CFA subjectively ``feel like'' C to user programmers.
    1364 An important part of this subjective feel is maintaining C's procedural programming paradigm, as opposed to the object-oriented paradigm of other systems languages such as \CC and Rust.
    1365 Maintaining this procedural paradigm means that coding patterns that work in C will remain not only functional but idiomatic in \CFA, reducing the mental burden of retraining C programmers and switching between C and \CFA development.
    1366 Nonetheless, some features of object-oriented languages are undeniably convienient, and the \CFA design team has attempted to adapt them to a procedural paradigm so as to incorporate their benefits into \CFA; two of these features are resource management and name scoping.
     1366It is important that \CFA subjectively ``feel like'' C to user programmers.
     1367An important part of this subjective feel is maintaining C's procedural paradigm, as opposed to the object-oriented paradigm of other systems languages such as \CC and Rust.
     1368Maintaining this procedural paradigm means that C coding-patterns remain not only functional but idiomatic in \CFA, reducing the mental burden of retraining C programmers and switching between C and \CFA development.
     1369Nonetheless, some features of object-oriented languages are undeniably convienient but are independent of object-oriented programming;
     1370\CFA adapts these features to a procedural paradigm.
    13671371
    13681372
    13691373\subsection{Alternative Declaration Syntax}
    1370 
    1371 \newcommand{\R}[1]{\Textbf{#1}}
    1372 \newcommand{\B}[1]{{\Textbf[blue]{#1}}}
    1373 \newcommand{\G}[1]{{\Textbf[OliveGreen]{#1}}}
    13741374
    13751375C declaration syntax is notoriously confusing and error prone.
     
    13991399\CFA provides its own type, variable and routine declarations, using a different syntax.
    14001400The new declarations place qualifiers to the left of the base type, while C declarations place qualifiers to the right of the base type.
    1401 In the following example, \R{red} is the base type and \B{blue} is qualifiers.
    1402 The \CFA declarations move the qualifiers to the left of the base type, \ie move the blue to the left of the red, while the qualifiers have the same meaning but are ordered left to right to specify a variable's type.
     1401The qualifiers have the same meaning but are ordered left to right to specify a variable's type.
    14031402\begin{cquote}
    14041403\lstDeleteShortInline@%
    1405 \lstset{moredelim=**[is][\color{blue}]{+}{+}}
    14061404\begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}}
    14071405\multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}}     & \multicolumn{1}{c}{\textbf{C}}        \\
    14081406\begin{cfa}
    1409 +[5] *+ `int` x1;
    1410 +* [5]+ `int` x2;
    1411 `[* [5] int]` f+( int p )+;
    1412 \end{cfa}
    1413 &
    1414 \begin{cfa}
    1415 `int` +*+ x1 +[5]+;
    1416 `int` +(*+x2+)[5]+;
    1417 `int (*`f+( int p )+`)[5]`;
     1407`[5] *` int x1;
     1408`* [5]` int x2;
     1409`[* [5] int]` f( int p );
     1410\end{cfa}
     1411&
     1412\begin{cfa}
     1413int `*` x1 `[5]`;
     1414int `(*`x2`)[5]`;
     1415`int (*`f( int p )`)[5]`;
    14181416\end{cfa}
    14191417\end{tabular}
     
    14561454\end{cquote}
    14571455which is prescribing a safety benefit.
     1456
     1457\begin{comment}
    14581458Other examples are:
    14591459\begin{cquote}
     
    14961496\lstMakeShortInline@%
    14971497\end{cquote}
    1498 
    1499 All type qualifiers, \eg @const@, @volatile@, etc., are used in the normal way with the new declarations and also appear left to right, \eg:
     1498\end{comment}
     1499
     1500All specifiers (@extern@, @static@, \etc) and qualifiers (@const@, @volatile@, \etc) are used in the normal way with the new declarations and also appear left to right, \eg:
    15001501\begin{cquote}
    15011502\lstDeleteShortInline@%
    1502 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{\hspace{\parindentlnth}}l@{}}
    1503 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}}     & \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{C}}      \\
    1504 \begin{cfa}
    1505 const * const int x;
    1506 const * [ 5 ] const int y;
    1507 \end{cfa}
    1508 &
    1509 \begin{cfa}
    1510 int const * const x;
    1511 const int (* const y)[ 5 ]
    1512 \end{cfa}
    1513 &
    1514 \begin{cfa}
    1515 // const pointer to const integer
    1516 // const pointer to array of 5 const integers
     1503\begin{tabular}{@{}l@{\hspace{1em}}l@{\hspace{1em}}l@{}}
     1504\multicolumn{1}{c@{\hspace{1em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{1em}}}{\textbf{C}} \\
     1505\begin{cfa}
     1506extern const * const int x;
     1507static const * [ 5 ] const int y;
     1508\end{cfa}
     1509&
     1510\begin{cfa}
     1511int extern const * const x;
     1512static const int (* const y)[ 5 ]
     1513\end{cfa}
     1514&
     1515\begin{cfa}
     1516// external const pointer to const int
     1517// internal const pointer to array of 5 const int
    15171518\end{cfa}
    15181519\end{tabular}
    15191520\lstMakeShortInline@%
    15201521\end{cquote}
    1521 All declaration qualifiers, \eg @extern@, @static@, etc., are used in the normal way with the new declarations but can only appear at the start of a \CFA routine declaration,\footnote{\label{StorageClassSpecifier}
    1522 The placement of a storage-class specifier other than at the beginning of the declaration specifiers in a declaration is an obsolescent feature.~\cite[\S~6.11.5(1)]{C11}} \eg:
    1523 \begin{cquote}
    1524 \lstDeleteShortInline@%
    1525 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{\hspace{\parindentlnth}}l@{}}
    1526 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}}     & \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{C}}      \\
    1527 \begin{cfa}
    1528 extern [ 5 ] int x;
    1529 static * const int y;
    1530 \end{cfa}
    1531 &
    1532 \begin{cfa}
    1533 int extern x[ 5 ];
    1534 const int static * y;
    1535 \end{cfa}
    1536 &
    1537 \begin{cfa}
    1538 // externally visible array of 5 integers
    1539 // internally visible pointer to constant int
    1540 \end{cfa}
    1541 \end{tabular}
    1542 \lstMakeShortInline@%
    1543 \end{cquote}
     1522All specifiers must appear at the start of a \CFA routine declaration,\footnote{\label{StorageClassSpecifier}
     1523The placement of a storage-class specifier other than at the beginning of the declaration specifiers in a declaration is an obsolescent feature.~\cite[\S~6.11.5(1)]{C11}}.
    15441524
    15451525The new declaration syntax can be used in other contexts where types are required, \eg casts and the pseudo-routine @sizeof@:
     
    15611541\end{cquote}
    15621542
    1563 Finally, new \CFA declarations may appear together with C declarations in the same program block, but cannot be mixed within a specific declaration.
    1564 Therefore, a programmer has the option of either continuing to use traditional C declarations or take advantage of the new style.
    1565 Clearly, both styles need to be supported for some time due to existing C-style header-files, particularly for UNIX-like systems.
    1566 
    15671543The syntax of the new routine prototype declaration follows directly from the new routine definition syntax;
    15681544as well, parameter names are optional, \eg:
    15691545\begin{cfa}
    15701546[ int x ] f ();                                                 $\C{// returning int with no parameters}$
    1571 [ * int ] g (int y);                                    $\C{// returning pointer to int with int parameter}$
     1547[ int x ] f (...);                                              $\C{// returning int with unknown parameters}$
     1548[ * int ] g ( int y );                                  $\C{// returning pointer to int with int parameter}$
    15721549[ ] h ( int, char );                                    $\C{// returning no result with int and char parameters}$
    15731550[ * int, int ] j ( int );                               $\C{// returning pointer to int and int, with int parameter}$
     
    15891566\lstMakeShortInline@%
    15901567\end{cquote}
    1591 \CFA allows the last routine in the list to define its body.
    1592 
    1593 Declaration qualifiers can only appear at the start of a \CFA routine declaration,\footref{StorageClassSpecifier} \eg:
    1594 \begin{cfa}
    1595 extern [ int ] f ( int );
    1596 static [ int ] g ( int );
    1597 \end{cfa}
     1568where \CFA allows the last routine in the list to define its body.
    15981569
    15991570The syntax for pointers to \CFA routines specifies the pointer name on the right, \eg:
    16001571\begin{cfa}
    16011572* [ int x ] () fp;                                              $\C{// pointer to routine returning int with no parameters}$
    1602 * [ * int ] (int y) gp;                                 $\C{// pointer to routine returning pointer to int with int parameter}$
    1603 * [ ] (int,char) hp;                                    $\C{// pointer to routine returning no result with int and char parameters}$
    1604 * [ * int,int ] ( int ) jp;                             $\C{// pointer to routine returning pointer to int and int, with int parameter}$
    1605 \end{cfa}
    1606 While parameter names are optional, \emph{a routine name cannot be specified};
    1607 for example, the following is incorrect:
    1608 \begin{cfa}
    1609 * [ int x ] f () fp;                                    $\C{// routine name "f" is not allowed}$
    1610 \end{cfa}
     1573* [ * int ] ( int y ) gp;                               $\C{// pointer to routine returning pointer to int with int parameter}$
     1574* [ ] ( int, char ) hp;                                 $\C{// pointer to routine returning no result with int and char parameters}$
     1575* [ * int, int ] ( int ) jp;                    $\C{// pointer to routine returning pointer to int and int, with int parameter}$
     1576\end{cfa}
     1577Note, \emph{a routine name cannot be specified}:
     1578\begin{cfa}
     1579* [ int x ] f () fp;                                    $\C{// routine name "f" is disallowed}$
     1580\end{cfa}
     1581
     1582Finally, new \CFA declarations may appear together with C declarations in the same program block, but cannot be mixed within a specific declaration.
     1583Therefore, a programmer has the option of either continuing to use traditional C declarations or take advantage of the new style.
     1584Clearly, both styles need to be supported for some time due to existing C-style header-files, particularly for UNIX-like systems.
    16111585
    16121586
Note: See TracChangeset for help on using the changeset viewer.