Give errors for most illegal uses of "restrict".

This commit is contained in:
Stephen Heumann 2020-01-19 17:31:20 -06:00
parent 49dea49cb8
commit dd92585116
2 changed files with 19 additions and 2 deletions

View File

@ -2864,6 +2864,10 @@ while token.kind in allowedTokens do begin
restrictsy: begin
myDeclarationModifiers := myDeclarationModifiers + [token.kind];
if typeDone or (typeSpecifiers <> []) then
if (myTypeSpec^.kind <> pointerType)
or (myTypeSpec^.pType^.kind = functionType) then
Error(143);
NextToken;
end;
@ -2896,6 +2900,10 @@ while token.kind in allowedTokens do begin
UnexpectedTokenError(expectedNext);
end {if}
else begin
if restrictsy in myDeclarationModifiers then begin
myDeclarationModifiers := myDeclarationModifiers - [restrictsy];
Error(143);
end; {if}
typeSpecifiers := typeSpecifiers + [token.kind];
ResolveType;
end; {else}
@ -2909,7 +2917,9 @@ while token.kind in allowedTokens do begin
enumsy: begin {enum}
if typeDone or (typeSpecifiers <> []) then
UnexpectedTokenError(expectedNext);
UnexpectedTokenError(expectedNext)
else if restrictsy in myDeclarationModifiers then
Error(143);
NextToken; {skip the 'enum' token}
if token.kind = ident then begin {handle a type definition}
variable := FindSymbol(token, tagSpace, true, true);
@ -2979,7 +2989,9 @@ while token.kind in allowedTokens do begin
structsy, {struct}
unionsy: begin {union}
if typeDone or (typeSpecifiers <> []) then
UnexpectedTokenError(expectedNext);
UnexpectedTokenError(expectedNext)
else if restrictsy in myDeclarationModifiers then
Error(143);
globalStruct := false; {we didn't make it global}
if token.kind = structsy then {set the type kind to use}
tKind := structType
@ -3066,6 +3078,10 @@ while token.kind in allowedTokens do begin
typedef: begin {named type definition}
if (typeSpecifiers = []) and not typeDone then begin
myTypeSpec := token.symbolPtr^.itype;
if restrictsy in myDeclarationModifiers then
if (myTypeSpec^.kind <> pointerType)
or (myTypeSpec^.pType^.kind = functionType) then
Error(143);
NextToken;
typeDone := true;
end {if}

View File

@ -664,6 +664,7 @@ if list or (numErr <> 0) then begin
140: msg := @'unexpected token';
141: msg := @'_Noreturn specifier is only allowed on functions';
142: msg := @'_Alignas may not be used in this declaration or type name';
143: msg := @'only object pointer types may be restrict-qualified';
otherwise: Error(57);
end; {case}
writeln(msg^);