mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2024-12-22 07:30:54 +00:00
Flag more appropriate errors about unexpected tokens in type names.
Previously, these would report "identifier expected"; now they correctly say "')' expected". This introduces a new UnexpectedTokenError procedure that can be used more generally for cases where the expected token may differ based on context.
This commit is contained in:
parent
dbe330a7b1
commit
b4232fd4ea
25
Parser.pas
25
Parser.pas
@ -2526,12 +2526,15 @@ Match(semicolonch, 22);
|
|||||||
end; {DoStaticAssert}
|
end; {DoStaticAssert}
|
||||||
|
|
||||||
|
|
||||||
procedure DeclarationSpecifiers (allowedTokens: tokenSet);
|
procedure DeclarationSpecifiers (allowedTokens: tokenSet;
|
||||||
|
expectedNext: tokenEnum);
|
||||||
|
|
||||||
{ handle declaration specifiers or a specifier-qualifier list }
|
{ handle declaration specifiers or a specifier-qualifier list }
|
||||||
{ }
|
{ }
|
||||||
{ parameters: }
|
{ parameters: }
|
||||||
{ allowedTokens - specifiers/qualifiers that can be used }
|
{ allowedTokens - specifiers/qualifiers that can be used }
|
||||||
|
{ expectedNext - token usually expected after declaration }
|
||||||
|
{ specifiers (used for error messages only) }
|
||||||
{ }
|
{ }
|
||||||
{ outputs: }
|
{ outputs: }
|
||||||
{ isForwardDeclared - is the field list component }
|
{ isForwardDeclared - is the field list component }
|
||||||
@ -2606,7 +2609,7 @@ var
|
|||||||
goto 1;
|
goto 1;
|
||||||
end; {if}
|
end; {if}
|
||||||
typeSpec := wordPtr; {default type specifier is an integer}
|
typeSpec := wordPtr; {default type specifier is an integer}
|
||||||
DeclarationSpecifiers(specifierQualifierListElement);
|
DeclarationSpecifiers(specifierQualifierListElement, ident);
|
||||||
if not skipDeclarator then
|
if not skipDeclarator then
|
||||||
repeat {declare the variables...}
|
repeat {declare the variables...}
|
||||||
if didFlexibleArray then
|
if didFlexibleArray then
|
||||||
@ -2779,7 +2782,7 @@ var
|
|||||||
myTypeSpec := wordPtr;
|
myTypeSpec := wordPtr;
|
||||||
end {else if}
|
end {else if}
|
||||||
else
|
else
|
||||||
Error(9);
|
UnexpectedTokenError(expectedNext);
|
||||||
end; {ResolveType}
|
end; {ResolveType}
|
||||||
|
|
||||||
|
|
||||||
@ -2797,7 +2800,7 @@ while token.kind in allowedTokens do begin
|
|||||||
autosy,externsy,registersy,staticsy,typedefsy: begin
|
autosy,externsy,registersy,staticsy,typedefsy: begin
|
||||||
if storageClass <> ident then begin
|
if storageClass <> ident then begin
|
||||||
if typeDone or (typeSpecifiers <> []) then
|
if typeDone or (typeSpecifiers <> []) then
|
||||||
Error(9)
|
UnexpectedTokenError(expectedNext)
|
||||||
else
|
else
|
||||||
Error(26);
|
Error(26);
|
||||||
end; {if}
|
end; {if}
|
||||||
@ -2854,7 +2857,7 @@ while token.kind in allowedTokens do begin
|
|||||||
if token.kind = lparench then begin
|
if token.kind = lparench then begin
|
||||||
{_Atomic(typename) as type specifier}
|
{_Atomic(typename) as type specifier}
|
||||||
if typeDone or (typeSpecifiers <> []) then
|
if typeDone or (typeSpecifiers <> []) then
|
||||||
Error(9);
|
UnexpectedTokenError(expectedNext);
|
||||||
NextToken;
|
NextToken;
|
||||||
TypeName;
|
TypeName;
|
||||||
myTypeSpec := typeSpec;
|
myTypeSpec := typeSpec;
|
||||||
@ -2867,13 +2870,13 @@ while token.kind in allowedTokens do begin
|
|||||||
unsignedsy,signedsy,intsy,longsy,charsy,shortsy,floatsy,doublesy,voidsy,
|
unsignedsy,signedsy,intsy,longsy,charsy,shortsy,floatsy,doublesy,voidsy,
|
||||||
compsy,extendedsy,_Boolsy: begin
|
compsy,extendedsy,_Boolsy: begin
|
||||||
if typeDone then
|
if typeDone then
|
||||||
Error(9)
|
UnexpectedTokenError(expectedNext)
|
||||||
else if token.kind in typeSpecifiers then begin
|
else if token.kind in typeSpecifiers then begin
|
||||||
if (token.kind = longsy)
|
if (token.kind = longsy)
|
||||||
and (typeSpecifiers <= [signedsy,unsignedsy,longsy,intsy]) then
|
and (typeSpecifiers <= [signedsy,unsignedsy,longsy,intsy]) then
|
||||||
Error(134)
|
Error(134)
|
||||||
else
|
else
|
||||||
Error(9);
|
UnexpectedTokenError(expectedNext);
|
||||||
end {if}
|
end {if}
|
||||||
else begin
|
else begin
|
||||||
typeSpecifiers := typeSpecifiers + [token.kind];
|
typeSpecifiers := typeSpecifiers + [token.kind];
|
||||||
@ -2889,7 +2892,7 @@ while token.kind in allowedTokens do begin
|
|||||||
|
|
||||||
enumsy: begin {enum}
|
enumsy: begin {enum}
|
||||||
if typeDone or (typeSpecifiers <> []) then
|
if typeDone or (typeSpecifiers <> []) then
|
||||||
Error(9);
|
UnexpectedTokenError(expectedNext);
|
||||||
NextToken; {skip the 'enum' token}
|
NextToken; {skip the 'enum' token}
|
||||||
if token.kind = ident then begin {handle a type definition}
|
if token.kind = ident then begin {handle a type definition}
|
||||||
variable := FindSymbol(token, tagSpace, true, true);
|
variable := FindSymbol(token, tagSpace, true, true);
|
||||||
@ -2959,7 +2962,7 @@ while token.kind in allowedTokens do begin
|
|||||||
structsy, {struct}
|
structsy, {struct}
|
||||||
unionsy: begin {union}
|
unionsy: begin {union}
|
||||||
if typeDone or (typeSpecifiers <> []) then
|
if typeDone or (typeSpecifiers <> []) then
|
||||||
Error(9);
|
UnexpectedTokenError(expectedNext);
|
||||||
globalStruct := false; {we didn't make it global}
|
globalStruct := false; {we didn't make it global}
|
||||||
if token.kind = structsy then {set the type kind to use}
|
if token.kind = structsy then {set the type kind to use}
|
||||||
tKind := structType
|
tKind := structType
|
||||||
@ -3358,7 +3361,7 @@ typeSpec := wordPtr; {default type specifier is an integer}
|
|||||||
{handle a TypeSpecifier/declarator}
|
{handle a TypeSpecifier/declarator}
|
||||||
if token.kind in declarationSpecifiersElement then
|
if token.kind in declarationSpecifiersElement then
|
||||||
typeFound := true;
|
typeFound := true;
|
||||||
DeclarationSpecifiers(declarationSpecifiersElement);
|
DeclarationSpecifiers(declarationSpecifiersElement, ident);
|
||||||
isPascal := pascalsy in functionSpecifiers;
|
isPascal := pascalsy in functionSpecifiers;
|
||||||
isAsm := asmsy in functionSpecifiers;
|
isAsm := asmsy in functionSpecifiers;
|
||||||
isInline := inlinesy in functionSpecifiers;
|
isInline := inlinesy in functionSpecifiers;
|
||||||
@ -3875,7 +3878,7 @@ var
|
|||||||
begin {TypeName}
|
begin {TypeName}
|
||||||
{read and process the type specifier}
|
{read and process the type specifier}
|
||||||
typeSpec := wordPtr;
|
typeSpec := wordPtr;
|
||||||
DeclarationSpecifiers(specifierQualifierListElement);
|
DeclarationSpecifiers(specifierQualifierListElement, rparench);
|
||||||
|
|
||||||
{handle the abstract-declarator part}
|
{handle the abstract-declarator part}
|
||||||
tl := nil; {no types so far}
|
tl := nil; {no types so far}
|
||||||
|
35
Scanner.pas
35
Scanner.pas
@ -111,6 +111,13 @@ procedure Error (err: integer);
|
|||||||
{ err - error number }
|
{ err - error number }
|
||||||
|
|
||||||
|
|
||||||
|
procedure UnexpectedTokenError (expectedToken: tokenEnum);
|
||||||
|
|
||||||
|
{ flag an error for an unexpected token }
|
||||||
|
{ }
|
||||||
|
{ expectedToken - what was expected }
|
||||||
|
|
||||||
|
|
||||||
procedure InitScanner (start, endPtr: ptr);
|
procedure InitScanner (start, endPtr: ptr);
|
||||||
|
|
||||||
{ initialize the scanner }
|
{ initialize the scanner }
|
||||||
@ -654,6 +661,7 @@ if list or (numErr <> 0) then begin
|
|||||||
137: msg := @'atomic types are not supported by ORCA/C';
|
137: msg := @'atomic types are not supported by ORCA/C';
|
||||||
138: msg := @'unsupported alignment';
|
138: msg := @'unsupported alignment';
|
||||||
139: msg := @'thread-local storage is not supported by ORCA/C';
|
139: msg := @'thread-local storage is not supported by ORCA/C';
|
||||||
|
140: msg := @'unexpected token';
|
||||||
otherwise: Error(57);
|
otherwise: Error(57);
|
||||||
end; {case}
|
end; {case}
|
||||||
writeln(msg^);
|
writeln(msg^);
|
||||||
@ -2975,6 +2983,33 @@ Error(err);
|
|||||||
end; {Error2}
|
end; {Error2}
|
||||||
|
|
||||||
|
|
||||||
|
procedure UnexpectedTokenError {expectedToken: tokenEnum};
|
||||||
|
|
||||||
|
{ flag an error for an unexpected token }
|
||||||
|
{ }
|
||||||
|
{ expectedToken - what was expected }
|
||||||
|
|
||||||
|
begin {UnexpectedTokenError}
|
||||||
|
case expectedToken of
|
||||||
|
ident: Error(9);
|
||||||
|
rparench: Error(12);
|
||||||
|
lparench: Error(13);
|
||||||
|
gtch: Error(15);
|
||||||
|
intconst: Error(18);
|
||||||
|
semicolonch: Error(22);
|
||||||
|
rbracech: Error(23);
|
||||||
|
rbrackch: Error(24);
|
||||||
|
lbracech: Error(27);
|
||||||
|
colonch: Error(29);
|
||||||
|
whilesy: Error(30);
|
||||||
|
stringconst: Error(83);
|
||||||
|
commach: Error(86);
|
||||||
|
dotch: Error(89);
|
||||||
|
otherwise: Error(140);
|
||||||
|
end; {case}
|
||||||
|
end; {UnexpectedTokenError}
|
||||||
|
|
||||||
|
|
||||||
procedure DoNumber {scanWork: boolean};
|
procedure DoNumber {scanWork: boolean};
|
||||||
|
|
||||||
{ The current character starts a number - scan it }
|
{ The current character starts a number - scan it }
|
||||||
|
Loading…
Reference in New Issue
Block a user