75

Use Of Aliases In Tabular Expressions

  • Upload
    amadon

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

USE OF ALIASES IN TABULAR

EXPRESSIONS

By

JUNHUA HU� M�ENG�

A ThesisSubmitted to the School of Graduate Studies

in partial ful�lment of the requirements for the degree of

Master of Engineering

McMaster University

c� Copyright by JUNHUA HU� September ��� ����

MASTER OF ENGINEERING ������ McMASTER UNIVERSITY

�Computer� Hamilton� Ontario� Canada

TITLE� Use of Aliases in Tabular Expressions

AUTHOR� Junhua Hu

BEng �Beijing University of Posts and

Telecommunications� China�

MEng �Academia Sinica� China�

SUPERVISOR� Dr David L Parnas

NUMBER OF PAGES� x� �

i

MASTER OF ENGINEERING ������ McMASTER UNIVERSITY

�Computer� Hamilton� Ontario� Canada

TITLE� Use of Aliases in Tabular Expressions

AUTHOR� Junhua Hu

BEng �Beijing University of Posts and

Telecommunications� China�

MEng �Academia Sinica� China�

SUPERVISOR� Dr David L Parnas

NUMBER OF PAGES� x� �

ii

Abstract

Experience has shown that tabular expressions �� can improve the readability of

document for conditional function and relation which frequently occur in software

documentation� but tabular expressions may still be long and hard to read when the

same substructure of a complicated data structure appears in several places in tabular

expressions Parnas proposed the use of aliases to reduce the complexity of tabular

expressions An alias is a short identi�er that designates a substructure or a set of

substructures Once an alias is de�ned� the short identi�er can be used in tabular

expressions This thesis presents how to de�ne aliases and how to use aliases in tabular

expressions This thesis also shows that the use of aliases can improve the readability

of tabular expression Tabular expressions containing aliases can be evaluated using

the Alias Table Tool and the Code Generator �� � ��� The Alias Table Tool� which

works as a preprocessor of the Code Generator� has been developed

iii

Acknowledgements

I would like to express my sincere thanks to Dr David Parnas for his guidance

and assistance throughout my thesis work He proposed the use of aliases to

reduce the complexity of tabular expressions Without his consistent support and

encouragement� it would have been impossible for me to �nish this work

I am grateful to Dr Ryszard Janicki and Dr Emil Sekerinski� for their valu�

able suggestions and comments I would also like to thank all the members of the

Software Engineering Research Group� especially Dennis Peters and Ruth Abraham

for their patient explanation of their thesis works

Special thanks to my wife� Huizhu and my family� for their love� support and

encouragement

Finally� I would like to thank the Communications and Information Technol�

ogy Ontario �CITO�� Natural Sciences and Engineering Research Council �NSERC�

and Bell Canada for their �nancial support

iv

Contents

Abstract iii

Acknowledgements iv

� Introduction �

�� Background �

�� Motivation for This Thesis �

�� Thesis Scope �

�� Alternative Abbreviation Methods �

��� Macros �

��� Auxiliary Functions �

��� Why Aliases are Di�erent from Macros and Auxiliary Functions �

�� Outline of This Thesis �

� Notation and Terminology �

�� Predicate Logic

��� Relations� Functions� Predicates and Characteristic Predicates

��� Function Applications and Terms �

��� Primitive Relation and Predicate Expression �

�� Tabular Expressions �

��� Syntax of Tables �

��� Semantics of Tables �

�� Table Tool System ��

��� Kernel ��

v

��� Infrastructure ��

��� Applications ��

��� Code Generator ��

� Alias De�nition and Use of Aliases ��

�� Alias De�nition ��

��� De�nition of a Primary Alias ��

��� De�nition of a Secondary Alias ��

�� Use of Aliases ��

��� Quote ��

��� Syntax Rules for Using Aliases ��

��� Semantic Steps in Interpreting Aliases ��

��� Why We Need Quotes� ��

�� Examples �

��� Example � �

��� Example � ��

� Alias Table Tool Design ��

�� Requirements�Informal� ��

��� Value File Format ��

��� User Interface ��

��� Anticipated Changes ��

�� Module Decomposition ��

��� Module Uses Relation ��

��� Program Uses Relation �

��� Alias De�nition �AT adc� ��

��� Alias Usage �AT auc� ��

��� User Interface �AT UIc� ��

�� Data Structure �AT dsc� ��

��� Value �AT valuec� ��

��� Evaluation �AT evaluatec� ��

��� Variable Set �AT varc� ��

���� Alias Set �AT aliasc� ��

vi

���� Alias Evaluation �AT aec� ��

���� Quote Evaluation �AT qec� ��

���� C Function �CFunc� ��

���� IdList �idlistc� ��

���� IdTab �IdTabc� ��

��� Sub�expression Substitution �AT subc� ��

���� Symbol Table Utility �AT stuc� ��

���� Status Reporting Module �AT errorc� ��

�� Algorithms ��

��� Algorithm Overview ��

��� Algorithm for Evaluating a Primary Alias ��

��� Algorithm for Evaluating a Secondary Alias ��

� Results and Conclusions ��

�� Results �

�� Limitation and Future Work ��

��� Performance ��

��� Structures Use Links ��

��� De�ne an Alias as an Ordered Set ��

��� Non�deterministic Aliases ��

��� Future Work �

�� Conclusions �

vii

List of Figures

�� Traditional De�nition of function f�x� y� �

�� Using a Tabular Expression to De�ne f�x� y� �

�� valve function ��

�� Input and Output Relation ��

�� Expression �� � �� Represented in TTS ��

�� Expression �� � �� Represented by Symbol Names ��

�� Syntax of Input Expressions to the Code Generator �

�� Membership is De�ned by a Predicate Table ��

�� A Normal Table Containing Quotes ��

�� A Vector Table Containing Quotes ��

�� The Quote Evaluation Result ��

�� Function GetAge is De�ned Without Using Aliases �

� Using Aliases to De�ne Function GetAge ��

�� Using Aliases to De�ne PointFunc ��

�� The Table After Aliases are Replaced ��

�� Using Aliases to De�ne PointFunc ��

�� Requirement of Alias table Tool ��

�� Dialogue Box for the Alias Table Tool ��

�� First Level Decomposition Module Uses Relation ��

�� Convert a Primary Alias De�nition Expression ��

�� De�nition of Function f �

viii

List of Tables

�� Di�erence among a Macro� an Auxiliary Function and an Alias �

�� Module Uses Relation ��

�� Access Programs of the Alias Table Tool ��

�� Program Uses Relation ��

�� Access Program of Alias De�nition Module ��

�� Access Program of Alias Usage Module ��

� Access Program of User Interface Module ��

�� Access Program of Data Structure Module ��

�� Access Program of Value Module ��

�� Access Program of Evaluation Module ��

��� Access Program of Variable Set Module ��

��� Access Program of Alias Set Module ��

��� Access Program of Alias Evaluation Module ��

��� Access Program of Quote Evaluation Module ��

��� Access Program of C Function Module ��

��� Access Program of IdList Module �

�� Access Program of IdTab Module ��

��� Access Program of Sub�expression Substitution Module ��

��� Access Program of Symbol Table Utility Module ��

��� Access Program of Status Reporting Module ��

��� Access Program of AT Error Token ��

ix

List of Acronyms

ATT Alias Table Tool

CM Context Manager

IDP Inductively De�ned Predicate

TCT Table Construction Tool

TIF Tool Integration Framework

TTS Table Tool System

TPT Table Printing Tool

x

Chapter �

Introduction

��� Background

Computer based systems are playing an increasingly important role in our society

These systems control rockets� nuclear reactors� automobile manufacturing plants

and banking systems Failures in these critical systems may result in heavy loss

of human life and�or �nancial resources Many of these failures may result from

software failures

The correct behavior of software is becoming increasingly critical to the safety

and well�being of people and businesses Therefore� there is an increasing need

for the application of engineering discipline to software development Documen�

tation plays an essential role in engineering Software documentation also plays a

crucial role in the whole life cycle of software� from requirements analysis� design�

implementation� veri�cation� testing� through to maintenance Informal documen�

tation �eg documentation written in natural language� often leads to imprecision

and misunderstanding Formal documentation �eg documentation presented in

mathematics� can eliminate imprecision� moreover formal speci�cation makes it

possible to automate checking of software speci�cation and automate software testing

The McMaster University Software Engineering Research Group �SERG� is

studying the documentation methods for computer systems engineering Mathe�

� Introduction �

f�x� y�df�

���������������

� if x � � � y � ��x if x � � � y � ��y� if x � � � y � ���y� if x � � � y � ��x� y if x � � � y � ��x� y if x � � � y � ��

Figure ��� Traditional De�nition of function f�x� y�

matical functions and relations �� are used to describe program behavior in SERG

Traditional mathematical representations denoting these functions and relations

are often complex and easily misunderstood because of the discontinuity of real

programs The example in Figure �� shows this discontinuity of function f�x� y�

In �� � Parnas de�ned tabular expressions� that evolved from earlier work at the Naval

Research Laboratory in Washington� DC �� Tabular expressions are equivalent

to expressions presented in a more conventional form� but often easier for human

readers to interpret Tabular expressions are particularly suited to describing the

relations with discontinuity that frequently occur in software documentation The

above function� f�x� y�� can be represented by the following table

f�x� y�df� H�

y � �� y � �� y � ��

x � � � y� �y�x � � x x � y x� y

H� G

Figure ��� Using a Tabular Expression to De�ne f�x� y�

��� Motivation for This Thesis

Use of tabular expressions can greatly improve the readability of software speci�ca�

tion� but tabular expressions may still be long and hard to read when a part of a

complicated data structure is referred to An array is an example of a complicated

� Introduction �

data structure A part of a complicated data structure is called a substructure Long

expressions are needed to specify some substructures The second largest element

in an array is an example of such a substructure� the smallest element from three

arrays is another example Sometimes the same substructure may appear in several

places in a tabular expression and consequently the whole tabular expression could

be quite long

Parnas proposed the use of aliases to reduce the complexity of expressions

An alias is a short identi�er that is used in tabular expressions The alias represents

a set of substructures The alias in the tabular expressions can be interpreted by

replacing the alias with the substructures that the alias stands for Using aliases can

improve the readability of tabular expressions in four ways

� First� understanding the de�nition of an alias is separated from understanding

the meaning of the whole table

� Second� the whole data structure� for example an array� can be partitioned into

several sets of substructures and each set of substructures is identi�ed by an

alias� so that the structures can be understood a little bit at a time

� Third� if the substructure appears in more than one place in the tabular ex�

pression� once the substructure is de�ned as an alias� the short identi�er is used

instead of the substructure which may need a long expression to describe itself�

so the tabular expression becomes much shorter and alias de�nition need to be

studied once

� Fourth� a meaningful identi�er of an alias may help readers to understand the

signi�cance of the substructure that the alias stands for

��� Thesis Scope

The objective of this thesis is to demonstrate how the use of aliases can improve the

