home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 December
/
simtel1292_SIMTEL_1292_Walnut_Creek.iso
/
msdos
/
turbopas
/
t_ref.arc
/
T-REFCH3.DOC
< prev
next >
Wrap
Text File
|
1987-01-15
|
16KB
|
397 lines
Chapter III - The Cross Reference Lister
This chapter deals primarily with the Cross Reference Listing program.
However, before getting into the details of the Reference Lister, several
important definitions need to be made to prevent any confusion. Once the terms
used in this chapter are presented, we will present an in-depth description of
the Cross Referencer and its print format.
System Identifiers:
Like most compilers, Turbo Pascal has defined a set of identifiers
already declared under the IBM-PC version. Often called Standard Identifiers
or System Identifiers, they include Constants (i.e., Blue and Co80), Types
(i.e., Integer, Real, Byte, String, and Char), Variables (i.e., Mem and MemW),
Procedures (i.e., Textcolor, Substr, and Window), and Functions (i.e., WhereX,
Copy, Cos, and Random). T-Ref has "pre-declared" the complete list of Turbo
system identifiers (up through Version 3.01) for referencing and they may be
included in the cross reference listing if so desired. Appendix A gives the
entire list of system defined (standard) identifiers.
Data Types:
There are three general catagories of data types in Pascal: scalars,
structured types, and pointers. Scalars include the standard scalar types as
noted above (Integer, Byte, Real, Boolean, String, and Char) and extended
scalar types (Subranges and User-Defined Scalars). Structured types are
arrays, records, sets, and files. Finally, pointers are address values to
variables of the other data types.
Basic Types:
Basic types, not to be confused with data types, are the types of the
identifiers. Basic types include Labels, Constants, Types, Variables, Proce-
dures, and Functions. The best way to prevent confusion between these and
data types is by noting that most basic types have an associated data type.
For example, the basic type 'Function' may have a data type of Integer. The
basic type 'Constant' may have a basic type of Char. However, basic types
Labels, Procedures, and untyped formal parameters are the only ones that have
an undefined data type.
Labels do not necessarily have to be identifiers, but may be integer
numbers as well. These are handled appropriately by T-Ref.
User defined scalar values are considered constants by T-Ref. For
example, in the following declaration:
TYPE DAY_OF_WEEK = (SUN,MON,TUE,WED,THU,FRI,SAT);
the identifiers SUN, MON, ..., SAT are considered of basic type Constant, even
though the identifier DAY_OF_WEEK is of basic type Type.
All formal parameter identifiers are considered a special extension of
the basic type Variable. Therefore, when Variables are listed in the cross
reference, formal parameter identifiers are included.
11
The program name, when a program head is given, does not actually fall
into any of the basic types listed above; however, rather than having a
separate field for a cross reference of the program name, it is considered by
T-Ref as a Procedure type with no references other than its declaration.
Now for the Cross Reference Lister:
The Cross Reference Lister, when activated ("ON"), gives a cross refer-
ence listing of the specified types of identifiers. Selection of identifiers
is determined by basic type in the following fashion:
Each of the basic types have two fields on the screen: a scope field and
a usage field (see Figure 1). The scope field is used to determine the
selection of identifiers based upon whether they are declared within the
system (system defined or "SysDf") or within the program (program defined or
"PrgDf"). The "All" setting is used to select all identifiers of that basic
type. The "None" setting tells the program to skip listing any identifier of
that basic type.
The usage field is used to determine the selection of identifiers based
upon whether or not they have been referenced within the program (other than
in their declarations). The "Used" setting will select for listing only
identifiers of that basic type that were actually used within the program.
The "Unused" setting selects only those identifiers not referenced anywhere
within its scope. The "All" setting selects identifiers declared of that
basic type irregardless of their use.
The Cross Reference Lister is activated by positioning the cursor over
the 'Cross Reference' field and striking the space bar until the word "On"
appears within the cursor. To deactivate the cross reference lister, hit the
space bar again and the word "Off" will appear. Note that the same procedure
here is used to activate the cross reference lister as in the source lister
described in chapter II above. Like the source lister, the nine fields that
appear on the screen directly below the 'Cross Reference' field relate to
specific information about what identifiers are to be included or not included
in the cross reference listing, as well as setting a header and paging. These
fields are updated in the same manner as those fields in the source lister
area: by placing the block cursor over the field and striking the space bar
until the desired parameter appears within the cursor.
Since we have already defined the parameters that appear in the fields
'Labels', 'Constants', 'Types', 'Variables', 'Procedures', and 'Functions', we
will not pursue this any further except to say that the 'Labels' field has a
restricted set of values for its scope field: "PrgDf" and "None". This is due
to the fact that Turbo has no System Defined labels. No other restrictions
apply to any of these fields.
The 'Header' field operates in exactly the same fashion as the 'Header'
field within the source lister area. When it is activated ("On"), the header
that was created using the F4 function key will be printed at the top of each
page of cross reference output. The header can be from two to five lines long
and each line can be up to 75 columns in length. Again, if a header is
printed, the program will automatically buffer 3 blank lines before the header
and 2 blank lines after the header.
The 'Page Numbering' field also operates like the field of the same name
within the source lister area. The number of lines per page is set by the F6
12
function key and is the same value used for paging the source listing output.
The 'Include File' field is used to tell the program whether or not to
print files made available to the Turbo compiler through the include file
compiler directive. When activated ("Yes"), include files are automatically
parsed for cross referencing all identifiers within the files (declarations
and uses). The OPTIONAL setting ("Opt") allows you to selectively choose the
files to be included in the cross referencing process. If one of the 'Include
File' fields (either for the source lister or the cross reference lister) is
activated and the other is not, the program will take the appropriate actions
to perform only the operations on the include file needed.
Interpreting the Cross Reference listing:
There are three parts to the cross reference listing: an identifier cross
reference listing, a procedure/function map listing (table of contents), and a
basic and data types count listing.
A. Identifier Cross Reference Listing:
Each identifier cross referenced is listed in alphabetical order and has
the following format. The first two lines of a cross reference entry has the
following format:
Name................ Basic-Type Data-Type
Declared on line LLLL:SSSS within Procedure-Name...... (LVL)
where Name is the name of the identifier (20 characters long), Basic-Type is
the basic type, Data-Type is the data type, LLLL:SSSS is the line number (and
possibly the include file's subline number) of the declaration, Procedure-Name
is the procedure or function name that the identifier was declared within (up
to 20 characters long), and LVL is the lexical level of the procedure or
function within the program.
If the identifier was not declared within the source code (as is the case
when cross referencing a portion of a program or a library or procedures that
reference identifiers in other portions of the program), then the second line
rather reads:
"Not declared within the scanned source."
The basic type field will be one of the following:
"Undefnd" - Signifies the use of an undeclared identifier found during
the parse.
Labels:
"Label " - Labels
Constants:
"Constnt" - Constants
"ScalVal" - Scalar Values
"Typed C" - Typed Constants
Types:
"Type " - Types
13
Variables:
"Var " - Variables
"FrmParm" - Formal Parameters (considered a Variable)
"VarParm" - Formal Variable Parameters (considered a Variable)
"Rec Fld" - Record Fields (considered a Variable)
"Rec Tag" - Record Fields declared as Record Tags (considered a Variable)
Procedures:
"Program" - Program name
"Procedr" - Procedures
Functions:
"Functn " - Functions
The data type field will be one of the following:
"Undefnd" - Signifies the use of an undeclared identifier found during
the parse, or an Untyped Formal Parameter
"Integer" - Integer scalars
"Byte " - Byte scalars
"Real " - Real scalars
"Boolean" - Boolean scalars
"String " - String scalars
"Char " - Character scalars
"Scalar " - User Defined Scalars
"Range " - Subranges
"Record " - Structured Type Records
and may be preceeded by some combination of the following to signify a
structured data type:
"Absolute Addr" - The Variable is located at a specific address
"File of" - The Type or Variable is of type File
"Set of" - The Constant, Type, or Variable is of type Set
"Pointer to" - The Type or Variable is of type Pointer
For example, "Absolute Addr Set of Scalar" means the data type of the ident-
ifier is a set of type scalar and is at a specific address in memory.
The third line of the reference, if the identifier is not referenced
within the scanned source code (other than its declaration), will be:
"<<< Identifier not referenced. >>>"
If the identifier has been referenced (other than its declaration), then a
sequence of references are printed.
First, a header for the references is printed describing the procedure or
function the reference took place:
"Referenced within" Procedure-Name......:
followed by an ordered list of the lines that identifier was referenced on.
The numbering is in the same format as the declaration line number format:
LLLL:SSSS.
An asterisk ("*") just before the line number means the identifier was
explicitly set to a value on that line of code. An ampersand ("&") means the
14
same thing, except that the identifier was set at a lexical (procedural) level
BELOW the level of its declaration.
Here, 'explicitly set' means that the variable or function was set with
a <variable> := <expression> statement, and does not take into consideration
setting the identifier through the use of procedure or function parameter
passing.
In addition, the referencer analyzes the code to provide additional
information:
a. For procedures and functions, a check is made to determine whether it
is recursive. If so, it is noted in the listing.
b. Overlay and external procedures and functions are noted.
c. For functions and variable formal parameters, if they are never
explicitly set in the code, a warning to this effect is printed. Note this
does not necessarily reflect an error, since these identifiers may be set
through other means.
d. For formal parameters (not variable formal parameters) that are
explicitly set in the code, a warning is printed. This may be an indication
that it should be a variable formal parameter.
At this point, it must be noted that record types and variables (and
their associated record fields) are a special case and are not handled pre-
cisely the same as other data types. This comes about primarily because it is
possible to have (and is often the case, rather than the exception) more than
one record variable with the same structure and therefore with precisely the
same record field identifiers. If a record field identifier were listed as
shown above, it would be impossible without inspection to determine which
record variable the reference was associated with.
Therefore, references to a specific record field are printed directly
under all record identifiers containing that field in its structure. Cross
references to that field then only include those that pertain specifically to
the record identifier being listed.
For example, suppose a record structure type were created:
TYPE
REC_STRUCT = RECORD
A,B : BYTE;
END;
and two different record variables were declared from this type:
4 VAR
5 REC_A, REC_B : REC_STRUCT;
Now suppose the following code is implemented:
35 WITH REC_A DO A := 1;
36 WITH REC_B DO A := 0;
where 35 and 36 refer to the line numbers. Then, a portion of the cross
reference listing would look like this:
15
REC_A Var Record
Declared on line 5 within PROGRAM (1)
Referenced within PROGRAM:
35 * 35
Record field: A Byte
Referenced within PROGRAM:
* 35
Record field: B Byte
<< Identifier not referenced. >>
REC_B Var Record
Declared on line 5 within PROGRAM (1)
Referenced within PROGRAM:
36 * 36
Record field: A Byte
Referenced within PROGRAM:
* 36
Record field: B Byte
<< Identifier not referenced. >>
Here, record field A has been broken out into its individual references and
therefore, it can be seen which reference goes with which record variable.
Also note that REC_A and REC_B show two references. The first are the
references of the identifiers within the WITH clauses; the second are the
references of record fields BELONGING to these identifiers. The asterisk (*)
shows where the identifiers were set to some value.
B. Procedure/Function Mapping:
The second part of the cross reference lister is a printout of all
procedures and functions declared within the parse, along with the line number
of the declaration. The names are indented according to the lexical (proc-
edural) level, and overlay and external procedures/functions are again noted.
This portion of the listing is excellent for getting a general layout (a table
of contents) of a program or library.
C. Basic and Data Type Count Listing:
Finally, the cross reference lister prints a summation of the total
number of lines parsed, the total number of identifiers cross referenced, and
a break-out of the identifier count by basic type and data type. Remember,
"Undefnd" basic types are those identifiers parsed but were never declared.
(Also remember, untyped formal parameters, labels, procedures, and the program
name have no data type associated with them and therefore will not be included
in the data type totals.)
16