Top Prev Next Up Down

CCompile preprocessor

In this release of ADA without 21-bit constant support we have to choose between

  1. Write the constant (constant CFix:=(CodePoint'Val(16#53#),CodePoint'Val(16#4F#),CodePoint'Val(16#55#),CodePoint'Val(16#52#),CodePoint'Val(16#43#),CodePoint'Val(16#45#));
    )
  2. Use at run-time a conversion UTF.To21("SOURCE")
  3. Run the preprocessor CCompile 

for the "SOURCE"c value.

What is it

Based on the input there are three different possibilities of how a ?-SECT file can be generated    
  1. package name_PSECT is to be generated, a procedure definition is found (CODE_PROCEDURE)
  2. package name_HSECT is to be generated, a package definition is found without 'body' term (CODE_PACKAGEHEAD)
  3. package name_BSECT is to be generated, a package definition is found with the 'body' term (CODE_PACKAGEBODY)
If a need exists for a ?-SECT file then one of these is generated with the named constants. The secret about the "-- with DSECT;" comment is that the preprocessor has to insert one new line in the original code for the with-statement needed to reference ?-SECT generated ads-file. This will disturb the line number in most raise-statemets. The  "-- with DSECT;" comment reserves a place for this with-statement in the original code and the problem with the line numbering is solved.

How to replace

The preprocessor uses backslash as first character in a Meta character sequence for replacing values \b (BS), \f (FF), \n (LF), \d (CR) and \t (HT or TAB) and hexadecimal values in 'Codepoint'-strings by writing \xHH, \uHHHH or \vHHHHHH (where 'H' stands for a hexadecimal digit 0123456789ABCDEF). But we have to escape backslash (\) with an extra backslash.
By applying following pattern to every line the preprocessor retrieves what to replace

001| patternLineSimple_C:constant CFix:=Y2018.Text.Core.UTF.To21(
002| __"^(.*?)(" &
003| __"--|" & --[U1]
004| __"""(?:[^""]|"""")*"".|" & --[U2]
005| __"'\\[BFNRT]'C|" & --[U13] <<
006| __"'.'C" & --[U3] <<
007| __")");

if none of these is found then copy the line as it is to output.
if [U1] is found then copy the line to output. if [U2] is found check for the 'c' or 'C', if not found copy what has been found to output and apply pattern again to the line. If 'c' or 'C' is found then we have a CFix constant and a constant should be generated in corresponding ?-SECT file and the name of the constant should be replaced here in output. If U3 or U13 replace the value with CodePoint'Val() value, and apply pattern again to the line.
If no CFix constant is found then the output is complete and no generated ?-SECT file is generated for this code file.

Examples