readability of tabular expression used in computer system descriptions This thesis

presents the syntax and semantics of expressions to de�ne aliases� it also presents

the syntactic and semantic rules for using aliases in tabular expressions Finally� it

� Introduction �

describes a prototype tool� Alias Table Tool �ATT� that allows table with aliases to

be evaluated

The Alias Table Tool works as a preprocessor of the Code Generator Tool

Given some expressions� the Code Generator can produce C�� code and execution

of this C�� code can evaluate these expressions The Alias Table Tool uses the

Code Generator to evaluate aliases based on their de�nitions and assignments to

the variables contained in the alias de�nition expressions� then the Alias Table Tool

replaces aliases contained in the tabular expressions with the evaluation results The

resulting expressions can be evaluated by the Code Generator without changing their

meaning for the same assignments

��� Alternative Abbreviation Methods

����� Macros

Using macros can make a mathematical expression shorter When several long sub�

expressions in an expression are identical� these sub�expressions can be represented

by a macro� a short identi�er For example� the sub�expression �sin�x�� � � �px� �

ln�x���� appears twice in d�sin�x�����px��ln�x����

dx�R y��sin�x��� �

�px� � ln�x����dx

If a macro� m� is de�ned as mdf� �sin�x�� � �

�px� � ln�x � ���� the whole expression

will be dmdx

�R y�m dx To evaluate an expression containing macros� every macro in

the expression is substituted by the sub�expression that the macro represents before

the whole expression is evaluated Macro substitution does not depend on the values

of the variables

����� Auxiliary Functions

Using auxiliary functions can also make mathematical expressions shorter When

there are some similar sub�expressions in a mathematical expression� these similar

sub�expressions may be replaced by applications of auxiliary function� respectively

For example� an expression a���a�b��ab���b� � �c�������c�����d������c�

�A function application is a string consisting of a function name and arguments�

� Introduction �

���d�������d���� can be represented by af�a� b� � af�c � �� d � �� if an auxiliary

function� af� is de�ned as� af�x� y�df� x���x�y��xy���y� In general� the de�nition

of an auxiliary function re�ects the similarity among these similar sub�expressions�

and the arguments of the auxiliary function applications re�ect dissimilarities among

the sub�expressions Auxiliary function applications need to be evaluated whenever

the expression containing them is evaluated The result of the evaluation is a value�

not the name of a substructure

����� Why Aliases are Di�erent from Macros and Auxiliary

Functions

An alias identi�es a set of substructures The de�nition of an alias states the criteria

to select substructures For example� an integer array A whose size is � contains �ve

substructures� A�� � A�� � A�� � A�� and A�� Alias B can be de�ned as the largest

substructure�s� in the array A If A is f�� �� � �� ��g� alias B will be evaluated as

fA�� g� If A is f�� �� �� �� �g� alias B will be evaluated as fA�� � A�� g The Table

�� shows the di�erence among a macro� an auxiliary function and an alias

Table �� � Di�erence among a Macro� an Auxiliary Function and an Alias

A macro An auxiliary function An alias

represents a string a value a set of substructures

depends on variable values no yes yes

��� Outline of This Thesis

Chapter � de�nes the terminology that is used in this thesis Chapter � describes the

de�nition of aliases and shows how to use aliases in tabular expressions Chapter �

discusses the design of the Alias Table Tool Chapter � discusses the limitations of

this work and proposes some future work

�Alias B is not evaluated as ��� which is the value of A����

Chapter �

Notation and Terminology

This chapter explains the notation and terminology used in this thesis The �rst

section of this chapter gives the de�nition of predicate logic� the second section de�

scribes the syntax and semantics of tabular expressions� and the last section provides

an introduction to the Table Tool System

��� Predicate Logic

The predicate logic used in this thesis is based on that is described in �� The

following terminology is adopted from ��

����� Relations� Functions� Predicates and Characteristic

Predicates

A relation is a set of tuples A binary relation R is a set of ordered pairs

The domain of binary relation� denoted as Dom�R�� is the set of values that

appears as the �rst element of R The range of binary relation R� denoted as

Ran�R�� is the set of values that appears as the second element of R A member

of the binary relation R can be denoted as �x� y�� where x � Dom�R� and y � Ran�R�

A function is a binary relation with the following property� for each element

x in the domain� there is only one pair �x� y� in the function

� Notation and Terminology �

A predicate is a function whose range contains no members other than true

and false

For any set of simple tuples�refer to �� for the de�nition of simple tuple�� the

characteristic predicate of that set is a predicate whose domain is S� and whose value

for a simple tuple b� is true if and only if b is a member of X

����� Function Applications and Terms

A function application is a string consisting of a function name and arguments The

arguments are terms For example� in f�x� y�� f is a function name� and x and y are

arguments

A term is a constant� variable or function application

����� Primitive Relation and Predicate Expression

Primitive relations include a small set of relations� such as �� � and �

All primitive expressions are Predicate expressions If P and Q are predicate expres�

sions and x is the index variable� then ��x� P�� �P � Q�� �P � Q�� and �P� are also

predicate expressions

The predicate expressions �� P� � Q� and ���x�P�� can be written in their equiv�

alent format�

�� P� � Q� �P � Q�

���x� P�� ��x� P�

��� Tabular Expressions

In �� � Dr Parnas describes a notation for representing relations and functions us�

ing multi�dimension tables called tabular expressions These are no more expressive

than expressions written in traditional manner� but they are much more suitable

� Notation and Terminology

for describing conditional relations and functions� which frequently occur in program

description

����� Syntax of Tables

Tabular expressions are constructed recursively from scalar expressions �which are

either terms or predicate expressions� and grids Tables are described as a collection

of sets of cells classi�ed into main grid and headers as follows

� A header H is an indexed set of cells� H � fhi j i � I g� where the index set of

H is I � f�� �� � ng

� A main grid G is an indexed set of cells� G � fg� j � � I g G is indexed by

headers H�� � Hn� with Hj � fhji ji � Ijg where j � �� � n and I � I� In The set I is the index of G

� A raw element is a tuple e� ��h�i� � � hnin� g� � where ij � Ij� j � �� � n� �

� i�� ���� in� � I

A table that is interpreted as a function is called a function table A table that is

interprted as a predicate is called a predicate table A function table is also a term

A predicate table is also considered as predicate expressions A table can be nested

in other tables

����� Semantics of Tables

In �� � Parnas describes the syntax and semantics of tabular expressions Janicki in ��

presents many table classes that have not been previously considered Based on this

work� Abraham in �� presents a formal model that can de�ne tabular expressions

She de�nes a tabular expression T as a tuple�

T � �H�� � Hn� G� ������ pT� rT �

where�

� Table components� fH�� � Hn� Gg

� A cell connection graph� �� is a relation represented by an acyclic directed

graph with the main grid and all of the headers as nodes Every arc must start

� Notation and Terminology �

or end at the main grid It characterizes information �ow among the cells and

is used for interpretation of tabular expressions There are four cell connection

graph classes� �Normal� Inverted� Vector and Decision �� �

� A table component C � fH�� � Hn� Gg is called maximal if �� D� D �fH�� � Hn� Gg � �C � D�

� A table component C � fH�� � Hn� Gg is called minimal if �� D� D �fH�� � Hn� Gg � �D � C�

� If a table component is minimal or non�maximal means that its cell ex�

pressions restrict the domain of a relation or function� R� speci�ed by the

table The cells from these components are called guard cells and these

components are called guard grids�

� If a table component is maximal means that its cell expressions contain

relation or function de�nition The cells from these components are called

value cells and these components are called value grids If a value grid is a

header� it also called a value header The value header in a vector table is

called a vector header A vector table must have exactly one vector header

� A table predicate rule� pT� is the predicate expression containing guard grids

This rule determines the domain of the tabular expression

� A table relation rule� rT� is the predicate expression containing value grids

This rule determines the value of the tabular expression

� A mapping� �� is responsible for assigning a predicate expression� or a part of

it� to the guard cells� or assigning a relation expression� or a part of it� to the

value cells

� A compose operation� � The tabular expression T is interpreted as a relation�

RT � that can be de�ned from the relation speci�ed by the table�s raw elements�

fR�j� � I g� which can be described as RT � ���I

R�

The advantage of using tabular expression to specify a complex relation is that the

relation can be composed into R�� where � � I The cell connection graph decomposes

� Notation and Terminology �

valve�temperature� pressure� � H�

open close

temperature � ��� pressure � ���� pressure� ����temperature � ��� � temperature � ��� pressure � ���� pressure � ����

temperature � ��� pressure � ���� pressure � ����

H� G

Figure ��� valve function

the raw table elements into guards and values

For the above table� the table class� table component� guard grid� value grid� predi�

cate rule and relation rule are given as follows�

� Table class is Inverted

� H�� H� and G are table components

� Guard grid is H� and G

� Value grid is H�

� pT� H� � G

� rT� H�

There are six R�s for the relation de�ned by the above table For example� R��� is

de�ned by the raw element e��� in Figure �� The interpretation of e��� is given as

follows�

�temperature����� � �pressure������ � � valve�temperature� pressure� � open�

To interpret the whole table� all the sub�relation R�s have to be combined using a

compose operator� � For Inverted table� the compose operator is � The above tableis interpreted as follows�

RT � R��� �R��� �R��� � R��� � R��� �R���

� Notation and Terminology ��

h��open

�temperature � ��� � pressure � ����

h�� g���

Figure ��� Input and Output Relation

��� Table Tool System

The Table Tool System �TTS� is a major e�ort by the Software Engineering

Research Group at McMaster University One of the objectives of the TTS is to

support the production of software documentation through an integrated set of

tools which manipulate multi�dimensional tabular expressions The manipulation

includes entering� formatting and transforming tabular expressions The TTS also

aims to automate checking of software speci�cation and design documents� and to

provide aid during software testing and maintenance The TTS Developer�s Guide

��� describes the TTS in reasonable detail Since this thesis makes reference to TTS

de�nitions� it is necessary to explain the de�nitions �rst

The TTS is decomposed into three tiers They are kernel� infrastructure and

applications The following description is based on ���

����� Kernel

The kernel module hides data structure representing expressions� and algorithms for

manipulating them A list of de�nitions of terms used with these modules is given

as follows

Expn

An Expn is a data object that represents a mathematical expression An expression

can be viewed as a pre�x expression tree� where the nodes of the tree are symbols

Symbols in an expression are identi�ed by their ids For example� a simple application

� Notation and Terminology ��

�� � �� can be represented as follows if the id of ��� is �� id of ��� is ��� and

id of ��� is ��� Expressions are grouped into three categories� atom �constants or

variables�� application �use of functions or predicates with one or more arguments��

and tables

���

����

������

Figure ��� Expression �� � �� Represented in TTS

Index

An index is a data object that identi�es a cell within a table by its grid and position

within that grid�eg row� column�

Path

A Path is a data object that identi�es the location of one sub�expression of an

expression It consists of a sequence of objects� each of which is either an integer

