From 9ecbd42c1a8caf05073b5945616d986522fd688a Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Wed, 28 Aug 2024 21:58:59 -0500 Subject: [PATCH] Recognize new C23 keywords as keywords (in C23 mode). They are recognized as keywords, but they currently don't do anything. --- CCommon.pas | 21 ++++--- Header.pas | 3 +- Scanner.pas | 56 ++++++++++++++---- Table.asm | 166 +++++++++++++++++++++++++++++++++++++++++++++------- Table.pas | 1 + 5 files changed, 203 insertions(+), 44 deletions(-) diff --git a/CCommon.pas b/CCommon.pas index 6ee870c..382c6ae 100644 --- a/CCommon.pas +++ b/CCommon.pas @@ -181,15 +181,18 @@ type ulonglongconst,floatconst,doubleconst,extendedconst,compconst, charconst,scharconst,ucharconst,ushortconst,stringconst, {reserved words} - _Alignassy,_Alignofsy,_Atomicsy,_Boolsy,_Complexsy, - _Genericsy,_Imaginarysy,_Noreturnsy,_Static_assertsy,_Thread_localsy, - autosy,asmsy,breaksy,casesy,charsy, - continuesy,constsy,compsy,defaultsy,dosy, - doublesy,elsesy,enumsy,externsy,extendedsy, - floatsy,forsy,gotosy,ifsy,intsy, - inlinesy,longsy,pascalsy,registersy,restrictsy, - returnsy,shortsy,sizeofsy,staticsy,structsy, - switchsy,segmentsy,signedsy,typedefsy,unionsy, + _Alignassy,_Alignofsy,_Atomicsy,_BitIntsy,_Boolsy, + _Complexsy,_Decimal128sy,_Decimal32sy,_Decimal64sy,_Genericsy, + _Imaginarysy,_Noreturnsy,_Static_assertsy,_Thread_localsy,alignassy, + alignofsy,autosy,asmsy,boolsy,breaksy, + casesy,charsy,continuesy,constsy,constexprsy, + compsy,defaultsy,dosy,doublesy,elsesy, + enumsy,externsy,extendedsy,falsesy,floatsy, + forsy,gotosy,ifsy,intsy,inlinesy, + longsy,nullptrsy,pascalsy,registersy,restrictsy, + returnsy,shortsy,sizeofsy,staticsy,static_assertsy, + structsy,switchsy,segmentsy,signedsy,thread_localsy, + truesy,typedefsy,typeofsy,typeof_unqualsy,unionsy, unsignedsy,voidsy,volatilesy,whilesy, {reserved symbols} excch,percentch,carotch,andch,asteriskch, diff --git a/Header.pas b/Header.pas index 26b5265..fb66f68 100644 --- a/Header.pas +++ b/Header.pas @@ -18,7 +18,7 @@ uses CCommon, MM, Scanner, Symbol, CGI; {$segment 'HEADER'} const - symFileVersion = 46; {version number of .sym file format} + symFileVersion = 47; {version number of .sym file format} var inhibitHeader: boolean; {should .sym includes be blocked?} @@ -1606,6 +1606,7 @@ var i := ReadByte; extendedKeywords := odd(i); extendedParameters := odd(i >> 1); + SetKeywordMask; end; otherwise: begin diff --git a/Scanner.pas b/Scanner.pas index e69d487..f6cba9e 100644 --- a/Scanner.pas +++ b/Scanner.pas @@ -83,6 +83,7 @@ var reportEOL: boolean; {report eolsy as a token?} token: tokenType; {next token to process} doingFakeFile: boolean; {processing tokens from fake "file" in memory?} + keywordMask: integer; {mask of keyword categories to enable} {#pragma ignore flags} {--------------------} @@ -177,6 +178,12 @@ procedure PutBackToken (var token: tokenType; expandEnabled: boolean; { suppressPrint - suppress printing with #pragma expand? } +procedure SetKeywordMask; + +{ Set the mask defining which keywords to recognize based on } +{ current language mode. } + + procedure TermScanner; { Shut down the scanner. } @@ -198,6 +205,12 @@ const RETURN = 13; {RETURN key code} VT = 11; {vertical tab} + {keyword categories} + {(also defined in Table.asm)} + c17keyword = 1; + c23keyword = 2; + orcacKeyword = 128; + {misc} {----} defaultName = '13:ORCACDefs:Defaults.h'; {default include file name} @@ -966,15 +979,18 @@ case token.kind of write('"'); end; - _Alignassy,_Alignofsy,_Atomicsy,_Boolsy,_Complexsy, - _Genericsy,_Imaginarysy,_Noreturnsy,_Static_assertsy,_Thread_localsy, - autosy,asmsy,breaksy,casesy,charsy, - continuesy,constsy,compsy,defaultsy,dosy, - doublesy,elsesy,enumsy,externsy,extendedsy, - floatsy,forsy,gotosy,ifsy,intsy, - inlinesy,longsy,pascalsy,registersy,restrictsy, - returnsy,shortsy,sizeofsy,staticsy,structsy, - switchsy,segmentsy,signedsy,typedefsy,unionsy, + _Alignassy,_Alignofsy,_Atomicsy,_BitIntsy,_Boolsy, + _Complexsy,_Decimal128sy,_Decimal32sy,_Decimal64sy,_Genericsy, + _Imaginarysy,_Noreturnsy,_Static_assertsy,_Thread_localsy,alignassy, + alignofsy,autosy,asmsy,boolsy,breaksy, + casesy,charsy,continuesy,constsy,constexprsy, + compsy,defaultsy,dosy,doublesy,elsesy, + enumsy,externsy,extendedsy,falsesy,floatsy, + forsy,gotosy,ifsy,intsy,inlinesy, + longsy,nullptrsy,pascalsy,registersy,restrictsy, + returnsy,shortsy,sizeofsy,staticsy,static_assertsy, + structsy,switchsy,segmentsy,signedsy,thread_localsy, + truesy,typedefsy,typeofsy,typeof_unqualsy,unionsy, unsignedsy,voidsy,volatilesy,whilesy: write(reservedWords[token.kind]); @@ -3623,6 +3639,7 @@ if ch in ['a','d','e','i','l','p','u','w'] then begin val := long(expressionValue).lsw; extendedKeywords := odd(val); extendedParameters := odd(val >> 1); + SetKeywordMask; if token.kind <> eolsy then Error(11); end {else if} @@ -4953,9 +4970,25 @@ if strictMode then begin mp^.next := bp^; bp^ := mp; end; {if} +SetKeywordMask; end; {InitScanner} +procedure SetKeywordMask; + +{ Set the mask defining which keywords to recognize based on } +{ current language mode. } + +begin {SetKeywordMask} +if cStd >= c23 then + keywordMask := c23keyword +else + keywordMask := c17keyword; +if extendedKeywords then + keywordMask := keywordMask | orcacKeyword; +end; {SetKeywordMask} + + procedure CheckIdentifier; { See if an identifier is a reserved word, macro or typedef } @@ -4982,12 +5015,11 @@ if expandMacros then {handle macro expansions} end; end; {if} {see if it's a reserved word} -if workString[1] in ['_','a'..'g','i','l','p','r'..'w'] then +if workString[1] in ['_','a'..'g','i','l','n','p','r'..'w'] then for rword := wordHash[ord(workString[1])-ord('_')] to pred(wordHash[ord(succ(workString[1]))-ord('_')]) do if reservedWords[rword] = workString then - if extendedKeywords or not (rword in - [asmsy,compsy,extendedsy,pascalsy,segmentsy]) then begin + if (keywordCategories[rword] & keywordMask) <> 0 then begin token.kind := rword; token.class := reservedWord; goto 1; diff --git a/Table.asm b/Table.asm index ab47857..1a2ddc2 100644 --- a/Table.asm +++ b/Table.asm @@ -288,15 +288,18 @@ charSym start single character symbols enum (ulonglongconst,floatconst,doubleconst,extendedconst,compconst) enum (charconst,scharconst,ucharconst,ushortconst,stringconst) ! reserved words - enum (_Alignassy,_Alignofsy,_Atomicsy,_Boolsy,_Complexsy) - enum (_Genericsy,_Imaginarysy,_Noreturnsy,_Static_assertsy,_Thread_localsy) - enum (autosy,asmsy,breaksy,casesy,charsy) - enum (continuesy,constsy,compsy,defaultsy,dosy) - enum (doublesy,elsesy,enumsy,externsy,extendedsy) - enum (floatsy,forsy,gotosy,ifsy,intsy) - enum (inlinesy,longsy,pascalsy,registersy,restrictsy) - enum (returnsy,shortsy,sizeofsy,staticsy,structsy) - enum (switchsy,segmentsy,signedsy,typedefsy,unionsy) + enum (_Alignassy,_Alignofsy,_Atomicsy,_BitIntsy,_Boolsy) + enum (_Complexsy,_Decimal128sy,_Decimal32sy,_Decimal64sy,_Genericsy) + enum (_Imaginarysy,_Noreturnsy,_Static_assertsy,_Thread_localsy,alignassy) + enum (alignofsy,autosy,asmsy,boolsy,breaksy) + enum (casesy,charsy,continuesy,constsy,constexprsy) + enum (compsy,defaultsy,dosy,doublesy,elsesy) + enum (enumsy,externsy,extendedsy,falsesy,floatsy) + enum (forsy,gotosy,ifsy,intsy,inlinesy) + enum (longsy,nullptrsy,pascalsy,registersy,restrictsy) + enum (returnsy,shortsy,sizeofsy,staticsy,static_assertsy) + enum (structsy,switchsy,segmentsy,signedsy,thread_localsy) + enum (truesy,typedefsy,typeofsy,typeof_unqualsy,unionsy) enum (unsignedsy,voidsy,volatilesy,whilesy) ! reserved symbols enum (excch,percentch,carotch,andch,asteriskch) @@ -374,20 +377,28 @@ icp start in-coming priority for expression dc i1'200' _Alignassy dc i1'16' _Alignofsy dc i1'200' _Atomicsy + dc i1'200' _BitInt dc i1'200' _Boolsy dc i1'200' _Complexsy + dc i1'200' _Decimal128sy + dc i1'200' _Decimal32sy + dc i1'200' _Decimal64sy dc i1'200' _Genericsy dc i1'200' _Imaginarysy dc i1'200' _Noreturnsy dc i1'200' _Static_assertsy dc i1'200' _Thread_localsy + dc i1'200' alignassy + dc i1'16' alignofsy dc i1'200' autosy dc i1'200' asmsy + dc i1'200' boolsy dc i1'200' breaksy dc i1'200' casesy dc i1'200' charsy dc i1'200' continuesy dc i1'200' constsy + dc i1'200' constexprsy dc i1'200' compsy dc i1'200' defaultsy dc i1'200' dosy @@ -396,6 +407,7 @@ icp start in-coming priority for expression dc i1'200' enumsy dc i1'200' externsy dc i1'200' extendedsy + dc i1'200' falsesy dc i1'200' floatsy dc i1'200' forsy dc i1'200' gotosy @@ -403,6 +415,7 @@ icp start in-coming priority for expression dc i1'200' intsy dc i1'200' inlinesy dc i1'200' longsy + dc i1'200' nullptrsy dc i1'200' pascalsy dc i1'200' registersy dc i1'200' restrictsy @@ -410,11 +423,16 @@ icp start in-coming priority for expression dc i1'200' shortsy dc i1'16' sizeofsy dc i1'200' staticsy + dc i1'200' static_assertsy dc i1'200' structsy dc i1'200' switchsy dc i1'200' segmentsy dc i1'200' signedsy + dc i1'200' thread_localsy + dc i1'200' truesy dc i1'200' typedefsy + dc i1'200' typeofsy + dc i1'200' typeof_unqualsy dc i1'200' unionsy dc i1'200' unsignedsy dc i1'200' voidsy @@ -553,20 +571,28 @@ isp start in stack priority for expression dc i1'0' _Alignassy dc i1'16' _Alignofsy dc i1'0' _Atomicsy + dc i1'0' _BitIntsy dc i1'0' _Boolsy dc i1'0' _Complexsy + dc i1'0' _Decimal128sy + dc i1'0' _Decimal32sy + dc i1'0' _Decimal64sy dc i1'0' _Genericsy dc i1'0' _Imaginarysy dc i1'0' _Noreturnsy dc i1'0' _Static_assertsy dc i1'0' _Thread_localsy + dc i1'0' alignassy + dc i1'16' alignofsy dc i1'0' autosy dc i1'0' asmsy + dc i1'0' boolsy dc i1'0' breaksy dc i1'0' casesy dc i1'0' charsy dc i1'0' continuesy dc i1'0' constsy + dc i1'0' constexprsy dc i1'0' compsy dc i1'0' defaultsy dc i1'0' dosy @@ -575,6 +601,7 @@ isp start in stack priority for expression dc i1'0' enumsy dc i1'0' externsy dc i1'0' extendedsy + dc i1'0' falsesy dc i1'0' floatsy dc i1'0' forsy dc i1'0' gotosy @@ -582,6 +609,7 @@ isp start in stack priority for expression dc i1'0' intsy dc i1'0' inlinesy dc i1'0' longsy + dc i1'0' nullptrsy dc i1'0' pascalsy dc i1'0' registersy dc i1'0' restrictsy @@ -589,11 +617,16 @@ isp start in stack priority for expression dc i1'0' shortsy dc i1'16' sizeofsy dc i1'0' staticsy + dc i1'0' static_assertsy dc i1'0' structsy dc i1'0' switchsy dc i1'0' segmentsy dc i1'0' signedsy + dc i1'0' thread_localsy + dc i1'0' truesy dc i1'0' typedefsy + dc i1'0' typeofsy + dc i1'0' typeof_unqualsy dc i1'0' unionsy dc i1'0' unsignedsy dc i1'0' voidsy @@ -858,20 +891,28 @@ reservedWords start reserved word names str14 _Alignas str14 _Alignof str14 _Atomic + str14 _BitInt str14 _Bool str14 _Complex + str14 _Decimal128 + str14 _Decimal32 + str14 _Decimal64 str14 _Generic str14 _Imaginary str14 _Noreturn str14 _Static_assert str14 _Thread_local + str14 alignas + str14 alignof str14 auto str14 asm + str14 bool str14 break str14 case str14 char str14 continue str14 const + str14 constexpr str14 comp str14 default str14 do @@ -880,6 +921,7 @@ reservedWords start reserved word names str14 enum str14 extern str14 extended + str14 false str14 float str14 for str14 goto @@ -887,6 +929,7 @@ reservedWords start reserved word names str14 int str14 inline str14 long + str14 nullptr str14 pascal str14 register str14 restrict @@ -894,11 +937,16 @@ reservedWords start reserved word names str14 short str14 sizeof str14 static + str14 static_assert str14 struct str14 switch str14 segment str14 signed + str14 thread_local + str14 true str14 typedef + str14 typeof + str14 typeof_unqual str14 union str14 unsigned str14 void @@ -906,6 +954,77 @@ reservedWords start reserved word names str14 while end +keywordCategories start keyword categories +c17keyword equ 1 +c23keyword equ 2 +orcacKeyword equ 128 + + dc i1'c17keyword+c23keyword' _Alignas + dc i1'c17keyword+c23keyword' _Alignof + dc i1'c17keyword+c23keyword' _Atomic + dc i1'c23keyword' _BitInt + dc i1'c17keyword+c23keyword' _Bool + dc i1'c17keyword+c23keyword' _Complex + dc i1'c23keyword' _Decimal128 + dc i1'c23keyword' _Decimal32 + dc i1'c23keyword' _Decimal64 + dc i1'c17keyword+c23keyword' _Generic + dc i1'c17keyword+c23keyword' _Imaginary + dc i1'c17keyword+c23keyword' _Noreturn + dc i1'c17keyword+c23keyword' _Static_assert + dc i1'c17keyword+c23keyword' _Thread_local + dc i1'c23keyword' alignas + dc i1'c23keyword' alignof + dc i1'c17keyword+c23keyword' auto + dc i1'orcacKeyword' asm + dc i1'c23keyword' bool + dc i1'c17keyword+c23keyword' break + dc i1'c17keyword+c23keyword' case + dc i1'c17keyword+c23keyword' char + dc i1'c17keyword+c23keyword' continue + dc i1'c17keyword+c23keyword' const + dc i1'c23keyword' constexpr + dc i1'orcacKeyword' comp + dc i1'c17keyword+c23keyword' default + dc i1'c17keyword+c23keyword' do + dc i1'c17keyword+c23keyword' double + dc i1'c17keyword+c23keyword' else + dc i1'c17keyword+c23keyword' enum + dc i1'c17keyword+c23keyword' extern + dc i1'orcacKeyword' extended + dc i1'c23keyword' false + dc i1'c17keyword+c23keyword' float + dc i1'c17keyword+c23keyword' for + dc i1'c17keyword+c23keyword' goto + dc i1'c17keyword+c23keyword' if + dc i1'c17keyword+c23keyword' int + dc i1'c17keyword+c23keyword+orcacKeyword' inline + dc i1'c17keyword+c23keyword' long + dc i1'c23keyword' nullptr + dc i1'orcacKeyword' pascal + dc i1'c17keyword+c23keyword' register + dc i1'c17keyword+c23keyword' restrict + dc i1'c17keyword+c23keyword' return + dc i1'c17keyword+c23keyword' short + dc i1'c17keyword+c23keyword' sizeof + dc i1'c17keyword+c23keyword' static + dc i1'c23keyword' static_assert + dc i1'c17keyword+c23keyword' struct + dc i1'c17keyword+c23keyword' switch + dc i1'orcacKeyword' segment + dc i1'c17keyword+c23keyword' signed + dc i1'c23keyword' thread_local + dc i1'c23keyword' true + dc i1'c17keyword+c23keyword' typedef + dc i1'c23keyword' typeof + dc i1'c23keyword' typeof_unqual + dc i1'c17keyword+c23keyword' union + dc i1'c17keyword+c23keyword' unsigned + dc i1'c17keyword+c23keyword' void + dc i1'c17keyword+c23keyword' volatile + dc i1'c17keyword+c23keyword' while + end + ropcodes start dc i1'$90' bcc @@ -929,22 +1048,25 @@ wordHash start reserved word hash table enum (ulonglongconst,floatconst,doubleconst,extendedconst,compconst) enum (charconst,scharconst,ucharconst,ushortconst,stringconst) ! reserved words - enum (_Alignassy,_Alignofsy,_Atomicsy,_Boolsy,_Complexsy) - enum (_Genericsy,_Imaginarysy,_Noreturnsy,_Static_assertsy,_Thread_localsy) - enum (autosy,asmsy,breaksy,casesy,charsy) - enum (continuesy,constsy,compsy,defaultsy,dosy) - enum (doublesy,elsesy,enumsy,externsy,extendedsy) - enum (floatsy,forsy,gotosy,ifsy,intsy) - enum (inlinesy,longsy,pascalsy,registersy,restrictsy) - enum (returnsy,shortsy,sizeofsy,staticsy,structsy) - enum (switchsy,segmentsy,signedsy,typedefsy,unionsy) + enum (_Alignassy,_Alignofsy,_Atomicsy,_BitIntsy,_Boolsy) + enum (_Complexsy,_Decimal128sy,_Decimal32sy,_Decimal64sy,_Genericsy) + enum (_Imaginarysy,_Noreturnsy,_Static_assertsy,_Thread_localsy,alignassy) + enum (alignofsy,autosy,asmsy,boolsy,breaksy) + enum (casesy,charsy,continuesy,constsy,constexprsy) + enum (compsy,defaultsy,dosy,doublesy,elsesy) + enum (enumsy,externsy,extendedsy,falsesy,floatsy) + enum (forsy,gotosy,ifsy,intsy,inlinesy) + enum (longsy,nullptrsy,pascalsy,registersy,restrictsy) + enum (returnsy,shortsy,sizeofsy,staticsy,static_assertsy) + enum (structsy,switchsy,segmentsy,signedsy,thread_localsy) + enum (truesy,typedefsy,typeofsy,typeof_unqualsy,unionsy) enum (unsignedsy,voidsy,volatilesy,whilesy,succwhilesy) - dc i'_Alignassy,autosy' - dc i'autosy,breaksy,casesy,defaultsy,elsesy,floatsy' + dc i'_Alignassy,alignassy' + dc i'alignassy,boolsy,casesy,defaultsy,elsesy,falsesy' dc i'gotosy,ifsy,ifsy,longsy,longsy,longsy' - dc i'pascalsy,pascalsy,pascalsy,pascalsy,registersy,registersy' - dc i'shortsy,typedefsy,unionsy,voidsy,whilesy,succwhilesy' + dc i'nullptrsy,nullptrsy,pascalsy,pascalsy,registersy,registersy' + dc i'shortsy,thread_localsy,unionsy,voidsy,whilesy,succwhilesy' end stdcVersion start __STDC_VERSION__ values diff --git a/Table.pas b/Table.pas index d450331..a75f768 100644 --- a/Table.pas +++ b/Table.pas @@ -21,6 +21,7 @@ var charKinds: array[minChar..maxChar] of charEnum; {character kinds} charSym: array[minChar..maxChar] of tokenEnum; {symbols for single char symbols} reservedWords: array[_Alignassy..whilesy] of string[14]; {reserved word strings} + keywordCategories: array[_Alignassy..whilesy] of byte; {keyword categories} wordHash: array[0..25] of tokenEnum; {for hashing reserved words} stdcVersion: array[c95..c23] of longint; {__STDC_VERSION__ values}