ORCA-C/Symbol.Print

108 lines
3.0 KiB
Plaintext

procedure PrintOneSymbol {ip: identPtr};
{ Print a symbol }
{ }
{ Parameters: }
{ ip - identifier to print }
procedure PrintClass (class: tokenEnum);
{ Print the class of a symbol }
{ }
{ Parameters: }
{ class - class of the symbol }
begin {PrintClass}
case class of
autosy: write('auto');
externsy: write('extern');
ident: write('ident');
otherwise: write(ord(class):1);
end; {case}
end; {PrintClass}
procedure PrintType (tp: typePtr);
{ Print a type }
{ }
{ Parameters: }
{ tp - type pointer }
begin {PrintType}
with tp^ do begin
write(' ', size:1, ' byte ');
if tqConst in qualifiers then
write('constant ');
if tqVolatile in qualifiers then
write('volatile ');
if tqRestrict in qualifiers then
write('restricted ');
case kind of
scalarType : writeln('scalar');
arrayType : begin
writeln(elements: 1, ' element array of');
PrintType(aType);
end;
pointerType : begin
writeln(' pointer to');
PrintType(pType);
end;
functionType: begin
writeln(' function returning');
PrintType(fType);
end;
enumConst : writeln('enumeration (', eval: 1, ')');
enumType : writeln('enum type');
definedType : begin
writeln('defined type of');
PrintType(dType);
end;
structType : writeln('struct: ', ord4(tp):1);
unionType : writeln('union');
end; {case}
end; {with}
end; {PrintType}
begin {PrintOneSymbol}
with ip^ do begin
writeln; {start with a blank line}
write(name^, {write id info}
': isForwardDeclared = ', isForwardDeclared,
'; class = ');
PrintClass(class);
writeln;
PrintType(iType); {print type info}
end; {with}
end; {PrintOneSymbol}
procedure PrintTable {sym: symbolTablePtr};
{ print a symbol table }
{ }
{ parameters: }
{ sym - symbol table to print }
var
i: integer; {loop variable}
ip: identPtr; {current symbol}
begin {PrintTable}
if sym <> nil then begin
writeln; {write header}
writeln('Symbols:');
writeln('========');
for i := 0 to hashSize do begin {loop over all hash buckets}
ip := sym^.buckets[i]; {trace through all symbols in this bucket}
while ip <> nil do begin
PrintOneSymbol(ip); {print a symbol}
ip := ip^.next; {next symbol}
end; {while}
end; {for}
end; {if}
end; {PrintTable}