or an Index A Path can be interpreted as a route map for �nding a speci�c sub�

expression� starting from the �root� of an expression An integer indicates a �branch� of

an application �ie argument sub�expression�� and an Index indicates a cell of a table

SymTbl

A SymTbl is a data object that represents a symbol table� which describes a

collection of symbols An id is used to associate a symbol and a node of the Expn

data object The information about a symbol is organised into a set of information

classes An information class is referred to by its name Some classes are shown

below

� The Name of a symbol is a string For example ���� �x� Names do not

necessarily distinguish symbols Since an expression represented in symbol ids

is not easy to understand� symbol names will be used instead of their ids to

represent the expression in this thesis For example� the expression �� � �� can

be shown as follows

� Notation and Terminology ��

���

��

���

Figure ��� Expression �� � �� Represented by Symbol Names

� Tag class is an integer It indicates if a symbol is a constant�ConsTag�� a predi�

cate constant�PConstTag�� a variable�VarTag�� a function application�FATag��

a logical expression�LETag�� a quanti�ed logical expression�QLETag�� a pred�

icate expression�PETag�� a function table�FTableTag� or a predicate ta�

ble�PdTableTag�

� Arity class contains an integer describing the arity of a function symbol

� CType class contains a string describing the C data type for a variable symbol

����� Infrastructure

The modules in the TTS infrastructure provide facilities to develop TTS applications

The basic concept in building an infrastructure is called a �context�

A context is an ordered set of named expressions together with a symbol ta�

ble Since all of the expressions use the same symbol table� ids will have consistent

interpretation within the context� which simpli�es manipulation and interpretation

of expressions A context can be saved to a �le or loaded from a �le CHandle is the

data type representing a context

The infrastructure contains three modules� Tools� Utilities and Tool Integration Tool

� A tool provides some primitive services that operate on TTS objects� such as

Expn and SymTbl For example� Table Construction Tool �TCT� edits and

constructs expressions� Table Printing Tool �TPT� prints and displays expres�

sions� Context Manager �CM� manipulates expressions in a context� and Code

Generator generates evaluation code for expressions Code Generator will be

� Notation and Terminology ��

discussed in detail in section ��� because the Alias Table Tool makes extensive

use of the Code Generator

� A utility provides a facility that may be used by more than one tool or appli�

cation The implementation of this thesis uses some utility modules

� The Tool Integration Framework makes it easy to integrate new tools and appli�

cations to the TTS The Tool Integration Framework can provide a menu item� for each tool or application The Tool Integration Framework also provides a

mechanism for passing TTS objects between tools or applications For example�

an expression constructed by the Table Construction Tool can be passed to the

Table Printing Tool

����� Applications

This layer contains programs that combine infrastructure modules to manipulate or

interpret groups of tabular expressions as documents� which describe some aspect of

a computer system The Test Oracle Generator ��� is the only available application

right now

����� Code Generator

The Code Generator evolved from Test Oracle Generator The Code Generator

generates code to evaluate tabular expressions The Code Generator takes a context

and C header �le as its input� and produces C�� �le and C�� header �le as its

output The input C header �le contains data structure de�nitions

The Code Generator translates scalar �ie non�tabular� expressions into equivalent

C statements The information needed to translate a function application is stored in

the function symbol�s CForm class Some basic function symbols� such as � and ��can be directly translated to their corresponding operators in the C language The

Code Generator also allows users to store the name and call format of a C function

in the CForm class of a function symbol� and the Code Generator generates the code

�A menu item is an ordinary textual component available on a menu� When a menu item isclicked by a mouse� a user de�ned program is invoked�

� Notation and Terminology ��

to call this C function

Tabular expressions are implemented by instantiating an object of one of four

C�� classes� which implements the four table classes� Normal� Inverted� Vector and

Decision The C�� classes encapsulate all knowledge of the table semantics

Some characteristics of the Code Generator are given as follows These char�

acteristics were taken into consideration when designing the Alias Table Tool

� For the Code Generator� quanti�cation is restricted to a �nite set� which is

characterized by an inductively de�ned predicate The Code Generator only

allows the quanti�cation expressions in the following forms�

Universal� ��x� IDP�x� � Q�x��

Existential� ��x� IDP�x� � Q�x��

where IDP�x� is an inductively de�ned predicate and Q�x� is any predicate

expression

An inductively de�ned predicate �IDP�� P� on �type� is de�ned as the

characteristic predicate of a set� S� in the following way Given a triple� I� G�

Q� where�

I is an enumerated �nite set of elements of � type ��

G is a function� G� � type ��� type ��

Q is a predicate on � type �

S is the least set formed by the following rules�

� all elements of I are in S

� �� x� x � S � �Q�x� � G�x� � S �

For example� IDP�df� � f�g� G�i� � i � �� x � �N � �� � de�nes the set f�� ��

� N � �g

The only type of inductively de�ned predicate that the Code Generator

supports is integer

� Notation and Terminology ��

� There are some restrictions on the syntax of expressions in the context supplied

to the Code Generatorde�ned���

function

���

function de�nition��

���

�st argument nth argument

Figure ��� Syntax of Input Expressions to the Code Generator

� The root symbol of every expression must be �de�ned�

� The left branch of the root must be a function with n arguments� where n

� �

� The right branch of the root is a function de�nition� but every variable in

the expression except index variables must be one of the arguments of the

function speci�ed by the left branch of the root

� The Code Generator can not generate code to evaluate set theoretic expressions

For example� the Code Generator can not produce code to evaluate A � B or

A � B

Chapter �

Alias De�nition and Use of Aliases

This chapter describes how to de�ne aliases and how to use aliases in tabular ex�

pressions The �rst section of this chapter gives de�nitions of a primary alias and a

secondary alias The second section explains the syntactic rules for using aliases in

tabular expressions and semantic steps in interpreting aliases in tabular expressions

The third section of this chapter gives two examples to show that use of aliases can

improve the readability of tabular expressions

��� Alias De�nition

����� De�nition of a Primary Alias

Aliases are classi�ed into primary aliases and secondary aliases based on how they

are de�ned A primary alias is de�ned by a ��tuple �T� D� M�� a secondary alias is

de�ned by a ��tuple �D� M�� which is discussed in Section ��� The T� D and M

of the ��tuple are described as follows

T�emplate� is an expression that describes the general form of the element in

the set described by the ��tuple For example� Tdf� A�i� �i� �in

D�omain� is a set of n�tuples from which indices of an element in the set de�

scribed by the ��tuple are chosen The domain can be de�ned by any mathematical

notation However� the Code Generator which is used in the Alias Table Tool only

��

� Alias De�nition and Use of Aliases �

supports sets de�ned by IDPs� so with the current implementation the general form

of domain is restricted to IDP��i�� � IDP��i�� � � IDPn�in�� where IDPj �j � ��

�� � n� is an inductively de�ned predicate and ij �j � �� �� � n� is an index in T

Domain means � i�� i�� ���� in � � S� S� Sn if for all j �j � �� �� � n� the

set Sj is the set de�ned by IDPj

M�embership Predicate� describes the criterion used to judge which element in

the domain belongs to an element in the set described by the ��tuple It must be a

predicate expression

For example� AliasXdf��T� D� M�� where

Tdf� A�i

Ddf� IDP��i�� where IDP�

df�� f�g� G�i� � i � �� x � �N � ���

Mdf� A�i � threshold

In the above example� the ��tuple de�nes a set as follows�

f A�i j IDP��i� � �A�i � threshold� g

A ��tuple can de�ne any substructure of an array IDP� in the following ex�

amples is de�ned as IDP�df� � f�g� G�i� � i � �� x � �N � �� �

� The maximum element of the array A

Maxdf�� A�i � IDP��i�� ��j� IDP��j�� �A�i � A�j � ��

� The �rst element in the array B whose value is �

FirstFivedf�� B�i � IDP��i�� �B�i �������j� IDP��j���j � i���B�j ����� �

� fA�� � A�� gOneAndThree

df�� A�i � IDP��i�� �i � �� � �i � �� �

The membership predicate can be a predicate tabular expression For example� the

membership predicate of the alias� best� is de�ned by a one�dimensional normal table

as shown in �gure �� BiggerIsBetter is a variable

� Alias De�nition and Use of Aliases ��

bestdf��T� D� M�� where

Tdf� A�i

Ddf� IDP��i�� where IDP�

df�� f�g� G�i� � i � �� x � �N � �� �

Mdf� H�

BiggerIsBetter BiggerIsBetter��j� IDP��j�� �A�i � A�j �� ��j� IDP��j�� �A�i � A�j ��

G

Figure ��� Membership is De�ned by a Predicate Table

The big limitation of the ��tuple de�ned above is that it can not represent elements

from more than one data structure� for example� the largest element in array A and

B A ��tuple� as described below� can be used to de�ne this kind of alias

����� De�nition of a Secondary Alias

A secondary alias can be de�ned using one or more previously de�ned aliases A

previously de�ned alias can be either a primary alias or secondary alias In general�

a secondary alias can be de�ned by a ��tuple �D� M�

D�omain� is a set and the elements of the set described by the ��tuple are

chosen from this domain Domain is a set operation expression The operators are

union ���� intersection ��� and di�erence ��� The operands are previously de�ned

aliases The syntax used to de�ne �D� is

D � expn� � expn� j expn� � expn� j expn�� expn�

expn�� �� alias� j alias� � alias� j alias� � alias� j alias�� alias�

M�embership Predicate� describes the criterion to judge which element in the

domain belongs to the set described by the ��tuple M must be a predicate expression

Here is an example that de�nes the largest element that can be found in ei�

ther array A or array B

AllAdf�� A�i � IDPA�i�� true �

� Alias De�nition and Use of Aliases �

AllBdf�� B�i � IDPB�i�� true �

MAXAandBdf�� AllA � AllB� ��x� �x � AllA � AllB� � �MAXAandB � x�� �

Two primary aliases� AllA and AllB are de�ned �rst� and then the secondary alias

MAXAandB is de�ned Actually� we could not refer to that element if we do not use

a secondary alias

Secondary aliases are de�ned using previously de�ned aliases This usage can

be described using a directed graph An edge from aliasA to aliasB means the

de�nition of aliasA uses the de�nition of aliasB There should be no loops in the

graph If there are loops� a circular de�nition exists Circular de�nitions are not

allowed The Alias Table Tool will detect a circular de�nition and give users a

message whenever a circular de�nition exists

��� Use of Aliases

This section shows how to use aliases in tabular expressions A term� �quote�� which

is closely related to the use of aliases� is explained �rst

����� Quote

The quote is a function with arity one It can have any expression as its argu�

ment A quoting expression is a function application with quote as the function

name For example� quote� x � � � is a quoting expression A quoted expression

is an expression that is the parameter of a quote function For example� � x �

� � in quote� x � � � is a quoted expression A quoting expression is also called a quote

The purpose of using the quote function is to delay evaluation of the quoted

expression Some expressions can not be evaluated or evaluated correctly unless

conditions are satis�ed See Section ��� for the reasons of why we need quotes

