From 275e1f080b85b0bf335375a84f6cc5ab9031c364 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 1 Apr 2018 14:14:18 -0500 Subject: [PATCH] Add a new flag to control whether mixed declarations are allowed and C99 scope rules are used. #pragma ignore bit 4 (a value of 16) now controls these. It is on by default (allowing them), but turning it off will restore the C89 rules. --- Header.pas | 5 ++++- Parser.pas | 2 -- Scanner.pas | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Header.pas b/Header.pas index ed918cd..19f93a0 100644 --- a/Header.pas +++ b/Header.pas @@ -864,7 +864,8 @@ procedure EndInclude {chPtr: ptr}; WriteByte(ord(skipIllegalTokens) | (ord(allowLongIntChar) << 1) | (ord(allowTokensAfterEndif) << 2) - | (ord(allowSlashSlashComments) << 3)); + | (ord(allowSlashSlashComments) << 3) + | (ord(allowMixedDeclarations) << 4)); p_segment: begin for i := 1 to 10 do begin @@ -1499,6 +1500,8 @@ var allowLongIntChar := odd(i >> 1); allowTokensAfterEndif := odd(i >> 2); allowSlashSlashComments := odd(i >> 3); + allowMixedDeclarations := odd(i >> 4); + c99Scope := allowMixedDeclarations; end; p_segment: begin diff --git a/Parser.pas b/Parser.pas index 422ac1e..318e022 100644 --- a/Parser.pas +++ b/Parser.pas @@ -81,8 +81,6 @@ implementation const maxBitField = 32; {max # of bits in a bit field} - allowMixedDeclarations = true; - c99Scope = true; type diff --git a/Scanner.pas b/Scanner.pas index 0b13888..e6302ee 100644 --- a/Scanner.pas +++ b/Scanner.pas @@ -85,6 +85,9 @@ var allowSlashSlashComments: boolean; {allow // comments?} allowTokensAfterEndif: boolean; {allow tokens after #endif?} skipIllegalTokens: boolean; {skip flagging illegal tokens in skipped code?} + {Note: The following two are set together} + allowMixedDeclarations: boolean; {allow mixed declarations & stmts (C99)?} + c99Scope: boolean; {follow C99 rules for block scopes?} {---------------------------------------------------------------} @@ -613,6 +616,7 @@ if list or (numErr <> 0) then begin 123: msg := @'array element type may not be an incomplete or function type'; 124: msg := @'invalid format string'; 125: msg := @'format string is not a string literal'; + 126: msg := @'scope rules may not be changed within a function'; otherwise: Error(57); end; {case} writeln(msg^); @@ -2792,6 +2796,7 @@ if ch in ['a','d','e','i','l','p','u','w'] then begin { 2 - allow long int character constants } { 4 - allow tokens after #endif } { 8 - allow // comments } + { 16 - allow mixed decls & use C99 scope rules } FlagPragmas(p_ignore); NumericDirective; val := long(expressionValue).lsw; @@ -2799,6 +2804,13 @@ if ch in ['a','d','e','i','l','p','u','w'] then begin allowLongIntChar := odd(val >> 1); allowTokensAfterEndif := odd(val >> 2); allowSlashSlashComments := odd(val >> 3); + allowMixedDeclarations := odd(val >> 4); + if allowMixedDeclarations <> c99Scope then begin + if doingFunction then + Error(126) + else + c99Scope := allowMixedDeclarations; + end; {if} if token.kind <> eolsy then Error(11); end {else if} @@ -3371,6 +3383,8 @@ skipIllegalTokens := false; {flag illegal tokens in skipped code} allowLongIntChar := false; {allow long int char constants} allowTokensAfterEndif := false; {allow tokens after #endif} allowSlashSlashComments := true; {allow // comments} +allowMixedDeclarations := true; {allow mixed declarations & stmts (C99)} +c99Scope := true; {follow C99 rules for block scopes} foundFunction := false; {no functions found so far} fileList := nil; {no included files} gettingFileName := false; {not in GetFileName}