From dd9258511698f8238e22f39ff3200b7cc4b18212 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 19 Jan 2020 17:31:20 -0600 Subject: [PATCH] Give errors for most illegal uses of "restrict". --- Parser.pas | 20 ++++++++++++++++++-- Scanner.pas | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Parser.pas b/Parser.pas index 66975eb..14c6e59 100644 --- a/Parser.pas +++ b/Parser.pas @@ -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} diff --git a/Scanner.pas b/Scanner.pas index 14905f6..691b4b0 100644 --- a/Scanner.pas +++ b/Scanner.pas @@ -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^);