Use of quotes can ensure �lazy� evaluation The process of evaluating an expression

E containing quotes based on the assignments to the variables in E and getting the

result expression without quotes is called quote evaluation

� Alias De�nition and Use of Aliases ��

Three assumptions about the syntax of quoting expressions are made for this

thesis These assumptions make quote evaluation easy but limit the use of aliases

� First� a quoting expression is only allowed to appear in the value grid of a

tabular expression and is not allowed in the vector header

� Second� a quoting expression must be the root expression of a table cell if the

quoting expression appears in the table For example� quote� x � � � can be a

cell expression� y � quote�x � �� can not be a cell expression

� Third� a quoting expression must not contain other quoting expressions For

example� quote� x � quote� y � ��� is not allowed

The quote evaluation result of a normal table� an inverted table or a decision table

can be obtained by the following steps

� Evaluate guard grids of the table� the guard cells evaluated as true determine one

value cell

� If the value cell chosen in step � is not a quoting expression� the result is the

expression in that cell� otherwise the result is the quoted expression of the cell

For example� in Figure ��� a normal table contains quoted expressions in its value

grid If x is � and y is �� quote evaluation result of the table is expn� If x is �� and

y is �� the result is expn�

x � � x � �

y � � expn� quote�expn��y �� � quote�expn�� expn�

Figure ��� A Normal Table Containing Quotes

The quote evaluation result of a vector table is a column of the main grid selected by

the guard cells evaluated as true� and if any cell in the column is a quoting expression�

the cell is replaced by its corresponding quoted expression For example� The quote

evaluation result of the table in Figure �� is shown in Figure �� if y is �

� Alias De�nition and Use of Aliases ��

y � � y �� �

x� quote�y � a���� a���x� quote�y � a���� a���x� quote�y � a���� a���

Figure ��� A Vector Table Containing Quotes

true

x� alias � a���x� alias � a���x� alias � a���

Figure ��� The Quote Evaluation Result

The need of quotes will be explained in section ���

����� Syntax Rules for Using Aliases

A function �card�alias�� is to denote the cardinality of the set identi�ed by the alias

�Unique alias� is an alias that identi�es a set with one substructure in it The syntax

rules to use aliases in a tabular expression are�

� Function �card�alias�� can appear anywhere in the tabular expressions� including

normal tables� inverted tables� vector tables and decision tables

� A �unique alias� can appear anywhere in the tabular expressions� including nor�

mal tables� inverted tables� vector tables and decision tables

� An alias �including �unique alias�� can appear in the vector header of a vector

table No more than one alias can appear in one cell of a vector header If an

alias appears in the vector header of a vector table� the same alias can appear

on the same row in the main grid as it does in the vector header An alias that

is not unique can not appear elsewhere in a vector table or in the tables other

than vector tables except if it appears in an quoted expression

� Alias De�nition and Use of Aliases ��

����� Semantic Steps in Interpreting Aliases

The semantic steps in interpreting aliases in a tabular expression are�

� Step �� evaluate aliases �ie �nd all the elements in the set described by an

alias�

� Step �� replace �card�alias�� with the cardinality of the set identi�ed by �alias�

if �card�alias�� does not appear in a quoted expression

� Step �� replace any unique alias with the substructure in the set identi�ed by

the alias if alias does not in a quoted expression

� Step �� Execute quote evaluation if tables contain quotes and apply step � and

step � again if the two steps are applicable to the quote evaluation result

An example is given below to show how to use the steps �� � and �

The following normal table contains quoted expressions �maxX� is an alias

card�maxX� � � card�maxX� �� �

t � �� quote�maxX�y � t� error

t � �� quote�maxX�y � t� error

Suppose the alias maxX is f A�� g and t is � After step �� � and � are applied

to the tubular expression� the expression will be maxX�y � t� after step � is

applied again� the expression will be A�� � t

� Step �� interpret aliases in the vector header of vector tables based on the

following steps

� Step ��� if the cardinality of the set identi�ed by an alias in the vector

header is �� the row containing that alias will be deleted

� Step ��� if the cardinality of the set identi�ed by an alias in the vector

header is greater than �� say n� the row containing that alias will be

replaced by n rows and that the alias will be replaced by each element

of the set identi�ed by the alias for each row Any replacement order is

acceptable For example� suppose alias X � fA�� � A�� � � A�n g and a

� Alias De�nition and Use of Aliases ��

vector table containing alias X is shown as follows

condition condition

X X � � X � �

The vector table will be replaced by the following vector table

condition condition

A�� A�� � � A�� � �

A�� A�� � � A�� � �

A�n A�n � � A�n � �

The vector table can also be replaced by the following vector table

condition condition

A�n A�n � � A�n � �

A�n�� A�n�� � � A�n�� � �

A�� A�� � � A�� � �

� Step ��� if two aliases appear in the vector header� the two sets identi�ed

by the two aliases must be disjoint� that is they do not have common

substructures� otherwise an error occurs If an alias appears in the vector

header� any substructure in the vector header should not be an element of

the set identi�ed by the alias� otherwise an error occurs For example� a

vector table containing aliases is shown as follows

� Alias De�nition and Use of Aliases ��

condition condition

A��

aliasX

If aliasX designates fA�� � A�� g� there is an error because A�� appears

elsewhere in the vector header

����� Why We Need Quotes

When an alias is used in a normal table� an inverted table or a decision table� it must

designate exactly one substructure However in many cases� this is not guaranteed

For example� alias maxX designates the point with the largest X coordinate from an

array of points Normally the cardinality of the set identi�ed by maxX is one� but

the abnormal case must be handled as a part of program behavior if the abnormal

case might occur For example� the program returns an error when the cardinality

of the set identi�ed by maxX is not one We can solve the problem by using quotes

and adding predicates about the cardinality into the condition header An example

is given as follows The data structure of point is de�ned �rst

typedef struct point fint x�

int y�

gIDPA

df�� f�g� G�i� � i � �� i � �N � �� � maxX

df�� A�i � IDPA�i�� ��j� IDP��j� �

�A�i x � A�j y�� �

The signature of the function �int func�point A�N � int t�� is point�N int � int

The function is de�ned by a normal table

int func�point A�N � int t�df�

card�maxX� � � card�maxX� �� �

t � �� quote� maxXy � t � error

t � �� quote� maxXy � t � error

If the cardinality of the set identi�ed by maxX is not one� the syntax of this normal

table is not wrong because the maxX is in a quoted expression We do not try to

replace the maxX before we execute quote evaluation

� Alias De�nition and Use of Aliases ��

��� Examples

����� Example �

Example � is a function that returns the age of the student with the speci�ed stdID

int GetAge�student A�StdNum � int stdID��

The signature of GetAge is student�StdNum int � int

The data structure of student is de�ned as follows

struct student fint ID�

int age�

gGetAge is de�ned in Figure �� without using aliases Two macros� exist and existU�

nique� are used The table in Figure �� is an one�dimension normal function table

IDPAdf�� f�g� G�i� � i � �� i � �StdNum � �� �

existdf� ��i� IDPA�i� � �A�i � stdID��

existUniquedf� ��i� IDPA�i� � ��A�i � stdID� � ��j� IDPA�j� � �j �� i � A�j ��

stdID ����

GetAge�student A�StdNum � int stdID�df� H�

exist existUnique exist �� existUnique� �

errOne A�i age j IDPA�i� � �A�i ID � stdID� errTwo

G

Figure ��� Function GetAge is De�ned Without Using Aliases

� Alias De�nition and Use of Aliases ��

GetAge is de�ned again in Figure � An alias� thestudent� is de�ned as a primary

alias The table in Figure � is an one�dimension function normal table

IDPAdf�� f�g� G�i� � i � �� i � �StdNum � �� �

thestudentdf�� A�i � IDPA�i�� A�i ID � stdID �

GetAge�student A�StdNum � int stdID�df� H�

Card�thestudent� � � Card�thestudent� � � Card�thestudent� � �

errOne quote�thestudentage� errTwo

G

Figure �� Using Aliases to De�ne Function GetAge

This example shows how using aliases can make the speci�cation of GetAge shorter

Another reason to give this example is that the Code Generator can not evaluate

the speci�cation presented in Figure �� The Code Generator can not evaluate any

expression containing the symbol �j�� such that

� Alias De�nition and Use of Aliases �

����� Example �

Example � is a function� PointFunc�unsigned int t� int a� int b� int c� masspoint

A�p � Its signature is shown as follows

unsigned int int int int masspoint�p � boolean

The data structure of masspoint is de�ned as follows

typedef struct masspoint fint x�

int y�

�oat m�

gconst K�

Four aliases� AllA� OnPara� OnCircle� and Rest are used to de�ne PointFunc

as shown in Figure �� The table is a two�dimensional vector table The predicate

rule pT is H� and the relation rule rT is G

IDPAdf� � f�g� G�i� � i � �� i � �p � �� �

AllAdf� � A�i � IDPA�i�� true �

OnParadf� � A�i � IDPA�i�� A�i y � �A�i x�� �

OnCircledf� � A�i � IDPA�i�� �A�i x�

� � �A�i y�� � �� �

Restdf�� AllA � OnPara � OnCircle� true �

PointFunc�unsigned t� int a� int b� int c� masspoint A�p��df� H�

t � �� t � ��

OnPara OnParam � K�aOnParax � OnParay� OnParam � KaOnParax

OnCircle OnCirclem � K�bOnCirclex � OnCircley� OnCirclem � KbOnCircley

Rest �Restm � ��� � �Resty � c� �Restm � � � � �Restx � c�H� G

Figure ��� Using Aliases to De�ne PointFunc

� Alias De�nition and Use of Aliases ��

An example table is given below after the four aliases are replaced by the substruc�

tures that they represent Suppose p � �p can be very large� and A� � ff�� ����g� f�� �� ��g� f�� �� ��g� f�� �� �g� f�� �� ��g� f�� �� ��gg The evaluation

results of aliases are listed below�

AllA � fA�� � A�� � A�� � A�� � A�� � A�� gOnPara � fgOnCircle � fA�� � A�� gRest � fA�� � A�� � A�� � A�� gThe replacement result of function PointFunc is shown in Figure ��

PointFunc�unsigned int t� int a� int b� int c� masspoint A�p �df�

t � �� t � ��

A�� A�� m � K �b A�� x � A�� y� A�� m � K b A�� yA�� �A�� �m � ���� � �A�� �y � c� �A�� �m � ���� � �A�� �x � c�A�� �A�� �m � ���� � �A�� �y � c� �A�� �m � ���� � �A�� �x � c�A�� �A�� �m � ���� � �A�� �y � c� �A�� �m � ���� � �A�� �x � c�A�� �A�� �m � ���� � �A�� �y � c� �A�� �m � ���� � �A�� �x � c�A�� A�� m � K �b A�� x � A�� y� A�� m � K b A�� y

Figure ��� The Table After Aliases are Replaced

� Alias De�nition and Use of Aliases �

