source: doc/theses/aaron_moss_PhD/phd/cfa-macros.tex @ 2801829

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 2801829 was 4075228, checked in by Aaron Moss <a3moss@…>, 6 years ago

Start generics chapter of thesis, add code examples of C polymorphic types

  • Property mode set to 100644
File size: 3.2 KB
Line 
1\usepackage{listings}
2
3% Default underscore is too low and wide. Cannot use lstlisting "literate" as replacing underscore
4% removes it as a variable-name character so keywords in variables are highlighted. MUST APPEAR
5% AFTER HYPERREF.
6%\DeclareTextCommandDefault{\textunderscore}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.1ex}}}
7\renewcommand{\textunderscore}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}}
8
9\renewcommand*{\thefootnote}{\Alph{footnote}} % hack because fnsymbol does not work
10%\renewcommand*{\thefootnote}{\fnsymbol{footnote}}
11
12\makeatletter
13% parindent is relative, i.e., toggled on/off in environments like itemize, so store the value for
14% use rather than use \parident directly.
15\newlength{\parindentlnth}
16\setlength{\parindentlnth}{\parindent}
17
18\newcommand{\LstBasicStyle}[1]{{\lst@basicstyle{\lst@basicstyle{#1}}}}
19\newcommand{\LstKeywordStyle}[1]{{\lst@basicstyle{\lst@keywordstyle{#1}}}}
20\newcommand{\LstCommentStyle}[1]{{\lst@basicstyle{\lst@commentstyle{#1}}}}
21
22\newcommand{\C}[2][3.5in]{\hfill\makebox[#1][l]{\LstCommentStyle{#2}}}
23
24% CFA programming language, based on ANSI C (with some gcc additions)
25\lstdefinelanguage{CFA}[ANSI]{C}{
26        morekeywords={
27                _Alignas, _Alignof, __alignof, __alignof__, asm, __asm, __asm__, __attribute, __attribute__,
28                auto, bool, _Bool, catch, catchResume, choose, _Complex, __complex, __complex__, __const, __const__,
29                coroutine, disable, dtype, enable, exception, __extension__, fallthrough, fallthru, finally,
30                __float80, float80, __float128, float128, forall, ftype, _Generic, _Imaginary, __imag, __imag__,
31                inline, __inline, __inline__, __int128, int128, __label__, monitor, mutex, _Noreturn, one_t, or,
32                otype, restrict, __restrict, __restrict__, __signed, __signed__, _Static_assert, thread,
33                _Thread_local, throw, throwResume, timeout, trait, try, ttype, typeof, __typeof, __typeof__,
34                virtual, __volatile, __volatile__, waitfor, when, with, zero_t},
35        moredirectives={defined,include_next}%
36}
37
38\lstset{
39language=CFA,
40columns=fullflexible,
41basicstyle=\linespread{0.9}\sf,                                                 % reduce line spacing and use sanserif font
42stringstyle=\tt,                                                                                % use typewriter font
43tabsize=5,                                                                                              % N space tabbing
44xleftmargin=\parindentlnth,                                                             % indent code to paragraph indentation
45escapechar=\$,                                                                                  % LaTeX escape in CFA code
46keepspaces=true,                                                                                %
47showstringspaces=false,                                                                 % do not show spaces with cup
48showlines=true,                                                                                 % show blank lines at end of code
49aboveskip=4pt,                                                                                  % spacing above/below code block
50belowskip=3pt,
51% replace/adjust listing characters that look bad in sanserif
52literate={-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.1ex}}}}1 {^}{\raisebox{0.6ex}{$\scriptstyle\land\,$}}1
53        {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 % {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1
54        {<}{\textrm{\textless}}1 {>}{\textrm{\textgreater}}1
55        {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1ex][c]{\raisebox{0.5ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex{\textrm{\textgreater}}}2,
56moredelim=**[is][\color{red}]{`}{`},
57}% lstset
58
59\lstnewenvironment{cfa}[1][]
60{\lstset{#1}}
61{}
62\lstnewenvironment{C++}[1][]                            % use C++ style
63{\lstset{language=C++,moredelim=**[is][\protect\color{red}]{`}{`},#1}\lstset{#1}}
64{}
65
66% inline code !...!
67\lstMakeShortInline!
68
Note: See TracBrowser for help on using the repository browser.