% T I T L E P A G E % ------------------- % Last updated August 16, 2022, by IST-Client Services % The title page is counted as page `i' but we need to suppress the % page number. Also, we don't want any headers or footers. \pagestyle{empty} \pagenumbering{roman} % The contents of the title page are specified in the "titlepage" % environment. \begin{titlepage} \begin{center} \vspace*{1.0cm} \Huge {\bf Enumerated Types in \CFA} \vspace*{1.0cm} \normalsize by \\ \vspace*{1.0cm} \Large Jiada Liang \\ \vspace*{3.0cm} \normalsize A thesis \\ presented to the University of Waterloo \\ in fulfillment of the \\ thesis requirement for the degree of \\ Master of Mathematics \\ in \\ Computer Science \\ \vspace*{2.0cm} Waterloo, Ontario, Canada, \the\year \\ \vspace*{1.0cm} \copyright{} Jiada Liang \the\year \\ \end{center} \end{titlepage} % The rest of the front pages should contain no headers and be numbered using Roman numerals starting with `ii' \pagestyle{plain} \setcounter{page}{2} \cleardoublepage % Ends the current page and causes all figures and tables that have so far appeared in the input to be printed. % In a two-sided printing style, it also makes the next page a right-hand (odd-numbered) page, producing a blank page if necessary. \phantomsection % allows hyperref to link to the correct page \begin{comment} % E X A M I N I N G C O M M I T T E E (Required for Ph.D. theses only) % Remove or comment out the lines below to remove this page \addcontentsline{toc}{chapter}{Examining Committee} \begin{center}\textbf{Examining Committee Membership}\end{center} \noindent The following served on the Examining Committee for this thesis. The decision of the Examining Committee is by majority vote. \bigskip \noindent \begin{tabbing} Internal-External Member: \= \kill % using longest text to define tab length External Examiner: \> Bruce Bruce \\ \> Professor, Dept. of Philosophy of Zoology, University of Wallamaloo \\ \end{tabbing} \bigskip \noindent \begin{tabbing} Internal-External Member: \= \kill % using longest text to define tab length Supervisor(s): \> Ann Elk \\ \> Professor, Dept. of Zoology, University of Waterloo \\ \> Andrea Anaconda \\ \> Professor Emeritus, Dept. of Zoology, University of Waterloo \\ \end{tabbing} \bigskip \noindent \begin{tabbing} Internal-External Member: \= \kill % using longest text to define tab length Internal Member: \> Pamela Python \\ \> Professor, Dept. of Zoology, University of Waterloo \\ \end{tabbing} \bigskip \noindent \begin{tabbing} Internal-External Member: \= \kill % using longest text to define tab length Internal-External Member: \> Meta Meta \\ \> Professor, Dept. of Philosophy, University of Waterloo \\ \end{tabbing} \bigskip \noindent \begin{tabbing} Internal-External Member: \= \kill % using longest text to define tab length Other Member(s): \> Leeping Fang \\ \> Professor, Dept. of Fine Art, University of Waterloo \\ \end{tabbing} \cleardoublepage \end{comment} % D E C L A R A T I O N P A G E % ------------------------------- % The following is a sample Declaration Page as provided by the GSO % December 13th, 2006. It is designed for an electronic thesis. \addcontentsline{toc}{chapter}{Author's Declaration} \begin{center}\textbf{Author's Declaration}\end{center} \noindent I hereby declare that I am the sole author of this thesis. This is a true copy of the thesis, including any required final revisions, as accepted by my examiners. \bigskip \noindent I understand that my thesis may be made electronically available to the public. \cleardoublepage \phantomsection % allows hyperref to link to the correct page % A B S T R A C T % --------------- \addcontentsline{toc}{chapter}{Abstract} \begin{center}\textbf{Abstract}\end{center} An \emph{enumeration} is a type defining a (ordered) set of named constant values. \begin{cfa} enum Week { Mon, Tue, Wed, Thu, Fri, Sat, Sun }; enum Math { PI = 3.14159, Tau = 6.28318, Phi = 1.61803 }; enum RGB { Red = 100b, Green = 010b, Blue = 001b }; \end{cfa} Its purpose is for readability: replacing constant values in a program with symbolic names that are more meaningful to programmers in the context of the application. Thereafter, associating a name to a different value automatically distributes this rebinding, preventing errors. One of the key properties of an enumeration is the ability to enumerate (iterate) through the constants, and hence, access their values, if present. C restricts an enumeration to the integral type @signed int@, while \CC extends enumerations to all integral types, meaning enumeration names must bind to integer constants. Other modern programming languages provide bindings to any type and additional features to extend enumeration capabilities for better software-engineering practices. The \CFA (C-for-all) programming language is an evolutionary refinement of the C programing language. One of its distinctive feature is a parametric-polymorphic generic type. However, legacy data types from C, such as enumerations, do not adapt well into the \CFA generic type-system. This thesis extends the simple and unsafe enumeration type in the C programming language into a complex and safe enumeration type in the \CFA programming-language, while maintaining backwards compatibility with C. The major contribution is an adaptation of enumerated types with the \CFA type-system in a way that integrates naturally with the generic types. This thesis also presents a number of smaller refinement to the \CFA overload resolution rules for enumerated types, each of which improves the intuitive nature of enumeration name resolution by the compiler. Finally, this work adds other useful features to enumerations that better support software-engineering practices and simplify program development. \cleardoublepage \phantomsection % allows hyperref to link to the correct page % A C K N O W L E D G E M E N T S % ------------------------------- \addcontentsline{toc}{chapter}{Acknowledgements} \begin{center}\textbf{Acknowledgements}\end{center} To begin, I would like to thank my supervisor Professor Peter Buhr. Thank you for your guidance and support throughout my study and research. I would not be here without you. Thanks to Gregor Richards and Yzihou Zhang for reading my thesis. Special thanks to Andrew James Beach for your insight on the theory development on the thesis. Thanks to Michael Brooks, Fangran Yu, Colby Parsons, Thierry Delisle, Mubeen Zulifiqar, and the entire \CFA team for development of the \CFA language, making it the best language it can be. Finally, a special thank you to Huawei Canada for funding this work. \cleardoublepage \phantomsection % allows hyperref to link to the correct page \begin{comment} % D E D I C A T I O N % ------------------- \addcontentsline{toc}{chapter}{Dedication} \begin{center}\textbf{Dedication}\end{center} This is dedicated to the one I love. \cleardoublepage \end{comment} % T A B L E O F C O N T E N T S % --------------------------------- \renewcommand\contentsname{Table of Contents} \tableofcontents \cleardoublepage \phantomsection % allows hyperref to link to the correct page % L I S T O F F I G U R E S % ----------------------------- \addcontentsline{toc}{chapter}{List of Figures} \listoffigures \cleardoublepage \phantomsection % allows hyperref to link to the correct page % L I S T O F T A B L E S % --------------------------- \addcontentsline{toc}{chapter}{List of Tables} \listoftables \cleardoublepage \phantomsection % allows hyperref to link to the correct page \begin{comment} % L I S T O F A B B R E V I A T I O N S % --------------------------- \renewcommand*{\abbreviationsname}{List of Abbreviations} \printglossary[type=abbreviations] \cleardoublepage \phantomsection % allows hyperref to link to the correct page % L I S T O F S Y M B O L S % --------------------------- \printglossary[type=symbols] \cleardoublepage \phantomsection % allows hyperref to link to the correct page \end{comment} % Change page numbering back to Arabic numerals \pagenumbering{arabic}