If we do not use aliases� PointFunc may be documented as shown in �gure �� The

table in Figure �� is a two�dimension vector table

IDPAdf� � f�g� G�i� � i � �� i � �p � �� �

PointFunc�unsigned int t� int a� int b� int c� masspoint A�p �df� H�

t � �� t � ��

A ��i� IDPA�i� � ����A�i �y ��A�i �x��� � �A�i �m � K � �a �A�i �x � A�i �y��� � ���A�i �x�� ��A�i �y�� � ��� � �A�i �m �K � �b � �A�i �x � A�i �y���� � ��A�i �y ���A�i �x�������A�i ����A�i �y�� �� ������A�i �m � ���� � �A�i �y � c�����

��i� IDPA�i� � ����A�i �y ��A�i �x���� �A�i �m � K�a�A�i �x������A�i �x�� � �A�i �y�� � ��� ��A�i �m � K � b � A�i �y�� � ��A�i �y ���A�i �x��� � ���A�i �� � �A�i �y�� ����� � ��A�i �m � ���� � �A�i �x �c�����

H� G

Figure ��� Using Aliases to De�ne PointFunc

This example shows that use of aliases can improve readability of tabular expressions

that contain complicated data structures

Chapter �

Alias Table Tool Design

The application tool developed for this thesis is called the Alias Table Tool This

chapter discusses the design of the Alias Table Tool The �rst section of this chap�

ter describes informal requirements� value �le format� user interface and anticipated

changes to the tool The second section describes the module decomposition and

access programs for each module The third section presents the algorithms used for

the Alias Table Tool

��� Requirements�Informal

The requirements of the Alias Table Tool are illustrated by the following �gure

The Alias Table Tool uses the initial context� a C header �le and a value �le� and

Context �

Alias Table Tool

Value File

� New ContextC Header File �

Figure ��� Requirement of Alias table Tool

��

� Alias Table Tool Design ��

produces a new equivalent � context without aliases The C header �le contains

the de�nitions of data structures The input context contains alias de�nitions and

tabular expressions containing aliases The value �le contains values for the variables

that appear in the alias de�nition expressions

While the initial context to the Alias Table Tool remains unchanged� there

may be more than one set of values for the variables After an alias is evaluated�

it must be evaluated again only if the values for the variables that appear in its

de�nition change

����� Value File Format

A collection of variable values is supplied to the Alias Table Tool by a text �le The

text �le contains several lines and each line contains a symbol id� a space character

and a string The symbol id is the id for a variable symbol The string is the value

of the variable identi�ed by the id Each variable symbol in the value �le must have

its C language data type� which is stored in the CType class in the symbol table of

the input context Suppose the C language data type of a variable symbol is ctype�

the string that represents the value of the variable is valuestring� and VariableName

is a valid identi�er in the C language Any statement of the form�

ctype VariableName � valuestring�

which can be successfully parsed by a C compiler� may be in the value �le

����� User Interface

The Tool Integration Framework �TIF� of TTS provides a menu item for the Alias

Table Tool Clicking the menu item invokes the Alias Table Tool The custom user

interface for this tool is a dialogue box as shown in Figure �� After the menu item

for this tool is clicked� the dialogue box will appear on the screen

�equivalent for the variable values speci�ed in the value �le�

� Alias Table Tool Design ��

Figure ��� Dialogue Box for the Alias Table Tool

A user of the Alias Table Tool can enter the name of the C header in the text �eld to

the right of the label �User Defn�s �le��� enter the name of the value �le in the text

�eld to the right of the label �Value�s �le��� and enter the �le name of the output

context in the text �eld to the right of the label �Context �le�� The �rst text �eld

can be empty if there are no user de�ned data structures The user can also click

the browser buttons to choose �le names from the directory instead of keying the �le

names The context as the input to the Alias Table Tool is the current context in

the TTS

After entering all the �le names� the user can click the �Start� button to run

the Alias Table Tool The user can also click the �Help� button to get a help message

about this dialogue box The text �eld in the bottom of the dialogue box displays

the status of execution of the tool �AT Success� means there is no error at all The

interpretation of other status codes is given in Table ��� Finally� the user can click

�Quit� to exit the tool

����� Anticipated Changes

It is expected that the following items are likely to change within the useful life of

the Alias Table Tool

� Syntax of alias de�nition

� Alias Table Tool Design ��

� Syntactic and semantic rules for using aliases in tabular expressions

� Value �le format

� User interface

��� Module Decomposition

To make the design easy to understand and change� the Alias Table Tool is decom�

posed into a set of modules using the �information hiding� principle ��

����� Module Uses Relation

Quote Evaluation

User Interface

Code Generator

Module A uses Module B

Module B

Module A

Evaluation

Data Structure Alias Usage

Value Alias Definition

Alias Evaluation

Figure ��� First Level Decomposition Module Uses Relation

� Alias Table Tool Design ��

Figure �� illustrates the Module Uses Relation �derived from the program uses re�

lation as described in � � Module A is said to use Module B if some programs in

Module A rely on the correct behavior of some programs in Module B to accomplish

their task Table �� gives the detailed Module Uses relation for all the modules

developed for the Alias Table Tool

Table �� � Module Uses Relation

Module Level Uses

User Interface � Evaluation

Value

Status Reporting

Evaluation � Alias Usage

Alias Evaluation

Quote Evaluation

Alias De�nition

Variable Set

Alias Set

IdTab

Symbol Table Utility

Status Reporting

Alias Usage � Alias Set

Subexpression Substitution

Symbol Table Utility

Status Reporting

Quote Evaluation � Alias Set

Value Set

Subexpression Substitution

Symbol Table Utility

IdTab

Status Reporting

� Alias Table Tool Design ��

Table �� � Module Uses Relation

Module Level Uses

Alias Evaluation � Alias De�nition

Alias Set

Value Set

C Function

Subexpression Substitution

Symbol Table Utility

IdTab

Status Reporting

Value � Value Set

Symbol Table Utility

Status Reporting

Alias De�nition � Symbol Table Utility

IdTab

Status Reporting

Alias Set � IdTab

Status Reporting

Value Set � IdTab

Status Reporting

Data Structure � Symbol Table Utility

Status Reporting

C Function � Status Reporting

Subexpression Substitution � Status Reporting

Symbol Table Utility � Status Reporting

IdTab � Status Reporting

����� Program Uses Relation

The program uses relation is used to illustrate the detailed design of the Alias Table

Tool in terms of the uses relation between access programs Program A is said to use

Program B is the correct behavior of Program A depends on the correct behavior of

Program B

� Alias Table Tool Design ��

The program uses relation of the Alias Table Tool is shown in Table �� Each program

of this tool is identi�ed by a program id Table �� gives the mapping between the

program ids and the program names

Table �� � Access Programs of the Alias Table Tool

Id Name Id Name

� AT adInit � AT adGetFirstAlias

� AT adGetNextAlias � AT adGetSymbolsInDef

AT adGetVarsInDef � AT adIsPrimaryAliasDef

� AT adIsSecondaryAlias � AT adGetTemplate

� AT adGetDomain �� AT adGetMembership

�� AT adClose �� AT auReplace

�� AT UIInit �� AT Main

� AT dsInit �� AT dsCheck

�� AT dsTypeIsDe�ned �� AT valueInit

�� AT valueGetValue �� AT evaluateInit

�� AT evaluateRun �� AT evaluateClose

�� AT varInit �� AT varCreate

� AT varDestroy �� AT varSetValue

�� AT varGetValue �� AT varGetAllVariables

�� AT aliasInit �� AT aliasCreate

�� AT aliasDestroy �� AT aliasRemoveElts

�� AT aliasAddElt �� AT aliasGetAliases

� AT aliasGetCardinality �� AT aliasGetElt

�� AT aeInit �� AT aeSetValues

�� AT aeGenerateCode �� AT aeExecCode

�� AT aeEvaluate �� AT aeClose

�� AT qeInit �� AT qeEvaluate

� AT qeGetFirstResult �� AT qeGetNextResult

�� AT qeClose �� CFunInit

�� CFunCreate � CFunDestroy

� CFunSetArgument � CFunGetArity

� CFunGetArgument � IdTabInit

� Alias Table Tool Design �

Table �� � Access Programs of the Alias Table Tool

Id Name Id Name

IdTabCreate � IdTabDestroy

� IdTabInsert � IdTabRemove

� IdTabGetSize �� IdTabGetAllIds

�� IdTabGet �� IdTabGetFirst

�� IdTabGetNext �� AT subReset

� AT subSetExpnToExpn �� AT subExec

�� AT stuGetAllVars �� AT stuGetType

�� AT stuGetName �� AT stuGetConst

�� AT stuAddVar �� AT stuAddFunction

�� AT stuAddIDP �� AT stuGetIDP

� AT stuSetIDP �� AT stuGetDisableIDP

�� AT stuAddOneDimPredNormalTbl �� AT errSet

�� AT stuGet �� AT errGetStr

Table �� � Program Uses Relation

Program Uses Programs Program Uses Programs

� � ��� ��� ��� ��� ��� ��� �� � ��

� �� � ��� ��

��� �� � ��� ��

� ��� �� � ��� ��

� ��� �� �� ��� ��

�� �� ��� ��� �� �� ��� � � ��� ��� � � ��� ��� ��� ��

�� �� �� ��� ��� ��� ��� ��� ��� ��� ��� ��

� �� �� ��

�� �� �� ��

�� ��� ��� ��� ��� �� �� �� �� �� �� � � � ��� ��� ��� ��� ���

��� ��� � �� �� ��� ��� ��� ���

��� ��

�� ��� � � ��� ��� ��� ��� ��� ��� � �

��� ��� ��� ��� ��� ��

�� � � ��� �� ��

� Alias Table Tool Design ��

Table �� � Program Uses Relation

Program Uses Programs Program Uses Programs

�� �� �� � ��

� �� ��� ��� �� �� �

�� ��� �� �� ��� ��� ��

�� �� �� � �� ��� ��� ��

�� ��� �� �� �� ��� ��

�� ��� ��� �� �� ��� ��� ��

� �� �� � � ��� ��

�� �� �� ��

�� � �� �� �� ��� �� � �� ��� ��� ���

� � ��� ��� ��� ��� ��

�� ��� ��� ��� ��

�� � �� �� �� ��� ��� ��� �� � �� ���

��� ��� ��� � � ��� ��� ��� ��� ��

�� �� �� ��

�� �� �� ��� � ��� ��

� ��� �� �� ��� ��

�� ��� ��� �� �� ��

�� �� � ��

� �� � ��

� �� � ��

�� � ��

� �� � ��

� �� �� ��

�� �� �� ��

�� �� �� ��

� �� �� ��

�� �� �� ��

�� �� �� ��

�� �� �� ��

�� �� �� ��

� �� �� ��

�� �� ��

�� ��

� Alias Table Tool Design �

����� Alias De�nition AT ad�c�

The secret of the module is the syntax and semantics of alias de�nitions It has

access programs for getting aliases from a context� for obtaining the symbols and the

