Changes in / [df2be83:5ba653c]
- Files:
-
- 3 added
- 3 deleted
- 20 edited
-
doc/LaTeXmacros/common.tex (deleted)
-
doc/LaTeXmacros/indexstyle (deleted)
-
doc/bibliography/cfa.bib (deleted)
-
doc/refrat/Makefile (modified) (3 diffs)
-
doc/refrat/indexstyle (added)
-
doc/refrat/refrat.tex (modified) (6 diffs)
-
doc/user/Makefile (modified) (3 diffs)
-
doc/user/indexstyle (added)
-
doc/user/user.bib (added)
-
doc/user/user.tex (modified) (4 diffs)
-
src/Parser/ExpressionNode.cc (modified) (3 diffs)
-
src/Parser/ParseNode.h (modified) (2 diffs)
-
src/Parser/parser.cc (modified) (1 diff)
-
src/Parser/parser.yy (modified) (2 diffs)
-
src/SymTab/AddVisit.h (modified) (3 diffs)
-
src/SymTab/Validate.cc (modified) (13 diffs)
-
src/SynTree/Expression.cc (modified) (3 diffs)
-
src/SynTree/Expression.h (modified) (2 diffs)
-
src/SynTree/Mutator.cc (modified) (2 diffs)
-
src/SynTree/Mutator.h (modified) (2 diffs)
-
src/SynTree/SynTree.h (modified) (2 diffs)
-
src/SynTree/Visitor.cc (modified) (2 diffs)
-
src/SynTree/Visitor.h (modified) (2 diffs)
-
src/examples/rational.c (modified) (1 diff)
-
src/libcfa/rational (modified) (3 diffs)
-
src/libcfa/rational.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/refrat/Makefile
rdf2be83 r5ba653c 1 1 ## Define the appropriate configuration variables. 2 2 3 TeXLIB = .:../bibliography/:../LaTeXmacros/: 3 Macros = 4 TeXLIB = .:${Macros}: 4 5 LaTeX = TEXINPUTS=${TeXLIB} && export TEXINPUTS && latex 5 BibTeX = B IBINPUTS=${TeXLIB} && export BIBINPUTS && bibtex6 BibTeX = BSTINPUTS=${TeXLIB} && export BSTINPUTS && bibtex 6 7 7 8 ## Define the text source files. … … 43 44 dvips $< -o $@ 44 45 45 ${basename ${DOCUMENT}}.dvi : Makefile ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${basename ${DOCUMENT}}.tex \ 46 ../LaTeXmacros/common.tex ../LaTeXmacros/indexstyle ../bibliography/cfa.bib 46 ${basename ${DOCUMENT}}.dvi : Makefile ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${basename ${DOCUMENT}}.tex ${basename ${DOCUMENT}}.bib 47 47 # Conditionally create an empty *.ind (index) file for inclusion until makeindex is run. 48 48 if [ ! -r ${basename $@}.ind ] ; then touch ${basename $@}.ind ; fi … … 54 54 -${BibTeX} ${basename $@} 55 55 # Make index from *.aux entries and input index at end of document 56 makeindex -s ../LaTeXmacros/indexstyle ${basename $@}.idx56 makeindex -s indexstyle ${basename $@}.idx 57 57 ${LaTeX} ${basename $@}.tex 58 58 # Run again to get index title into table of contents -
doc/refrat/refrat.tex
rdf2be83 r5ba653c 11 11 %% Created On : Wed Apr 6 14:52:25 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Fri Apr 8 18:32:07 201614 %% Update Count : 613 %% Last Modified On : Wed Apr 6 21:57:27 2016 14 %% Update Count : 2 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 36 36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 37 37 38 % Names used in the document. 39 40 \newcommand{\CFA}{C$\mathbf\forall$\xspace} % set language symbolic name 41 \newcommand{\CFL}{Cforall\xspace} % set language text name 42 \newcommand{\CC}{C\kern-.1em\hbox{+\kern-.25em+}\xspace} % CC symbolic name 43 \def\c11{ISO/IEC C} % C11 name (cannot have numbers in latex command name) 44 45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 46 38 47 % Bespoke macros used in the document. 39 \input{common} 48 49 \makeatletter 50 % allow escape sequence in lstinline 51 %\usepackage{etoolbox} 52 %\patchcmd{\lsthk@TextStyle}{\let\lst@DefEsc\@empty}{}{}{\errmessage{failed to patch}} 53 54 \renewcommand\small{% 55 \@setfontsize\small{8.5}{11}% 56 \abovedisplayskip 8.5pt \@plus 3pt \@minus 4pt 57 \abovedisplayshortskip \z@ \@plus 2pt 58 \belowdisplayshortskip 4pt \@plus 2pt \@minus 2pt 59 \def\@listi{\leftmargin\leftmargini 60 \topsep 4pt \@plus 2pt \@minus 2pt 61 \parsep 2pt \@pluspt \@minuspt 62 \itemsep \parsep}% 63 \belowdisplayskip \abovedisplayskip 64 } 65 \usepackage{relsize} % must be after change to small 66 67 \renewcommand{\labelitemi}{{\raisebox{0.25ex}{\footnotesize$\bullet$}}} 68 \renewenvironment{itemize}{\begin{list}{\labelitemi}{\topsep=5pt\itemsep=5pt\parsep=0pt}}{\end{list}} 69 70 % Reduce size of chapter/section titles 71 \def\@makechapterhead#1{% 72 \vspace*{50\p@}% 73 {\parindent \z@ \raggedright \normalfont 74 \ifnum \c@secnumdepth >\m@ne 75 \large\bfseries \@chapapp\space \thechapter 76 \par\nobreak 77 \vskip 5\p@ 78 \fi 79 \interlinepenalty\@M 80 \Large \bfseries #1\par\nobreak 81 \vskip 50\p@ 82 }} 83 \def\@makeschapterhead#1{% 84 \vspace*{50\p@}% 85 {\parindent \z@ \raggedright 86 \normalfont 87 \interlinepenalty\@M 88 \Large \bfseries #1\par\nobreak 89 \vskip 50\p@ 90 }} 91 \renewcommand\section{\@startsection{section}{1}{\z@}{-3.0ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\large\bfseries}} 92 \renewcommand\subsection{\@startsection{subsection}{2}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}} 93 \renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}} 94 \renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}{-2.0ex \@plus -1ex \@minus -.2ex}{-1em}{\normalfont\normalsize\bfseries}} 95 96 % index macros 97 \newcommand{\italic}[1]{\emph{\hyperpage{#1}}} 98 \newcommand{\definition}[1]{\textbf{\hyperpage{#1}}} 99 \newcommand{\see}[1]{\emph{see} #1} 100 101 % Define some commands that produce formatted index entries suitable for cross-references. 102 % ``\spec'' produces entries for specifications of entities. ``\impl'' produces entries for their 103 % implementations, and ``\use'' for their uses. 104 105 % \newcommand{\bold}[1]{{\bf #1}} 106 % \def\spec{\@bsphack\begingroup 107 % \def\protect##1{\string##1\space}\@sanitize 108 % \@wrxref{|bold}} 109 \def\impl{\@bsphack\begingroup 110 \def\protect##1{\string##1\space}\@sanitize 111 \@wrxref{|definition}} 112 \newcommand{\indexcode}[1]{{\lstinline$#1$}} 113 \def\use{\@bsphack\begingroup 114 \def\protect##1{\string##1\space}\@sanitize 115 \@wrxref{|hyperpage}} 116 \def\@wrxref#1#2{\let\thepage\relax 117 \xdef\@gtempa{\write\@indexfile{\string 118 \indexentry{#2@{\lstinline$#2$}#1}{\thepage}}}\endgroup\@gtempa 119 \if@nobreak \ifvmode\nobreak\fi\fi\@esphack} 120 %\newcommand{\use}[1]{\index{#1@{\lstinline$#1$}}} 121 %\newcommand{\impl}[1]{\index{\protect#1@{\lstinline$\protect#1$}|definition}} 122 123 % inline text and lowercase index: \Index{inline and lowercase index text} 124 % inline text and as-in index: \Index[as-is index text]{inline text} 125 % inline text but index with different as-is text: \Index[index text]{inline text} 126 \newcommand{\Index}{\@ifstar\@sIndex\@Index} 127 \newcommand{\@Index}[2][\@empty]{\lowercase{\def\temp{#2}}#2\ifx#1\@empty\index{\temp}\else\index{#1@{\protect#2}}\fi} 128 \newcommand{\@sIndex}[2][\@empty]{#2\ifx#1\@empty\index{#2}\else\index{#1@{\protect#2}}\fi} 129 \makeatother 130 131 % blocks and titles 132 \newenvironment{rationale}{% 133 \begin{quotation}\noindent$\Box$\enspace 134 }{% 135 \hfill\enspace$\Box$\end{quotation} 136 }% 137 \newcommand{\define}[1]{\emph{#1\/}\index{#1}} 138 \newcommand{\rewrite}{\(\Rightarrow\)} 139 \newcommand{\rewriterules}{\paragraph{Rewrite Rules}~\par\noindent} 140 \newcommand{\examples}{\paragraph{Examples}~\par\noindent} 141 \newcommand{\semantics}{\paragraph{Semantics}~\par\noindent} 142 \newcommand{\constraints}{\paragraph{Constraints}~\par\noindent} 143 \newcommand{\predefined}{\paragraph{Predefined Identifiers}~\par\noindent} 144 145 % BNF macros 146 \def\syntax{\paragraph{Syntax}\trivlist\parindent=.5in\item[\hskip.5in]} 147 \let\endsyntax=\endtrivlist 148 \newcommand{\lhs}[1]{\par{\emph{#1:}}\index{#1@{\emph{#1}}|italic}} 149 \newcommand{\rhs}{\hfil\break\hbox{\hskip1in}} 150 \newcommand{\oldlhs}[1]{\emph{#1: \ldots}\index{#1@{\emph{#1}}|italic}} 151 \newcommand{\nonterm}[1]{\emph{#1\/}\index{#1@{\emph{#1}}|italic}} 152 \newcommand{\opt}{$_{opt}$\ } 153 154 % adjust varioref package with default "section" and "page" titles, and optional title with faraway page numbers 155 % \VRef{label} => Section 2.7, \VPageref{label} => page 17 156 % \VRef[Figure]{label} => Figure 3.4, \VPageref{label} => page 17 157 \renewcommand{\reftextfaceafter}{\unskip} 158 \renewcommand{\reftextfacebefore}{\unskip} 159 \renewcommand{\reftextafter}{\unskip} 160 \renewcommand{\reftextbefore}{\unskip} 161 \renewcommand{\reftextfaraway}[1]{\unskip, p.~\pageref{#1}} 162 \renewcommand{\reftextpagerange}[2]{\unskip, pp.~\pageref{#1}--\pageref{#2}} 163 \newcommand{\VRef}[2][Section]{\ifx#1\@empty\else{#1}\nobreakspace\fi\vref{#2}} 164 \newcommand{\VPageref}[2][page]{\ifx#1\@empty\else{#1}\nobreakspace\fi\pageref{#2}} 165 166 % CFA based on ANSI C 167 \lstdefinelanguage{CFA}[ANSI]{C}% 168 {morekeywords={_Alignas,_Alignof,__alignof,__alignof__,asm,__asm,__asm__,_At,_Atomic,__attribute,__attribute__,auto, 169 _Bool,catch,catchResume,choose,_Complex,__complex,__complex__,__const,__const__,disable,dtype,enable,__extension__, 170 fallthru,finally,forall,ftype,_Generic,_Imaginary,inline,__label__,lvalue,_Noreturn,otype,restrict,_Static_assert, 171 _Thread_local,throw,throwResume,trait,try,typeof,__typeof,__typeof__,}, 172 }% 173 174 \lstset{ 175 language=CFA, 176 columns=flexible, 177 basicstyle=\sf\relsize{-1}, 178 tabsize=4, 179 xleftmargin=\parindent, 180 escapechar=@, 181 mathescape=true, 182 keepspaces=true, 183 showstringspaces=false, 184 showlines=true, 185 aboveskip=6pt, 186 belowskip=4pt, 187 }% 188 189 \makeatletter 190 % replace/adjust listings characters that look bad in sanserif 191 \lst@CCPutMacro 192 \lst@ProcessOther{"22}{\lst@ttfamily{"}{\raisebox{0.3ex}{\ttfamily\upshape "}}} % replace double quote 193 \lst@ProcessOther{"27}{\lst@ttfamily{'}{\raisebox{0.3ex}{\ttfamily\upshape '\hspace*{-2pt}}}} % replace single quote 194 \lst@ProcessOther{"2D}{\lst@ttfamily{-}{\ttfamily\upshape -}} % replace minus 195 \lst@ProcessOther{"3C}{\lst@ttfamily{<}{\texttt{<}}} % replace less than 196 \lst@ProcessOther{"3E}{\lst@ttfamily{<}{\texttt{>}}} % replace greater than 197 \lst@ProcessOther{"5E}{\raisebox{0.4ex}{$\scriptstyle\land\,$}} % replace circumflex 198 \lst@ProcessOther{"5F}{\lst@ttfamily{\char95}{{\makebox[1.2ex][c]{\rule{1ex}{0.1ex}}}}} % replace underscore 199 \lst@ProcessOther{"60}{\lst@ttfamily{`}{\raisebox{0.3ex}{\ttfamily\upshape \hspace*{-2pt}`}}} % replace backquote 200 \lst@ProcessOther{"7E}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}} % replace tilde 201 %\lst@ProcessOther{"7E}{\raisebox{-.4ex}[1ex][0pt]{\textasciitilde}} % lower tilde 202 \@empty\z@\@empty 203 \makeatother 40 204 41 205 \setcounter{secnumdepth}{3} % number subsubsections … … 84 248 85 249 This document is a reference manual and rationale for \CFA, a polymorphic extension of the C programming language. 86 It makes frequent reference to the {\c11} standard \cite{ C11}, and occasionally compares \CFA to {\CC} \cite{C++}.250 It makes frequent reference to the {\c11} standard \cite{ANS:C11}, and occasionally compares \CFA to {\CC} \cite{c++}. 87 251 88 252 The manual deliberately imitates the ordering of the {\c11} standard (although the section numbering differs). … … 578 742 579 743 There are two notable differences between \CFA's overload resolution rules and the rules for 580 {\CC} defined in \cite{ C++}.744 {\CC} defined in \cite{c++}. 581 745 First, the result type of a function plays a role. 582 746 In {\CC}, a function call must be completely resolved based on the arguments to the call in most circumstances. … … 3242 3406 \begin{itemize} 3243 3407 \item 3244 Inside a Clu cluster \cite{ CLU}, the declaration of an instance states which view applies.3408 Inside a Clu cluster \cite{clu}, the declaration of an instance states which view applies. 3245 3409 Two primitives called \lstinline$up$ and \lstinline$down$ can be used to convert between the views. 3246 3410 \item 3247 The Simula class \cite{S IMULA87} is essentially a record type.3411 The Simula class \cite{Simula87} is essentially a record type. 3248 3412 Since the only operations on a record are member selection and assignment, which can not be overloaded, there is never any ambiguity as to whether the abstraction or the implementation view is being used. 3249 3413 In {\CC} 3250 \cite{ C++}, operations on class instances include assignment and ``\lstinline$&$'', which can be overloaded.3414 \cite{c++}, operations on class instances include assignment and ``\lstinline$&$'', which can be overloaded. 3251 3415 A ``scope resolution'' operator can be used inside the class to specify whether the abstract or implementation version of the operation should be used. 3252 3416 \item 3253 An Ada derived type definition \cite{ Ada} creates a new type from an old type, and also implicitly declares derived subprograms that correspond to the existing subprograms that use the old type as a parameter type or result type.3417 An Ada derived type definition \cite{ada} creates a new type from an old type, and also implicitly declares derived subprograms that correspond to the existing subprograms that use the old type as a parameter type or result type. 3254 3418 The derived subprograms are clones of the existing subprograms with the old type replaced by the derived type. 3255 3419 Literals and aggregates of the old type are also cloned. … … 3864 4028 3865 4029 \bibliographystyle{plain} 3866 \bibliography{ cfa}4030 \bibliography{refrat} 3867 4031 3868 4032 -
doc/user/Makefile
rdf2be83 r5ba653c 1 1 ## Define the appropriate configuration variables. 2 2 3 TeXLIB = .: ../bibliography/:../LaTeXmacros/:3 TeXLIB = .:: 4 4 LaTeX = TEXINPUTS=${TeXLIB} && export TEXINPUTS && latex 5 BibTeX = B IBINPUTS=${TeXLIB} && export BIBINPUTS && bibtex5 BibTeX = BSTINPUTS=${TeXLIB} && export BSTINPUTS && bibtex 6 6 7 7 ## Define the text source files. … … 43 43 dvips $< -o $@ 44 44 45 ${basename ${DOCUMENT}}.dvi : Makefile ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${basename ${DOCUMENT}}.tex \ 46 ../LaTeXmacros/common.tex ../LaTeXmacros/indexstyle ../bibliography/cfa.bib 45 ${basename ${DOCUMENT}}.dvi : Makefile ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${basename ${DOCUMENT}}.tex ${basename ${DOCUMENT}}.bib /usr/local/bibliographies/pl.bib 47 46 # Conditionally create an empty *.ind (index) file for inclusion until makeindex is run. 48 47 if [ ! -r ${basename $@}.ind ] ; then touch ${basename $@}.ind ; fi … … 54 53 -${BibTeX} ${basename $@} 55 54 # Make index from *.aux entries and input index at end of document 56 makeindex -s ../LaTeXmacros/indexstyle ${basename $@}.idx55 makeindex -s indexstyle ${basename $@}.idx 57 56 ${LaTeX} ${basename $@}.tex 58 57 # Run again to get index title into table of contents -
doc/user/user.tex
rdf2be83 r5ba653c 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Fri Apr 8 11:40:53201614 %% Update Count : 4213 %% Last Modified On : Wed Apr 6 17:37:39 2016 14 %% Update Count : 34 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 43 43 % Names used in the document. 44 44 45 \newcommand{\CFA}{C$\mathbf\forall$\xspace} % set language symbolic name 46 \newcommand{\CFL}{Cforall\xspace} % set language text name 47 \newcommand{\CC}{C\kern-.1em\hbox{+\kern-.25em+}\xspace} % CC symbolic name 48 \def\c11{ISO/IEC C} % C11 name (cannot have numbers in latex command name) 45 49 \newcommand{\CS}{C\raisebox{-0.9ex}{\large$^\sharp$}\xspace} 46 50 … … 48 52 49 53 % Bespoke macros used in the document. 50 \input{common} 54 55 \makeatletter 56 % allow escape sequence in lstinline 57 %\usepackage{etoolbox} 58 %\patchcmd{\lsthk@TextStyle}{\let\lst@DefEsc\@empty}{}{}{\errmessage{failed to patch}} 59 60 \renewcommand\small{% 61 \@setfontsize\small{8.5}{11}% 62 \abovedisplayskip 8.5pt \@plus 3pt \@minus 4pt 63 \abovedisplayshortskip \z@ \@plus 2pt 64 \belowdisplayshortskip 4pt \@plus 2pt \@minus 2pt 65 \def\@listi{\leftmargin\leftmargini 66 \topsep 4pt \@plus 2pt \@minus 2pt 67 \parsep 2pt \@pluspt \@minuspt 68 \itemsep \parsep}% 69 \belowdisplayskip \abovedisplayskip 70 } 71 \usepackage{relsize} % must be after change to small 72 73 \renewcommand{\labelitemi}{{\raisebox{0.25ex}{\footnotesize$\bullet$}}} 74 \renewenvironment{itemize}{\begin{list}{\labelitemi}{\topsep=5pt\itemsep=5pt\parsep=0pt}}{\end{list}} 75 76 % Reduce size of section titles 77 \renewcommand\section{\@startsection{section}{1}{\z@}{-3.0ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\large\bfseries}} 78 \renewcommand\subsection{\@startsection{subsection}{2}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}} 79 \renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}} 80 \renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}{-2.0ex \@plus -1ex \@minus -.2ex}{-1em}{\normalfont\normalsize\bfseries}} 81 82 % index macros 83 \newcommand{\italic}[1]{\emph{\hyperpage{#1}}} 84 \newcommand{\definition}[1]{\textbf{\hyperpage{#1}}} 85 \newcommand{\see}[1]{\emph{see} #1} 86 87 % Define some commands that produce formatted index entries suitable for cross-references. 88 % ``\spec'' produces entries for specifications of entities. ``\impl'' produces entries for their 89 % implementations, and ``\use'' for their uses. 90 91 % \newcommand{\bold}[1]{{\bf #1}} 92 % \def\spec{\@bsphack\begingroup 93 % \def\protect##1{\string##1\space}\@sanitize 94 % \@wrxref{|bold}} 95 \def\impl{\@bsphack\begingroup 96 \def\protect##1{\string##1\space}\@sanitize 97 \@wrxref{|definition}} 98 \newcommand{\indexcode}[1]{{\lstinline$#1$}} 99 \def\use{\@bsphack\begingroup 100 \def\protect##1{\string##1\space}\@sanitize 101 \@wrxref{|hyperpage}} 102 \def\@wrxref#1#2{\let\thepage\relax 103 \xdef\@gtempa{\write\@indexfile{\string 104 \indexentry{#2@{\lstinline$#2$}#1}{\thepage}}}\endgroup\@gtempa 105 \if@nobreak \ifvmode\nobreak\fi\fi\@esphack} 106 %\newcommand{\use}[1]{\index{#1@{\lstinline$#1$}}} 107 %\newcommand{\impl}[1]{\index{\protect#1@{\lstinline$\protect#1$}|definition}} 108 109 % inline text and lowercase index: \Index{inline and lowercase index text} 110 % inline text and as-in index: \Index[as-is index text]{inline text} 111 % inline text but index with different as-is text: \Index[index text]{inline text} 112 \newcommand{\Index}{\@ifstar\@sIndex\@Index} 113 \newcommand{\@Index}[2][\@empty]{\lowercase{\def\temp{#2}}#2\ifx#1\@empty\index{\temp}\else\index{#1@{\protect#2}}\fi} 114 \newcommand{\@sIndex}[2][\@empty]{#2\ifx#1\@empty\index{#2}\else\index{#1@{\protect#2}}\fi} 115 116 \newcommand{\newtermFontInline}{\emph} 117 \newcommand{\newterm}{\@ifstar\@snewterm\@newterm} 118 \newcommand{\@newterm}[2][\@empty]{\lowercase{\def\temp{#2}}{\newtermFontInline{#2}}\ifx#1\@empty\index{\temp}\else\index{#1@{\protect#2}}\fi} 119 \newcommand{\@snewterm}[2][\@empty]{{\newtermFontInline{#2}}\ifx#1\@empty\index{#2}\else\index{#1@{\protect#2}}\fi} 120 \makeatother 121 122 % blocks and titles 123 \newenvironment{quote2}{% 124 \list{}{\lstset{resetmargins=true}\leftmargin=\parindent\rightmargin\leftmargin}% 125 \item\relax 126 }{% 127 \endlist 128 }% quote2 129 \newenvironment{rationale}{% 130 \begin{quotation}\noindent$\Box$\enspace 131 }{% 132 \hfill\enspace$\Box$\end{quotation} 133 }% 134 \newcommand{\define}[1]{\emph{#1\/}\index{#1}} 135 \newcommand{\rewrite}{\(\Rightarrow\)} 136 \newcommand{\rewriterules}{\paragraph{Rewrite Rules}~\par\noindent} 137 \newcommand{\examples}{\paragraph{Examples}~\par\noindent} 138 \newcommand{\semantics}{\paragraph{Semantics}~\par\noindent} 139 \newcommand{\constraints}{\paragraph{Constraints}~\par\noindent} 140 \newcommand{\predefined}{\paragraph{Predefined Identifiers}~\par\noindent} 141 142 % BNF macros 143 \def\syntax{\paragraph{Syntax}\trivlist\parindent=.5in\item[\hskip.5in]} 144 \let\endsyntax=\endtrivlist 145 \newcommand{\lhs}[1]{\par{\emph{#1:}}\index{#1@{\emph{#1}}|italic}} 146 \newcommand{\rhs}{\hfil\break\hbox{\hskip1in}} 147 \newcommand{\oldlhs}[1]{\emph{#1: \ldots}\index{#1@{\emph{#1}}|italic}} 148 \newcommand{\nonterm}[1]{\emph{#1\/}\index{#1@{\emph{#1}}|italic}} 149 \newcommand{\opt}{$_{opt}$\ } 150 151 % adjust varioref package with default "section" and "page" titles, and optional title with faraway page numbers 152 % \VRef{label} => Section 2.7, \VPageref{label} => page 17 153 % \VRef[Figure]{label} => Figure 3.4, \VPageref{label} => page 17 154 \renewcommand{\reftextfaceafter}{\unskip} 155 \renewcommand{\reftextfacebefore}{\unskip} 156 \renewcommand{\reftextafter}{\unskip} 157 \renewcommand{\reftextbefore}{\unskip} 158 \renewcommand{\reftextfaraway}[1]{\unskip, p.~\pageref{#1}} 159 \renewcommand{\reftextpagerange}[2]{\unskip, pp.~\pageref{#1}--\pageref{#2}} 160 \newcommand{\VRef}[2][Section]{\ifx#1\@empty\else{#1}\nobreakspace\fi\vref{#2}} 161 \newcommand{\VPageref}[2][page]{\ifx#1\@empty\else{#1}\nobreakspace\fi\pageref{#2}} 162 163 % Go programming language 164 \lstdefinelanguage{Golang}% 165 {morekeywords=[1]{package,import,func,type,struct,return,defer,panic, recover,select,var,const,iota,},% 166 morekeywords=[2]{string,uint,uint8,uint16,uint32,uint64,int,int8,int16, int32,int64, 167 bool,float32,float64,complex64,complex128,byte,rune,uintptr, error,interface},% 168 morekeywords=[3]{map,slice,make,new,nil,len,cap,copy,close,true,false, delete,append,real,imag,complex,chan,},% 169 morekeywords=[4]{for,break,continue,range,goto,switch,case,fallthrough,if, else,default,},% 170 morekeywords=[5]{Println,Printf,Error,},% 171 sensitive=true,% 172 morecomment=[l]{//},% 173 morecomment=[s]{/*}{*/},% 174 morestring=[b]',% 175 morestring=[b]",% 176 morestring=[s]{`}{`},% 177 } 178 179 % CFA based on ANSI C 180 \lstdefinelanguage{CFA}[ANSI]{C}% 181 {morekeywords={_Alignas,_Alignof,__alignof,__alignof__,asm,__asm,__asm__,_At,_Atomic,__attribute,__attribute__,auto, 182 _Bool,catch,catchResume,choose,_Complex,__complex,__complex__,__const,__const__,disable,dtype,enable,__extension__, 183 fallthru,finally,forall,ftype,_Generic,_Imaginary,inline,__label__,lvalue,_Noreturn,otype,restrict,_Static_assert, 184 _Thread_local,throw,throwResume,trait,try,typeof,__typeof,__typeof__,}, 185 moredelim=**[is][\color{red}]{`}{`}, 186 }% 187 188 \lstset{ 189 language=CFA, 190 columns=flexible, 191 basicstyle=\sf\relsize{-1}, 192 tabsize=4, 193 xleftmargin=\parindent, 194 escapechar=@, 195 mathescape=true, 196 keepspaces=true, 197 showstringspaces=false, 198 showlines=true, 199 aboveskip=6pt, 200 belowskip=4pt, 201 literate={\\`}{\raisebox{0.3ex}{\ttfamily\upshape \hspace*{-2pt}`}}1, % escape \`, otherwise used to highlight in red 202 %extendedchars=true, 203 }% 204 205 \makeatletter 206 % replace/adjust listings characters that look bad in sanserif 207 \lst@CCPutMacro 208 \lst@ProcessOther{"22}{\lst@ttfamily{"}{\raisebox{0.3ex}{\ttfamily\upshape "}}} % replace double quote 209 \lst@ProcessOther{"27}{\lst@ttfamily{'}{\raisebox{0.3ex}{\ttfamily\upshape '\hspace*{-2pt}}}} % replace single quote 210 \lst@ProcessOther{"2D}{\lst@ttfamily{-}{\ttfamily\upshape -}} % replace minus 211 \lst@ProcessOther{"3C}{\lst@ttfamily{<}{\texttt{<}}} % replace less than 212 \lst@ProcessOther{"3E}{\lst@ttfamily{<}{\texttt{>}}} % replace greater than 213 \lst@ProcessOther{"5E}{\raisebox{0.4ex}{$\scriptstyle\land\,$}} % replace circumflex 214 \lst@ProcessOther{"5F}{\lst@ttfamily{\char95}{{\makebox[1.2ex][c]{\rule{1ex}{0.1ex}}}}} % replace underscore 215 \lst@ProcessOther{"60}{\lst@ttfamily{`}{\raisebox{0.3ex}{\ttfamily\upshape \hspace*{-2pt}`}}} % replace backquote 216 \lst@ProcessOther{"7E}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}} % replace tilde 217 %\lst@ProcessOther{"7E}{\raisebox{-.4ex}[1ex][0pt]{\textasciitilde}} % lower tilde 218 \@empty\z@\@empty 219 \makeatother 51 220 52 221 \setcounter{secnumdepth}{3} % number subsubsections … … 4404 4573 4405 4574 4406 \section{Rational Numbers}4407 \label{s:RationalNumbers}4408 4409 Rational numbers are numbers written as a ratio, i.e., as a fraction, where the numerator (top number) and the denominator (bottom number) are whole numbers.4410 When creating and computing with rational numbers, results are constantly reduced to keep the numerator and denominator as small as possible.4411 4412 \begin{lstlisting}4413 // implementation4414 struct Rational {4415 long int numerator, denominator; // invariant: denominator > 04416 }; // Rational4417 4418 // constants4419 extern struct Rational 0;4420 extern struct Rational 1;4421 4422 // constructors4423 Rational rational();4424 Rational rational( long int n );4425 Rational rational( long int n, long int d );4426 4427 // getter/setter for numerator/denominator4428 long int numerator( Rational r );4429 long int numerator( Rational r, long int n );4430 long int denominator( Rational r );4431 long int denominator( Rational r, long int d );4432 4433 // comparison4434 int ?==?( Rational l, Rational r );4435 int ?!=?( Rational l, Rational r );4436 int ?<?( Rational l, Rational r );4437 int ?<=?( Rational l, Rational r );4438 int ?>?( Rational l, Rational r );4439 int ?>=?( Rational l, Rational r );4440 4441 // arithmetic4442 Rational -?( Rational r );4443 Rational ?+?( Rational l, Rational r );4444 Rational ?-?( Rational l, Rational r );4445 Rational ?*?( Rational l, Rational r );4446 Rational ?/?( Rational l, Rational r );4447 4448 // conversion4449 double widen( Rational r );4450 Rational narrow( double f, long int md );4451 4452 // I/O4453 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, Rational * );4454 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, Rational );4455 \end{lstlisting}4456 4457 4458 4575 \bibliographystyle{plain} 4459 \bibliography{ cfa}4576 \bibliography{/usr/local/bibliographies/pl.bib} 4460 4577 4461 4578 -
src/Parser/ExpressionNode.cc
rdf2be83 r5ba653c 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Apr 8 15:43:05201613 // Update Count : 2 9612 // Last Modified On : Sun Mar 13 12:34:38 2016 13 // Update Count : 272 14 14 // 15 15 … … 22 22 23 23 #include "ParseNode.h" 24 #include "TypeData.h"25 24 #include "SynTree/Constant.h" 26 25 #include "SynTree/Expression.h" 27 #include "SynTree/Declaration.h"28 26 #include "Common/UnimplementedError.h" 29 27 #include "parseutility.h" … … 874 872 } 875 873 876 877 CompoundLiteralNode::CompoundLiteralNode( DeclarationNode *type, InitializerNode *kids ) : type( type ), kids( kids ) {}878 CompoundLiteralNode::CompoundLiteralNode( const CompoundLiteralNode &other ) : ExpressionNode( other ), type( other.type ), kids( other.kids ) {}879 880 CompoundLiteralNode::~CompoundLiteralNode() {881 delete kids;882 delete type;883 }884 885 CompoundLiteralNode *CompoundLiteralNode::clone() const {886 return new CompoundLiteralNode( *this );887 }888 889 void CompoundLiteralNode::print( std::ostream &os, int indent ) const {890 os << string( indent,' ' ) << "CompoundLiteralNode:" << endl;891 892 os << string( indent + 2, ' ' ) << "type:" << endl;893 if ( type != 0 )894 type->print( os, indent + 4 );895 896 os << string( indent + 2, ' ' ) << "initialization:" << endl;897 if ( kids != 0 )898 kids->printList( os, indent + 4 );899 }900 901 void CompoundLiteralNode::printOneLine( std::ostream &os, int indent ) const {902 os << "( ";903 if ( type ) type->print( os );904 os << ", ";905 if ( kids ) kids->printOneLine( os );906 os << ") ";907 }908 909 Expression *CompoundLiteralNode::build() const {910 Declaration * newDecl = type->build(); // compound literal type911 if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type912 return new CompoundLiteralExpr( newDeclWithType->get_type(), kids->build() );913 // these types do not have associated type information914 } else if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( newDecl ) ) {915 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), kids->build() );916 } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( newDecl ) ) {917 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), kids->build() );918 } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( newDecl ) ) {919 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), kids->build() );920 } else {921 assert( false );922 } // if923 }924 925 926 874 ExpressionNode *flattenCommas( ExpressionNode *list ) { 927 875 if ( CompositeExprNode *composite = dynamic_cast< CompositeExprNode * >( list ) ) { -
src/Parser/ParseNode.h
rdf2be83 r5ba653c 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Apr 8 16:27:20201613 // Update Count : 20512 // Last Modified On : Wed Mar 2 17:26:35 2016 13 // Update Count : 190 14 14 // 15 15 … … 538 538 }; 539 539 540 class CompoundLiteralNode : public ExpressionNode {541 public:542 CompoundLiteralNode( DeclarationNode *type, InitializerNode *kids );543 CompoundLiteralNode( const CompoundLiteralNode &type );544 ~CompoundLiteralNode();545 546 virtual CompoundLiteralNode *clone() const;547 548 DeclarationNode *get_type() const { return type; }549 CompoundLiteralNode *set_type( DeclarationNode *t ) { type = t; return this; }550 551 InitializerNode *get_initializer() const { return kids; }552 CompoundLiteralNode *set_initializer( InitializerNode *k ) { kids = k; return this; }553 554 void print( std::ostream &, int indent = 0 ) const;555 void printOneLine( std::ostream &, int indent = 0 ) const;556 557 virtual Expression *build() const;558 private:559 DeclarationNode *type;560 InitializerNode *kids;561 };562 563 540 template< typename SynTreeType, typename NodeType > 564 541 void buildList( const NodeType *firstNode, std::list< SynTreeType *> &outputList ) { -
src/Parser/parser.cc
rdf2be83 r5ba653c 5180 5180 /* Line 1806 of yacc.c */ 5181 5181 #line 374 "parser.yy" 5182 { (yyval.en) = new CompoundLiteralNode( (yyvsp[(2) - (7)].decl), new InitializerNode( (yyvsp[(5) - (7)].in), true ) ); }5182 { (yyval.en) = 0; } 5183 5183 break; 5184 5184 -
src/Parser/parser.yy
rdf2be83 r5ba653c 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Apr 8 16:21:55201613 // Update Count : 1 50812 // Last Modified On : Thu Mar 24 16:16:16 2016 13 // Update Count : 1498 14 14 // 15 15 … … 372 372 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::DecrPost ), $1 ); } 373 373 | '(' type_name_no_function ')' '{' initializer_list comma_opt '}' // C99 374 { $$ = new CompoundLiteralNode( $2, new InitializerNode( $5, true ) ); }374 { $$ = 0; } 375 375 | postfix_expression '{' argument_expression_list '}' // CFA 376 376 { -
src/SymTab/AddVisit.h
rdf2be83 r5ba653c 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 16:14:32 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : T hu Apr 7 14:42:21 201613 // Update Count : 511 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Jul 14 12:26:17 2015 13 // Update Count : 4 14 14 // 15 15 … … 27 27 28 28 template< typename Visitor > 29 inline void addVisitStatement( Statement *stmt, Visitor &visitor ) { 30 maybeAccept( stmt, visitor ); 31 /// if ( ! declsToAdd.empty() ) { 32 /// CompoundStmt *compound = new CompoundStmt( noLabels ); 33 /// compound->get_kids().push_back( stmt ); 34 /// addDecls( declsToAdd, compound->get_kids(), compound->get_kids().end() ); 35 /// } 36 } 37 38 template< typename Visitor > 29 39 inline void addVisit(CompoundStmt *compoundStmt, Visitor &visitor) { 30 40 addVisitStatementList( compoundStmt->get_kids(), visitor ); 41 } 42 43 template< typename Visitor > 44 inline void addVisit(IfStmt *ifStmt, Visitor &visitor) { 45 addVisitStatement( ifStmt->get_thenPart(), visitor ); 46 addVisitStatement( ifStmt->get_elsePart(), visitor ); 47 maybeAccept( ifStmt->get_condition(), visitor ); 48 } 49 50 template< typename Visitor > 51 inline void addVisit(WhileStmt *whileStmt, Visitor &visitor) { 52 addVisitStatement( whileStmt->get_body(), visitor ); 53 maybeAccept( whileStmt->get_condition(), visitor ); 54 } 55 56 template< typename Visitor > 57 inline void addVisit(ForStmt *forStmt, Visitor &visitor) { 58 addVisitStatement( forStmt->get_body(), visitor ); 59 acceptAll( forStmt->get_initialization(), visitor ); 60 maybeAccept( forStmt->get_condition(), visitor ); 61 maybeAccept( forStmt->get_increment(), visitor ); 31 62 } 32 63 … … 43 74 } 44 75 45 // template< typename Visitor > 46 // inline void addVisit(CaseStmt *caseStmt, Visitor &visitor) { 47 // addVisitStatementList( caseStmt->get_statements(), visitor ); 48 // maybeAccept( caseStmt->get_condition(), visitor ); 49 // } 76 template< typename Visitor > 77 inline void addVisit(CaseStmt *caseStmt, Visitor &visitor) { 78 addVisitStatementList( caseStmt->get_statements(), visitor ); 79 maybeAccept( caseStmt->get_condition(), visitor ); 80 } 81 82 template< typename Visitor > 83 inline void addVisit(CatchStmt *cathStmt, Visitor &visitor) { 84 addVisitStatement( cathStmt->get_body(), visitor ); 85 maybeAccept( cathStmt->get_decl(), visitor ); 86 } 50 87 } // namespace SymTab 51 88 -
src/SymTab/Validate.cc
rdf2be83 r5ba653c 10 10 // Created On : Sun May 17 21:50:04 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Apr 7 16:45:30201613 // Update Count : 2 4312 // Last Modified On : Wed Mar 2 17:31:39 2016 13 // Update Count : 226 14 14 // 15 15 … … 40 40 #include <list> 41 41 #include <iterator> 42 #include "Common/utility.h"43 #include "Common/UniqueName.h"44 42 #include "Validate.h" 45 43 #include "SynTree/Visitor.h" 46 44 #include "SynTree/Mutator.h" 47 45 #include "SynTree/Type.h" 48 #include "SynTree/Expression.h"49 46 #include "SynTree/Statement.h" 50 47 #include "SynTree/TypeSubstitution.h" … … 52 49 #include "FixFunction.h" 53 50 // #include "ImplementationType.h" 54 #include "GenPoly/DeclMutator.h" 51 #include "Common/utility.h" 52 #include "Common/UniqueName.h" 55 53 #include "AddVisit.h" 56 54 #include "MakeLibCfa.h" … … 72 70 73 71 virtual void visit( CompoundStmt *compoundStmt ); 72 virtual void visit( IfStmt *ifStmt ); 73 virtual void visit( WhileStmt *whileStmt ); 74 virtual void visit( ForStmt *forStmt ); 74 75 virtual void visit( SwitchStmt *switchStmt ); 75 76 virtual void visit( ChooseStmt *chooseStmt ); 76 // virtual void visit( CaseStmt *caseStmt ); 77 virtual void visit( CaseStmt *caseStmt ); 78 virtual void visit( CatchStmt *catchStmt ); 77 79 private: 78 80 HoistStruct(); … … 142 144 143 145 virtual void visit( CompoundStmt *compoundStmt ); 146 virtual void visit( IfStmt *ifStmt ); 147 virtual void visit( WhileStmt *whileStmt ); 148 virtual void visit( ForStmt *forStmt ); 144 149 virtual void visit( SwitchStmt *switchStmt ); 145 150 virtual void visit( ChooseStmt *chooseStmt ); 146 // virtual void visit( CaseStmt *caseStmt ); 151 virtual void visit( CaseStmt *caseStmt ); 152 virtual void visit( CatchStmt *catchStmt ); 147 153 148 154 AutogenerateRoutines() : functionNesting( 0 ) {} … … 160 166 /// and return something if the return type is non-void. 161 167 static void checkFunctionReturns( std::list< Declaration * > & translationUnit ); 168 162 169 private: 163 170 virtual void visit( FunctionDecl * functionDecl ); … … 195 202 }; 196 203 197 class CompoundLiteral : public GenPoly::DeclMutator {198 DeclarationNode::StorageClass storageclass = DeclarationNode::NoStorageClass;199 200 virtual DeclarationWithType * mutate( ObjectDecl *objectDecl );201 virtual Expression *mutate( CompoundLiteralExpr *compLitExpr );202 };203 204 204 void validate( std::list< Declaration * > &translationUnit, bool doDebug ) { 205 205 Pass1 pass1; 206 206 Pass2 pass2( doDebug, 0 ); 207 207 Pass3 pass3( 0 ); 208 CompoundLiteral compoundliteral;209 210 208 EliminateTypedef::eliminateTypedef( translationUnit ); 211 209 HoistStruct::hoistStruct( translationUnit ); … … 213 211 acceptAll( translationUnit, pass2 ); 214 212 ReturnChecker::checkFunctionReturns( translationUnit ); 215 mutateAll( translationUnit, compoundliteral );216 213 AutogenerateRoutines::autogenerateRoutines( translationUnit ); 217 214 acceptAll( translationUnit, pass3 ); … … 295 292 } 296 293 294 void HoistStruct::visit( IfStmt *ifStmt ) { 295 addVisit( ifStmt, *this ); 296 } 297 298 void HoistStruct::visit( WhileStmt *whileStmt ) { 299 addVisit( whileStmt, *this ); 300 } 301 302 void HoistStruct::visit( ForStmt *forStmt ) { 303 addVisit( forStmt, *this ); 304 } 305 297 306 void HoistStruct::visit( SwitchStmt *switchStmt ) { 298 307 addVisit( switchStmt, *this ); … … 303 312 } 304 313 305 // void HoistStruct::visit( CaseStmt *caseStmt ) { 306 // addVisit( caseStmt, *this ); 307 // } 314 void HoistStruct::visit( CaseStmt *caseStmt ) { 315 addVisit( caseStmt, *this ); 316 } 317 318 void HoistStruct::visit( CatchStmt *cathStmt ) { 319 addVisit( cathStmt, *this ); 320 } 308 321 309 322 void Pass1::visit( EnumDecl *enumDecl ) { … … 861 874 } 862 875 876 void AutogenerateRoutines::visit( IfStmt *ifStmt ) { 877 visitStatement( ifStmt ); 878 } 879 880 void AutogenerateRoutines::visit( WhileStmt *whileStmt ) { 881 visitStatement( whileStmt ); 882 } 883 884 void AutogenerateRoutines::visit( ForStmt *forStmt ) { 885 visitStatement( forStmt ); 886 } 887 863 888 void AutogenerateRoutines::visit( SwitchStmt *switchStmt ) { 864 889 visitStatement( switchStmt ); … … 869 894 } 870 895 871 // void AutogenerateRoutines::visit( CaseStmt *caseStmt ) { 872 // visitStatement( caseStmt ); 873 // } 896 void AutogenerateRoutines::visit( CaseStmt *caseStmt ) { 897 visitStatement( caseStmt ); 898 } 899 900 void AutogenerateRoutines::visit( CatchStmt *cathStmt ) { 901 visitStatement( cathStmt ); 902 } 874 903 875 904 void ReturnChecker::checkFunctionReturns( std::list< Declaration * > & translationUnit ) { … … 1051 1080 } 1052 1081 1053 DeclarationWithType * CompoundLiteral::mutate( ObjectDecl *objectDecl ) {1054 storageclass = objectDecl->get_storageClass();1055 DeclarationWithType * temp = Mutator::mutate( objectDecl );1056 storageclass = DeclarationNode::NoStorageClass;1057 return temp;1058 }1059 1060 Expression *CompoundLiteral::mutate( CompoundLiteralExpr *compLitExpr ) {1061 // transform [storage_class] ... (struct S){ 3, ... };1062 // into [storage_class] struct S temp = { 3, ... };1063 static UniqueName indexName( "_compLit" );1064 1065 ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageclass, LinkageSpec::C, 0, compLitExpr->get_type(), compLitExpr->get_initializer() );1066 compLitExpr->set_type( 0 );1067 compLitExpr->set_initializer( 0 );1068 delete compLitExpr;1069 DeclarationWithType * newtempvar = mutate( tempvar );1070 addDeclaration( newtempvar ); // add modified temporary to current block1071 return new VariableExpr( newtempvar );1072 }1073 1082 } // namespace SymTab 1074 1083 -
src/SynTree/Expression.cc
rdf2be83 r5ba653c 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Fri Apr 8 17:16:23 201613 // Update Count : 4011 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Dec 09 14:10:29 2015 13 // Update Count : 34 14 14 // 15 15 … … 22 22 23 23 #include "Type.h" 24 #include "Initializer.h"25 24 #include "Expression.h" 26 25 #include "Declaration.h" … … 465 464 466 465 467 CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) {468 add_result( type->clone() );469 }470 471 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( maybeClone( other.type ) ), initializer( maybeClone( other.initializer ) ) {}472 473 CompoundLiteralExpr::~CompoundLiteralExpr() {474 delete initializer;475 delete type;476 }477 478 void CompoundLiteralExpr::print( std::ostream &os, int indent ) const {479 os << "Compound Literal Expression: " << std::endl;480 if ( type ) type->print( os, indent + 2 );481 if ( initializer ) initializer->print( os, indent + 2 );482 }483 484 466 485 467 std::ostream & operator<<( std::ostream & out, Expression * expr ) { -
src/SynTree/Expression.h
rdf2be83 r5ba653c 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Fri Apr 8 17:18:06 201613 // Update Count : 2111 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Dec 09 14:10:21 2015 13 // Update Count : 19 14 14 // 15 15 … … 577 577 }; 578 578 579 /// CompoundLiteralExpr represents a C99 'compound literal'580 class CompoundLiteralExpr : public Expression {581 public:582 CompoundLiteralExpr( Type * type, Initializer * initializer );583 CompoundLiteralExpr( const CompoundLiteralExpr &other );584 ~CompoundLiteralExpr();585 586 Type * get_type() const { return type; }587 void set_type( Type * t ) { type = t; }588 589 Initializer * get_initializer() const { return initializer; }590 void set_initializer( Initializer * i ) { initializer = i; }591 592 virtual CompoundLiteralExpr *clone() const { return new CompoundLiteralExpr( *this ); }593 virtual void accept( Visitor &v ) { v.visit( this ); }594 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }595 virtual void print( std::ostream &os, int indent = 0 ) const;596 private:597 Type * type;598 Initializer * initializer;599 };600 601 579 std::ostream & operator<<( std::ostream & out, Expression * expr ); 602 580 -
src/SynTree/Mutator.cc
rdf2be83 r5ba653c 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Apr 1 18:05:16201613 // Update Count : 1 612 // Last Modified On : Wed Mar 2 17:28:20 2016 13 // Update Count : 12 14 14 // 15 15 … … 342 342 } 343 343 344 Expression *Mutator::mutate( CompoundLiteralExpr *compLitExpr ) {345 mutateAll( compLitExpr->get_results(), *this );346 compLitExpr->set_type( maybeMutate( compLitExpr->get_type(), *this ) );347 compLitExpr->set_initializer( maybeMutate( compLitExpr->get_initializer(), *this ) );348 return compLitExpr;349 }350 351 344 Type *Mutator::mutate( VoidType *voidType ) { 352 345 mutateAll( voidType->get_forall(), *this ); -
src/SynTree/Mutator.h
rdf2be83 r5ba653c 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Apr 1 17:26:56201613 // Update Count : 1012 // Last Modified On : Wed Mar 2 17:33:11 2016 13 // Update Count : 9 14 14 // 15 15 #include <cassert> … … 77 77 virtual Expression* mutate( AsmExpr *asmExpr ); 78 78 virtual Expression* mutate( UntypedValofExpr *valofExpr ); 79 virtual Expression* mutate( CompoundLiteralExpr *compLitExpr );80 79 81 80 virtual Type* mutate( VoidType *basicType ); -
src/SynTree/SynTree.h
rdf2be83 r5ba653c 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Apr 1 16:47:44201613 // Update Count : 512 // Last Modified On : Wed Mar 2 17:29:00 2016 13 // Update Count : 4 14 14 // 15 15 … … 82 82 class AsmExpr; 83 83 class UntypedValofExpr; 84 class CompoundLiteralExpr;85 84 86 85 class Type; -
src/SynTree/Visitor.cc
rdf2be83 r5ba653c 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Apr 1 18:05:13 201613 // Update Count : 1 812 // Last Modified On : Wed Mar 2 17:29:23 2016 13 // Update Count : 16 14 14 // 15 15 … … 289 289 } 290 290 291 void Visitor::visit( CompoundLiteralExpr *compLitExpr ) {292 acceptAll( compLitExpr->get_results(), *this );293 maybeAccept( compLitExpr->get_type(), *this );294 maybeAccept( compLitExpr->get_initializer(), *this );295 }296 297 291 void Visitor::visit( VoidType *voidType ) { 298 292 acceptAll( voidType->get_forall(), *this ); -
src/SynTree/Visitor.h
rdf2be83 r5ba653c 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Apr 1 17:26:55 201613 // Update Count : 712 // Last Modified On : Wed Mar 2 17:33:35 2016 13 // Update Count : 6 14 14 // 15 15 … … 77 77 virtual void visit( AsmExpr *asmExpr ); 78 78 virtual void visit( UntypedValofExpr *valofExpr ); 79 virtual void visit( CompoundLiteralExpr *compLitExpr );80 79 81 80 virtual void visit( VoidType *basicType ); -
src/examples/rational.c
rdf2be83 r5ba653c 6 6 // file "LICENCE" distributed with Cforall. 7 7 // 8 // rational.c -- test rational number package8 // rational.c -- 9 9 // 10 10 // Author : Peter A. Buhr 11 11 // Created On : Mon Mar 28 08:43:12 2016 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Fri Apr 8 11:27:48201614 // Update Count : 2 113 // Last Modified On : Thu Apr 7 17:25:44 2016 14 // Update Count : 20 15 15 // 16 16 -
src/libcfa/rational
rdf2be83 r5ba653c 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // rational -- Rational numbers are numbers written as a ratio, i.e., as a fraction, where the numerator (top number) 8 // and the denominator (bottom number) are whole numbers. When creating and computing with rational numbers, results 9 // are constantly reduced to keep the numerator and denominator as small as possible. 7 // rational -- 10 8 // 11 9 // Author : Peter A. Buhr 12 10 // Created On : Wed Apr 6 17:56:25 2016 13 11 // Last Modified By : Peter A. Buhr 14 // Last Modified On : Fri Apr 8 11:38:27201615 // Update Count : 1512 // Last Modified On : Thu Apr 7 17:23:36 2016 13 // Update Count : 9 16 14 // 17 15 18 16 #include "iostream" 19 17 20 // implementation21 18 struct Rational { 22 19 long int numerator, denominator; // invariant: denominator > 0 23 20 }; // Rational 24 21 25 // constants26 22 extern struct Rational 0; 27 23 extern struct Rational 1; 28 24 29 // constructors 30 Rational rational(); 31 Rational rational( long int n ); 32 Rational rational( long int n, long int d ); 33 34 // getter/setter for numerator/denominator 25 long int gcd( long int a, long int b ); 26 long int simplify( long int *n, long int *d ); 27 Rational rational(); // constructor 28 Rational rational( long int n ); // constructor 29 Rational rational( long int n, long int d ); // constructor 35 30 long int numerator( Rational r ); 36 31 long int numerator( Rational r, long int n ); 37 long int denominator( Rational r );38 32 long int denominator( Rational r, long int d ); 39 40 // comparison41 33 int ?==?( Rational l, Rational r ); 42 34 int ?!=?( Rational l, Rational r ); … … 45 37 int ?>?( Rational l, Rational r ); 46 38 int ?>=?( Rational l, Rational r ); 47 48 // arithmetic49 39 Rational -?( Rational r ); 50 40 Rational ?+?( Rational l, Rational r ); … … 52 42 Rational ?*?( Rational l, Rational r ); 53 43 Rational ?/?( Rational l, Rational r ); 54 55 // conversion56 44 double widen( Rational r ); 57 45 Rational narrow( double f, long int md ); 58 59 // I/O60 46 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, Rational * ); 61 47 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, Rational ); -
src/libcfa/rational.c
rdf2be83 r5ba653c 11 11 // Created On : Wed Apr 6 17:54:28 2016 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Fri Apr 8 17:35:05201614 // Update Count : 1 813 // Last Modified On : Thu Apr 7 17:28:03 2016 14 // Update Count : 12 15 15 // 16 16 … … 23 23 } // extern 24 24 25 26 // constants27 28 25 struct Rational 0 = {0, 1}; 29 26 struct Rational 1 = {1, 1}; 30 27 31 32 // helper 33 34 // Calculate greatest common denominator of two numbers, the first of which may be negative. Used to reduce rationals. 35 static long int gcd( long int a, long int b ) { 28 // Calculate the greatest common denominator of two numbers, the first of which may be negative. It is used to reduce 29 // rationals. 30 31 long int gcd( long int a, long int b ) { 36 32 for ( ;; ) { // Euclid's algorithm 37 33 long int r = a % b; … … 43 39 } // gcd 44 40 45 staticlong int simplify( long int *n, long int *d ) {41 long int simplify( long int *n, long int *d ) { 46 42 if ( *d == 0 ) { 47 43 serr | "Invalid rational number construction: denominator cannot be equal to 0." | endl; … … 52 48 } // Rationalnumber::simplify 53 49 54 55 // constructors 56 57 Rational rational() { 58 return (Rational){ 0, 1 }; 50 Rational rational() { // constructor 51 // r = (Rational){ 0, 1 }; 52 Rational t = { 0, 1 }; 53 return t; 59 54 } // rational 60 55 61 Rational rational( long int n ) { 62 return (Rational){ n, 1 }; 56 Rational rational( long int n ) { // constructor 57 // r = (Rational){ n, 1 }; 58 Rational t = { n, 1 }; 59 return t; 63 60 } // rational 64 61 65 Rational rational( long int n, long int d ) { 62 Rational rational( long int n, long int d ) { // constructor 66 63 long int t = simplify( &n, &d ); // simplify 67 return (Rational){ n / t, d / t }; 64 // r = (Rational){ n / t, d / t }; 65 Rational t = { n / t, d / t }; 66 return t; 68 67 } // rational 69 70 71 // getter/setter for numerator/denominator72 68 73 69 long int numerator( Rational r ) { … … 83 79 } // numerator 84 80 85 long int denominator( Rational r ) {86 return r.denominator;87 } // denominator88 89 81 long int denominator( Rational r, long int d ) { 90 82 long int prev = r.denominator; … … 95 87 } // denominator 96 88 97 98 // comparison99 100 89 int ?==?( Rational l, Rational r ) { 101 90 return l.numerator * r.denominator == l.denominator * r.numerator; … … 121 110 return ! ( l < r ); 122 111 } // ?>=? 123 124 125 // arithmetic126 112 127 113 Rational -?( Rational r ) { … … 163 149 return t; 164 150 } // ?/? 165 166 167 // conversion168 151 169 152 double widen( Rational r ) { … … 205 188 } // narrow 206 189 207 208 // I/O209 210 190 forall( dtype istype | istream( istype ) ) 211 191 istype * ?|?( istype *is, Rational *r ) {
Note:
See TracChangeset
for help on using the changeset viewer.