Changeset ec8bcc4 for doc/papers/general
- Timestamp:
- Feb 17, 2018, 7:17:15 PM (7 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/general/Paper.tex
rd4933b3 rec8bcc4 90 90 \newcommand*{\etc}{% 91 91 \@ifnextchar{.}{\ETC}% 92 {\ETC \xspace}%92 {\ETC.\xspace}% 93 93 }% 94 \newcommand{\ETAL}{\abbrevFont{et} \hspace{2pt}\abbrevFont{al}}94 \newcommand{\ETAL}{\abbrevFont{et}~\abbrevFont{al}} 95 95 \newcommand*{\etal}{% 96 96 \@ifnextchar{.}{\protect\ETAL}% 97 {\ abbrevFont{\protect\ETAL}.\xspace}%97 {\protect\ETAL.\xspace}% 98 98 }% 99 99 \newcommand{\VIZ}{\abbrevFont{viz}} 100 100 \newcommand*{\viz}{% 101 101 \@ifnextchar{.}{\VIZ}% 102 {\ abbrevFont{\VIZ}.\xspace}%102 {\VIZ.\xspace}% 103 103 }% 104 104 \makeatother … … 120 120 otype, restrict, _Static_assert, throw, throwResume, trait, try, ttype, typeof, __typeof, 121 121 __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}, 122 125 moredirectives={defined,include_next}% 123 } %126 } 124 127 125 128 \lstset{ … … 1361 1364 \section{Declarations} 1362 1365 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. 1366 It is important that \CFA subjectively ``feel like'' C to user programmers. 1367 An 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. 1368 Maintaining 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. 1369 Nonetheless, 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. 1367 1371 1368 1372 1369 1373 \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}}}1374 1374 1375 1375 C declaration syntax is notoriously confusing and error prone. … … 1399 1399 \CFA provides its own type, variable and routine declarations, using a different syntax. 1400 1400 The 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. 1401 The qualifiers have the same meaning but are ordered left to right to specify a variable's type. 1403 1402 \begin{cquote} 1404 1403 \lstDeleteShortInline@% 1405 \lstset{moredelim=**[is][\color{blue}]{+}{+}}1406 1404 \begin{tabular}{@{}l@{\hspace{\parindentlnth}}l@{}} 1407 1405 \multicolumn{1}{c@{\hspace{\parindentlnth}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1408 1406 \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} 1413 int `*` x1 `[5]`; 1414 int `(*`x2`)[5]`; 1415 `int (*`f( int p )`)[5]`; 1418 1416 \end{cfa} 1419 1417 \end{tabular} … … 1456 1454 \end{cquote} 1457 1455 which is prescribing a safety benefit. 1456 1457 \begin{comment} 1458 1458 Other examples are: 1459 1459 \begin{cquote} … … 1496 1496 \lstMakeShortInline@% 1497 1497 \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 1500 All 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: 1500 1501 \begin{cquote} 1501 1502 \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 integer1516 // const pointer to array of 5 const integers1503 \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} 1506 extern const * const int x; 1507 static const * [ 5 ] const int y; 1508 \end{cfa} 1509 & 1510 \begin{cfa} 1511 int extern const * const x; 1512 static 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 1517 1518 \end{cfa} 1518 1519 \end{tabular} 1519 1520 \lstMakeShortInline@% 1520 1521 \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} 1522 All specifiers must appear at the start of a \CFA routine declaration,\footnote{\label{StorageClassSpecifier} 1523 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}}. 1544 1524 1545 1525 The new declaration syntax can be used in other contexts where types are required, \eg casts and the pseudo-routine @sizeof@: … … 1561 1541 \end{cquote} 1562 1542 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 1567 1543 The syntax of the new routine prototype declaration follows directly from the new routine definition syntax; 1568 1544 as well, parameter names are optional, \eg: 1569 1545 \begin{cfa} 1570 1546 [ 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}$ 1572 1549 [ ] h ( int, char ); $\C{// returning no result with int and char parameters}$ 1573 1550 [ * int, int ] j ( int ); $\C{// returning pointer to int and int, with int parameter}$ … … 1589 1566 \lstMakeShortInline@% 1590 1567 \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} 1568 where \CFA allows the last routine in the list to define its body. 1598 1569 1599 1570 The syntax for pointers to \CFA routines specifies the pointer name on the right, \eg: 1600 1571 \begin{cfa} 1601 1572 * [ 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} 1577 Note, \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 1582 Finally, new \CFA declarations may appear together with C declarations in the same program block, but cannot be mixed within a specific declaration. 1583 Therefore, a programmer has the option of either continuing to use traditional C declarations or take advantage of the new style. 1584 Clearly, both styles need to be supported for some time due to existing C-style header-files, particularly for UNIX-like systems. 1611 1585 1612 1586
Note: See TracChangeset
for help on using the changeset viewer.