variable symbols contained in an alias de�nition� for decomposing an alias de�nition

into template� domain and membership predicate expressions

Table �� � Access Program of Alias De�nition Module

Access Program Description

void AT adInit �CHandle context� Initialize the module and check syntax of all

the aliases de�ned in the context

Id AT adGetFirstAlias �� Return the id of the �rst alias de�ned in the

context set by the �rst access program Re�

turn �� if there is no alias in the context

Id AT adGetNextAlias�� Return the id of the next alias de�ned in the

context set by the �rst access program Re�

turn �� if there is no next alias in the context

IdList AT adGetSymbolsInDef�Id a� Return all the symbols in the de�nition of the

alias indicated by a

IdList AT adGetVarsInDef�Id a� Return all the variable symbols in the de�ni�

tion of the alias indicated by a

bool AT adIsPrimaryAliasDef�Id a� Return BOOL TRUE only if the alias indi�

cated by a is a primary alias

bool AT adIsSecondaryAliasDef�Id a� Return BOOL TRUE only if the alias indi�

cated by a is a secondary alias

Expn AT adGetTemplate�Id a� Return a copy of the template of the alias

indicated by a if it is a primary alias

Expn AT adGetDomain�Id a� Return a copy of the domain of the alias in�

dicated by a

Expn AT adGetMembership�Id a� Return a copy of the membership predicate

of the alias indicated by a

void AT adClose�� Free resources allocated for the module

� Alias Table Tool Design ��

����� Alias Usage AT au�c�

The secret of this module is the rule for using aliases in tabular expressions and for

replacing aliases with full identi�ers of the substructures that aliases designate The

module has an access program for replacing aliases in tabular expressions

Table �� � Access Program of Alias Usage Module

Access Program Description

void AT auReplace �SymTbl s�

AT AliSet a� Expn e� Path p�

Replace the aliases in the expression speci�

�ed by �e� p� with the alias evaluation result

speci�ed by a If any new symbols are needed�

they are added to s

����� User Interface AT UI�c�

The User Interface module hides the characteristics of Motif The two access programs

are required by the TIF

Table � � Access Program of User Interface Module

Access Program Description

bool AT UIinit�� Initial function call to set up the Alias Table

Tool

void AT Main�PHandle toplevel� The event handler if the menu item for the

Alias Table Tool is clicked

���� Data Structure AT ds�c�

In this prototype tool� the data structures are de�ned in a C header �le The module

hides the algorithm for checking the syntax of data structures de�ned in a C header

�le� and for answering if the de�nition of a data structure is given in the C header

�le

Table �� � Access Program of Data Structure Module

Access Program Description

void AT dsInit�char dsdef� Set a C header �le name

� Alias Table Tool Design ��

Table �� � Access Program of Data Structure Module

Access Program Description

bool AT dsCheck �� Return BOOL TRUE if the syntax of the C

header �le is correct

bool AT dsTypeIsDe�ned�char type�

name�

Return BOOL TRUE if the data type indi�

cated by typename is de�ned in the C header

�le

����� Value AT value�c�

In this prototype tool� values of variables are de�ned by a text �le The module hides

the syntax of the text �le

Table �� � Access Program of Value Module

Access Program Description

void AT valueInit� char dsdef� SymTbl

s�

Initialize this module with a C header �le

speci�ed by dsdef and a symbol table spec�

i�ed by s

AT VarSet AT valueGetValue � char

valuefn�

Return an AT VarSet object derived from the

value �le speci�ed by valuefn

����� Evaluation AT evaluate�c�

The Evaluation module is the master control of the Alias Table Tool The secret of

the module is how all the modules work together to do the job A future tool will

only need to invoke these access programs if it uses this tool

Table �� � Access Program of Evaluation Module

Access Program Description

void AT evaluateInit�Chandle context�

char dsdef�

Initialize this module with a context and a C

header �le The context contains aliases

CHandle AT evaluateRun�AT VarSet

v�

Return a new equivalent context without

aliases for the speci�ed values for variables

void AT evaluateClose�� Free system resources

� Alias Table Tool Design ��

����� Variable SetAT var�c�

The secret of the Variable Set module is the data structure for representing a set of

variable id and its value pairs It has access programs for setting and retrieving a

variable�s value

Type exported� AT VarSet

Table ��� � Access Program of Variable Set Module

Access Program Description

void AT varInit� � Initialize the module

AT VarSet AT varCreate� � Create a new variable set

void AT varDestroy�AT VarSet v� Destroy a variable set

void AT varSetValue�AT VarSet v� Id

var� char val�

Set the variable speci�ed by var and its value

speci�ed by val in the variable set

char AT varGetValue�AT VarSet v�

Id var�

Get the value of the variable var

IdList AT varGetAllVariables

�AT VarSet v �

Get a list of all the variable ids from the vari�

able set

������ Alias Set AT alias�c�

The secret of the module is the data structure for representing the evaluation result of

a collection of aliases It has access programs for setting and retrieving each element

of an alias

Type exported� AT AliSet

Table ��� � Access Program of Alias Set Module

Access Program Description

void AT aliasInit�� Initialize the module

AT AliSet AT aliasCreate�� Create a new alias set

void AT aliasDestroy�AT AliSet a� Destroy the alias set

void AT aliasRemoveElts�AT AliSet a�

Id alias�

Remove all the substructures designated by

the alias in the alias set

void AT aliasAddElt�AT AliSet a� Id

alias� Expn e�

Add the substructure designated by the alias

to the alias set

� Alias Table Tool Design ��

Table ��� � Access Program of Alias Set Module

Access Program Description

IdList AT aliasGetAliases�AT AliSet a� Get a list of all the aliases in the alias set

int AT aliasGetCardinality�AT AliSet

a� Id alias�

Get the cardinality of the alias in the alias

set

Expn AT aliasGetElt�AT AliSet a� Id

alias� int nth�

Get the nth substructure designated by the

alias in the alias set

������ Alias Evaluation AT ae�c�

This module hides the algorithm for evaluating aliases

Table ��� � Access Program of Alias Evaluation Module

Access Program Description

void AT aeInit� char dsdef� Initialize the module with a C header �le

void AT aeSetValues� AT VarSet a � Set variable values

void AT aeGenerateCode �CHandle

context� IdList list�

Generate the code to evaluate the list of

aliases in the context

void AT aeExecCode � AT AliSet a�

SymTbl s �

Execute the code generated by the above ac�

cess program and return the evaluation result

and a new symbol table

void AT aeEvaluate �CHandle context�

IdList list� AT AliSet a� SymTbl s�

Evaluate the list of aliases in the context The

alias evaluation result is returned by a and a

new symbol table is returned by s

void AT aeClose�� Free resources

������ Quote Evaluation AT qe�c�

The module hides the algorithm for evaluating quotes

Table ��� � Access Program of Quote Evaluation Module

Access Program Description

void AT qeInit�char dsdef� Initialize the module with a C header �le

void AT qeEvaluate �CHandle context�

int n� AT VarSet v�

Evaluate last n expressions contained in the

context based on the variable set

� Alias Table Tool Design ��

Table ��� � Access Program of Quote Evaluation Module

Access Program Description

Expn AT qeGetFirstResult�� Get the �rst evaluated expression

Expn AT qeGetNextResult�� Get the next evaluated expression

void AT qeClose�� Free system resources

������ C Function CFun�c�

The secret of this module is the data structure for representing the description of

a C function A C function has its name� arity� parameters and parameter passing

method for each argument The parameter passing method can be either of PASS�

BYVALUE or PASSBYREFERENCE It has access programs for manipulating all

these information

Type exported� CFun

Table ��� � Access Program of C Function Module

Access Program Description

void CFunInit�� Initialize this module to a known state

CFun CFunCreate�char funName� int

arity�

Create a new function with the function name

and the arity

void CFunDestroy�CFun h� Destroy the function

void CFunSetArgument�CFun h� int

nth� Id var� PassMethod pass�

Set the nth argument of the function The

argument id is var and its passing method is

speci�ed by pass

int CFunGetArity�CFun h� Get the arity of the function speci�ed by h

void CFunGetArgument�CFun h� int

nth� Id var� PassMethod pass�

Get the Id of nth argument of function h The

Id is returned by var and the passing method

is returned by pass

������ IdList idlist�c�

IdList is a module in the general utilities of TTS The secret of the IdList module is

the data structure for representing lists of Ids It also hides algorithms for searching�

� Alias Table Tool Design ��

manipulating and querying these lists There are a couple of access programs that act

as operations on the idlists� for example list union and intersection A couple of new

access programs are added for this thesis These access programs are list query and

operations on the lists� such as list di�erence The new access programs are presented

in italic font

Type exported� IdList

Table ��� � Access Program of IdList Module

Access Program Description

IdList IdListCreate �void� Create an empty IdList and return it to the

calling program

void IdListDestroy �IdList� Destroy the IdList passed to it� freeing appro�

priate memory

void IdListDelete �IdList� int� Delete the Id located at the speci�ed position

� indexed from � � in the speci�ed IdList

int IdListGetLen �IdList� Return the number of Ids in the speci�ed

IdList

Id IdListGet �IdList� int� Return the Id located at the speci�ed position

in the speci�ed IdList

void IdListJoin �IdList� IdList� Append a copy of the second IdList onto the

end of the �rst IdList

int IdListGetPos �IdList� Id� Return the positions of the speci�ed Id in the

speci�ed IdList

IdList IdListDup �IdList list� Duplicate the IdList passed to it and return

the duplicating IdList

void IdListRemoveDup �IdList list� Return a new IdList and it contain every Id

in list once

void IdListUnion �IdList list�� IdList

list��

Union two IdLists passed to it� list� holds the

result

void IdListIntersection�IdList list��

IdList list��

Intersection two IdLists� list� holds the result

void IdListRemoveId�IdList� Id� Remove the speci�ed Id from the IdList�

void IdListRemoveAll�IdList� Remove all the Ids from the speci�ed IdList�

� Alias Table Tool Design ��

Table ��� � Access Program of IdList Module

Access Program Description

bool IdListContainsId�IdList� Id� Return BOOL TRUE if the Id is in the spec�

i�ed IdList� otherwise BOOL FALSE�

bool IdListIsEmpty�IdList� Return BOOL TRUE if the speci�ed IdList is

empty� otherwise BOOL FALSE�

bool IdListContainedBy�IdList list��

IdList list�

Return BOOL TRUE if every Id in list� is

also in list�

void IdListDierence�IdList list�� IdList

list�

Dierence two IdLists� list� holds the result�

������ IdTab IdTab�c�

The secret of the module is the data structure for representing pointers keyed by

an integer identi�er The module has access programs for setting and retrieving the

pointers keyed by an integer identi�er

Type exported� IdTab

Table �� � Access Program of IdTab Module

Access Program Description

void IdTabInit�� Initialize the module to a known state

IdTab IdTabCreate�� Create a new IdTab object

void IdTabDestroy�IdTab t� Destroy the IdTab object

bool IdTabInsert�IdTab t� int id� void

data�

Return BOOL TRUE if the data is success�

fully inserted to the IdTab� otherwise return

BOOL FALSE

void IdTabRemove�IdTab t� int id� Remove the data keyed by id from the IdTab

object

int IdTabGetSize�IdTab t� Get the number of ids in the IdTab

IdList IdTabGetAllIds�IdTab t� Get the list of ids in the IdTab

void IdTabGet�IdTab t� int id� Return the void pointer pointed to the data

keyed by id if the data in the IdTab� otherwise

return NULL

� Alias Table Tool Design �

Table �� � Access Program of IdTab Module

Access Program Description

void IdTabGetFirst�IdTab t� int id� Return the pointer to the data added �rst

to the IdTab and id holds its integer key if

there exists one in the IdTab� otherwise re�

turn NULL

void IdTabGetNext�IdTab t� int id� Return the pointer to the data added next

to the IdTab and id holds its integer key if

there exists next data in the IdTab� otherwise

return NULL

����� Sub�expression Substitution AT sub�c�

The secret of the module is the algorithm for substituting sub�expressions in an

expression with other sub�expressions AT subSetExpnToExpn can be called several

times before AT subExec is called

Table ��� � Access Program of Sub�expression Substitution Module

Access Program Description

void AT subReset�� Reset this module to a known status

void AT subSetExpnToExpn�Expn O�

Expn N�

Tell the module that the sub�expression O

to be substituted by the sub�expression N

If AT subReset is called twice� any N set

by a call of this program should not be

a sub�expression of Os that are set by

other calls of this program� otherwise an

AT AmbiguousSubErr error token is set

void AT subExec�Expn e� Path p� Substitute all the sub�expression Os in �e� p�

by the corresponding sub�expression Ns set by

the above access program

� Alias Table Tool Design ��

������ Symbol Table Utility AT stu�c�

A symbol table contains a collection of symbol ids The information about each

symbol is organized into a set of classes This module hides the interpretation of each

classes�

Table ��� � Access Program of Symbol Table Utility Module

Access Program Description

IdList AT stuGetAllVars�SymTbl t� Get a list of variable symbols in the symbol

table t

void AT stuGetType�SymTbl t� Id var�

char wholetype� char truetype� int

idx� int dim�

Return the type of the variable identi�ed by

var in the symbol table t If the type is an ar�

ray� � dim� returns the dimensionality of the

array� and � idx� returns the length of every

dimension

char AT stuGetName�SymTbl t� Id

id� char buf�

Get the name of the symbol

Id AT stuGetConst�SymTbl t� int con�

stant�

If the constant is in the symbol table� return

the Id of the constant� otherwise create a new

symbol identifying the constant and return

the Id

Id AT stuAddVar�SymTbl t� char

name� char type�

Create a new variable symbol with the name

and the type and return the Id of the new

symbol

Id AT stuAddFunction�SymTbl t� char

name� int arity�

Create a new function symbol with the name

and the arity and return the Id of the new

symbol

void AT stuDisableIDP�SymTbl t� Id

id�

Remove the information classes about the

IDP speci�ed by id

�This module is dierent from the Information module ���� and the Symbol Utilities module �����The Information module just provides a means of storing and retrieving class name and class datapairs about symbols� The Symbol Utilities module provides means for creatingdeleting symboltables� as well as copying symbols within a symbol table or between two symbol tables� They bothwork at syntactic level� This module and Symbol Utilities module use the Information module�

� Alias Table Tool Design �

Table ��� � Access Program of Symbol Table Utility Module

Access Program Description

Id AT stuAddIDP�SymTbl t� char I�

int I card� Id G� Id Q�

Create a new symbol for the IDP speci�ed by

I� I card� G and Q and return the Id of the

new symbol

void AT stuGetIDP�SymTbl t� Id id�

char I� int I card� Id G� Id Q�

Get the information about the IDP indicated

by id The information is returned by I�

I card� G and Q

void AT stuSetIDP�SymTbl t� Id id�

char I� int I card� Id G� Id Q�

Set the information about the IDP identi�

�ed by id The information is speci�ed by

I� I card� G and Q

Id AT stuAddOneDimPredNormalTbl�

SymTbl t �

Create a new symbol for an one�dimension

predicate normal table and return the new Id

of the symbol

������ Status Reporting Module AT error�c�

The status reporting module for the Alias Table Tool encapsulates the representation

of the result of invoking access programs of various Alias Table Tool modules An

invocation is successful if the value of AT Token is AT Success� otherwise an error

token describing the error is returned Table ��� contains a list of all the error

tokens used in the Alias Table Tool along with their description

This module hides the data structure for representing the status of invoca�

tions of access programs of the Alias Table Tool modules It also hides an algorithm

for translating a status token into its textual description

Table ��� � Access Program of Status Reporting Module

Access Program Description

void AT errSet�AT Token� Set the current error status

AT Token AT errGet�� Return the current error status

char AT errGetStr�AT Token� Return a descriptive string corresponding to

the given error status

� Alias Table Tool Design ��

Table ��� � AT Error Tokens

Status Token Description

AT Success No error

AT TableOver�owErr More objects of the given type cannot be

created

AT ArgNumErr Argument Number is not consistent in a

context

AT UnknownIdErr Id is not speci�ed

AT InvalidHandleErr Current object is not valid

AT AllocFailErr Memory allocation failure

AT NotInitializedATErr ATT is not initialized

AT CircularDe�nitionErr Circular de�nition of aliases

AT NoEnoughVarsErr No enough variable values to evaluate

aliases

AT DataStructureDefErr Data structure de�nition error

AT VectHdrSyntaxErr More than one alias appears in a vector

header cell

AT DupVarInVectHdrErr Substructures in a vector header are not dis�

joint

AT AliasNotUniqueErr The alias is not unique

AT GTSErr Error in GTS module

AT QuoteSyntaxErr Quote syntax error

AT VarSetErr Variable set error

AT ValueSyntaxErr Error in the syntax of variable value

AT VarTypeUnDe�nedErr Variable type is not de�ned

AT CodeGenErr Error in the Code Generator

AT SecondaryAliasDomainSyntaxErr Error in the syntax of the domain of a sec�

ondary alias

AT PrimaryAliasTemplateSyntaxErr Error in the syntax of the template of a pri�

mary alias

AT PrimaryAliasDomainSyntaxErr Error in the syntax of the domain of a pri�

mary alias

� Alias Table Tool Design ��

Table ��� � AT Error Tokens

Status Token Description

AT PrimaryAliasMembershipSyntaxErr The membership of an alias is not predicate

expression

AT AliasSyntaxErr Syntax of an alias is wrong

AT AliasRepetitiveDefErr An alias is de�ned more than once

AT AmbiguousSubErr Error in setting sub�expression substitution

AT CTypeErr Error in the variable type

AT NotAliasIdErr An id is not alias id

AT CanNotCreateIdListErr Fail to create an IdList

AT CanNotCreateIdTabErr Fail to create an IdTab

AT CMErr Error in CM module

AT THErr Error in TH module

AT FileErr File operation failure

AT InfoTableErr Error in info module

AT OutOfIndexErr An Index is out of bound

AT InvalidIdErr Id is not valid

AT NULLPointerErr Pointer is NULL

AT UnknownErr Unknown type of error

��� Algorithms

����� Algorithm Overview

The inputs to the Alias Table Tool are a context� a value �le and a C header �le

The output of the Alias Table Tool is a equivalent context without aliases The Alias

Table Tool uses the following algorithm to evaluate aliases and replace aliases in the

expressions containing these aliases

� Check the syntax of the input C header �le

� Check the syntax of variable values in the value �le

� Check the syntax of the alias de�nition expressions

� Alias Table Tool Design ��

� Find all the evaluatable aliases An Evaluatable alias is an alias that satis�es the

following conditions

� Its de�nition contains no aliases� or if it contains aliases� all the aliases are

evaluated

� If any function� f�� which is used in the alias de�nition� is de�ned in the

input context� then the de�nition of f� does not contain aliases that have

not been evaluated and moreover if any function� f�� which is used in the

de�nition of f�� is de�ned in the input context� then the de�nition of f�

does not contain aliases that have not been evaluated� and so on

If this step fails to �nd evaluatable aliases from aliases that have not been

evaluated� The error token� AT CircularDe�nitionErr� is set and then this tool

exits

� Convert the de�nition expressions of all the evaluatable aliases from step � to the

expressions that can be handled by the Code Generator based on the algorithms

discussed in section ��� and ���

Form a context that contains converting expressions from � and input this context

to the Code Generator

� Run the code generated by the Code Generator and get the substructures that

aliases represents

� Replace the aliases contained in the expressions in the input context based on

the steps discussed in section ��

� If there are some aliases that are not evaluated� go to step �� otherwise generate

an output context The context contains all the resulting expression from step

� and it does not contain alias de�nitions

����� Algorithm for Evaluating a Primary Alias

The algorithm shown below is to convert a primary alias de�nition expression to an

expression for which the Code Generator can generate evaluation code The algorithm

� Alias Table Tool Design ��

is shown by an example Without losing generality� suppose a primary de�nition X

is de�ned as follow

Xdf� �A�i� �i� ����in � IDP��i�� � IDP��i�������IDPn�in��Membership�

�� Convert the above de�nition expression to the following expression� E

��i�� IDP �i�����i�� IDP �i���

��in� IDP �in��H�

Membership Membership

record�X� id of i�� i��!A�i� �i� ����in ��record�X� id of i�� i��!A�i� �i� ����in ��

���record�X� id of in� in�!A�i� �i� ����in �

true��

G

Figure ��� Convert a Primary Alias De�nition Expression

In E� the table is one�dimensional predicate normal table The predicate rule

pT is H� and the relation rule rT is G

In E� �record� is a function symbol and its corresponding C declaration

is given as follows

bool record�int alias id� int index id� int index value� void elt�

The C function writes the information passed by its arguments to a �le and it

always returns true

�� Find out all the variables except index variables in E These variables form a set�

V In this example� A � V� but i� �� V

�� Make a function application F with all the variables in V as its arguments

�� Produce an expression like �de�ned�F� E��

� Alias Table Tool Design ��

����� Algorithm for Evaluating a Secondary Alias

The idea of evaluating a secondary alias is to convert a secondary alias de�nition

expression to a primary alias de�nition expression Suppose a secondary alias Y is

de�ned as follows

Ydf� �Dom� Mem�

�� Since every alias in the Dom has been evaluated� the Alias Table Tool can evaluate

the Dom and get the result set� D Suppose the cardinality of D is n

�� Use a new variable N� which is a one dimensional array and the size of the array

is n� to hold each element of D

�� Use a new inductively de�ned predicate IDPn to de�ne the index set f�� �� � n� �g

�� Convert the secondary alias de�nition to a primary alias de�nition� �N�i � IDPn�i��

Mem��� where Mem� is Mem except each Y in Mem� is replaced by N�i

�� If the domain of any quanti�cation expression � in Mem� is a set that is constructed

by aliases �eg ��u� �u � �P � Q�� � �u � ���� where P and Q are aliases��

similarly use step �� �� � and � to replace aliases in the quanti�cation domain

�A domain of a quanti�cation expression is the set that con�nes the index variable in the quan�ti�cation expression�

Chapter �

Results and Conclusions

This chapter discusses the results of this thesis� shows the limitations and future work�

and draws the conclusions

��� Results

This thesis shows how we can de�ne aliases and use those aliases in tabular expres�

sions The Alias Table Tool is a prototype that has been developed as a preprocessor

of the Code Generator The Alias Table Tool evaluates aliases based on their

de�nition and a set of variable values� then the Alias Table Tool constructs a new

tabular expression where the aliases contained in the original tabular expression are

replaced by the substructures that they stand for The resulting tabular expressions

can be processed by the Code Generator The constructed expression can be used

more than once if the values of the variables that are used in the de�nition of the

aliases do not change

We have shown that aliases can improve the readability of formal software

documentation presented in tabular notation

The Alias Table Tool and the Code Generator can work together as a part of

many tools� for example test oracle� Given a relational program speci�cation ��

�A test oracle is some mechanism that can determine if the output from a program is correct�

� Results and Conclusions ��

using tabular expressions �� and an input� output pair from the program under test�

the Alias Table Tool �rst evaluates and replaces the aliases in tabular expressions

based on the pair and the alias de�nitions contained in the speci�cation� then the

Code Generator generates evaluation code for the resulting tabular expressions�

�nally execution of the evaluation code returns true if the pair satis�es the relation

described by the speci�cation� or false if it does not

The concept of an alias can be used in other situations Aliases can be used

in conventional expressions which describe the program behavior They can even be

used in programs An alias must be evaluated whenever it is referred to during the

execution of the program

��� Limitation and Future Work

Like any other practical tool or technique� this Alias Table Tool also has limitations

and future work is needed to eliminate these limitations

����� Performance

Theoretically� it is possible to generate evaluation code for an expression containing

aliases and execute the same code for di�erent sets of variable values This thesis

described two steps to evaluate an expression In the �rst step� aliases in the ex�

pression are evaluated for a set of variable values and aliases in the expression are

replaced with the evaluation result In the second step� the expression resulting from

the �rst step is evaluated for the same set of variable values The two�step evaluation

means that the second evaluation step has to be executed for di�erent sets of variable

values Obviously� the performance of the two�step evaluation is inferior to that of

an one�step evaluation

����� Structures Use Links

Linked lists are frequently used to store a collection of data in software In this thesis�

aliases do not stand for substructures �ie nodes� of linked lists We may use the

same ��tuple and ��tuple described in Chapter � to de�ne an alias that designates

� Results and Conclusions �

substructures of a linked list An inductively de�ned predicate can be used to de�ne

the set of the nodes for the linked list There are two reasons that this thesis does not

support linked lists First� the author of this thesis has not found a satisfactory way

to de�ne the template of a primary alias that designates substructures of a linked

list Second� the Code Generator does not support any type other than integer for

an inductively de�ned predicate The second reason does not make the evaluation of

aliases impossible� but it makes the evaluation complicated

����� De�ne an Alias as an Ordered Set

In this thesis� an alias identi�es a set of substructures� so when an alias that identi�es

a set with cardinality greater than one appears in the vector header of a vector table�

no other unquoted aliases that identify sets with cardinality greater than one are

allowed to appear in the same row of the main grid of the vector table

If an alias is de�ned as an ordered set� of substructures� we can have one

alias in the vector header of a vector table and other aliases in the same row of the

main grid of the vector table as long as all of the sets identi�ed by the aliases have

the same cardinality However� the de�nitions of such aliases may be quite long and

hard to read We may pay more than we get if we de�ne and use such aliases� so this

thesis does not support aliases that are de�ned as ordered sets

����� Non�deterministic Aliases

A kind of important alias� non�deterministic alias� is not covered in this thesis A

non�deterministic alias designates a non�deterministically selected substructure from

a complicated data structure For example� a positive element non�deterministically

selected from an integer array This kind of alias can be clearly de�ned after some

modi�cations are made to alias de�nitions described in Chapter � An alias can be

de�ned by a ��tuple or ��tuple

An alias de�ned by a ��tuple is called a primary alias It can be de�ned by

�A ordered set is a set over which a �xed complete element order is de�ned�

� Results and Conclusions ��

�T� D� M� A� The syntax of T� D and M is respectively the same as that of

T� D and M of a primary alias described in Chapter � A can be either All or

Any The meaning of �T� D� M� All� is the same as the meaning of the primary

alias de�ned by �T� D� M� �T� D� M� Any� means one substructure that is

non�deterministically selected from the substructures de�ned by �T� D� M� All��

An alias de�ned by �T� D� M� Any� is a non�deterministic alias

An alias de�ned by a ��tuple is called a secondary alias It can be de�ned by

�D� M� A� The syntax of D and M is respectively the same as that of D and M of

a secondary alias described in Chapter � A can be either All or Any The meaning

�D� M� All� is the same as the meaning of the secondary alias de�ned by �D� M�

�D� M� Any� means one substructure that is non�deterministically selected from

the substructures de�ned by �D� M� All�� An alias de�ned by �D� M� Any� is a

non�deterministic alias

There is one thing that should be pointed out Even if two non�deterministic

aliases have the same de�nition� they do not necessarily stand for the same substruc�

ture

If the de�nition of a non�deterministically selected substructure is long and

the substructure appears in several places in tabular expressions� using a non�

deterministic alias can make expressions shorter The following example shows the

advantage of using a non�deterministic alias The table in Figure �� is a normal

function table

�There is an error if the cardinality of the set de�ned by �T� D� M� All� is ���There is an error if the cardinality of the set de�ned by �D� M� All� is ��

� Results and Conclusions �

f�int A�N � int x�df� H�

x � � x � �

largest � � largest � �

G

where

IDPAdf�� f�g� G�i� � i � �� i � �N ��� �

largestdf�� A�i � IDPA�i�� ��j� IDPA�j� � �A�i � A�j ��� Any �

Figure ��� De�nition of Function f

The meaning of this example is clear Because f is a function� not a relation� it can be

evaluated by the two�step evaluation The Alias Table Tool can non�deterministically

select one substructure for the alias �largest� and replace it contained in the table

with the substructure without changing the meaning of the function presented by

the table

However� if an expression containing non�deterministic aliases de�nes a rela�

tion� the expression may not be evaluated by two�step evaluation The following

example will illustrate that The data structure is given �rst A program GetVa�

cantRoom returns the roomNum of any one vacant room in the building

typedef struct Room fbool isVacant�

int roomNum�

gRoom building�N �

GetVacantRoom�Room building�N �df� vacantroomroomNum where

vacantroomdf�� building�i � IDPN�i�� building�i isVacant � true� Any �

IDPNdf�� f�g� G�i� � i � �� i � �N ��� �

If the Alias Table Tool just non�deterministically selects a substructure for an

�The description of a program can be either a function or a relation�

� Results and Conclusions ��

alias and replaces that alias with the substructure in expressions containing the alias�

the information �non�deterministic selection� is lost For example� suppose N is � and

building is fftrue� ���g� ffalse� ���g� ftrue� ���g� ffalse� ���gg If the Alias Table

Tool evaluates vacantroom and selects building�� as the substructure designated by

vacantroom and replaces vacantroom in GetVacantRoom� GetVacantRoom will be

de�ned as

GetVacantRoom�Room building�N �df� building�� roomNum

The relation GetVacantRoom will be treated as a function in the second eval�

uation step The meaning of the expression would not be what we want For

example� if the expression is used as the speci�cation of the program GetVacant�

Room for testing� and given the same value for building�N � the execution of program

GetVacantRoom may return ��� The second evaluation step would have no way to

determine whether the execution result of GetVacantRoom satis�ed its speci�cation

or not

Use of non�deterministic aliases can make software speci�cation short and clear

The problem is how to correctly evaluate expressions containing non�deterministic

aliases At present� the Alias Table Tool does not support non�deterministic aliases

����� Future Work

Limitations of this thesis are explained above Some of the future work is listed as

follows

� Merge the Alias Table Tool and the Code Generator to obtain one�step evaluation

tool

� Find how to de�ne the template of a primary alias that stands for substructures

of a linked list

� Study how to use non�deterministic aliases and how to evaluate expressions

containing non�deterministic aliases

� Results and Conclusions ��

��� Conclusions

An e�ort to make software documentation more readable is always important�

because software documentation usually has more readers than writers and it

plays a crucial role in the whole life cycle of software development and mainte�

nance This thesis has illustrated that use of aliases can reduce the complexity

of mathematical expressions when the same substructures of a complicated data

structure appear in several places in the tabular expressions The Alias Table Tool�

the prototype tool for this thesis� has demonstrated that the idea can be implemented

Bibliography

�� Ruth Abraham� �Evaluating Generalized Tabular Expressions in Software

Documentation�� CRL Report No� �� � Telecommunications Research In�

stitute of Ontario�TRIO�� McMaster University� Hamilton� Ont� February

����

�� K L Heninger� JKallander� D L Parnas� J E Shore� �Software Require�

ments for the A��E Aircraft�� NRL Memorandum Report ��� � United

States Naval Research Laboratory� Washington� DC� Nov ����

�� R Janicki� �Towards a Formal Semantics of Parnas Tables�� ��th Interna�

tional Conference on Software Engineering� IEEE Computer Society� Seat�

tle� WA� April ����� pp �������

�� D LParnas� �Tabular Representation of Relations�� CRL Report No� ��

Telecommunications Research Institute of Ontario�TRIO�� McMaster Uni�

versity� Hamilton� Ont� Oct ����

�� D LParnas� �Predicate Logical for Software Engineering�� IEEE Trans�

actions on Software Engineering� Vol ��� No � �September ������ pp

�����

� D LParnas� �On a �Buzzword�� Hierarchical Structure�� Proceedings of

the IFIP Congress ����� North Holland ����� pp ������

�� D LParnas� �On the Criteria to be Used in Decomposing Systems into

Modules�� Commun ACM� vol ��� pp ���������� December ����

BIBLIOGRAPHY ��

�� D LParnas� �A Generalized Control Structure and Its Formal De�nition��

Communications of the ACM� vol �� No � �August ������ pp �������

�� D L Parnas� J Madey� �Functional Documentation for Computer Sys�

tems� Science of Computer Programming� Elesevier� Vol ��� No �� pp

����� Oct ����

��� Dennis Peters� �Generating a Test Oracle From Program Documenta�

tion�� CRL Report No� ��� Telecommunications Research Institute of On�

tario�TRIO�� McMaster University� Hamilton� Ont� April ����

��� Software Engineering Research Group� �Table Tool System Developer�s

Guide�� CRL Report No� ���� Telecommunications Research Institute of

Ontario�TRIO�� McMaster University� Hamilton� Ont� January ����