diff options
Diffstat (limited to 'source/compiler/prscan.c')
-rw-r--r-- | source/compiler/prscan.c | 160 |
1 files changed, 135 insertions, 25 deletions
diff --git a/source/compiler/prscan.c b/source/compiler/prscan.c index 47f772ff33d2..393d80149fb1 100644 --- a/source/compiler/prscan.c +++ b/source/compiler/prscan.c @@ -67,6 +67,14 @@ PrDoDirective ( char *DirectiveToken, char **Next); +static void +PrGetNextLineInit ( + void); + +static UINT32 +PrGetNextLine ( + FILE *Handle); + static int PrMatchDirective ( char *Directive); @@ -186,7 +194,7 @@ PrInitializeGlobals ( /* Init globals */ Gbl_InputFileList = NULL; - Gbl_CurrentLineNumber = 0; + Gbl_CurrentLineNumber = 1; Gbl_PreprocessorLineNumber = 1; Gbl_PreprocessorError = FALSE; @@ -271,7 +279,7 @@ PrDoPreprocess ( } while (MoreInputFiles); - /* Point compiler input to the new preprocessor output file (.i) */ + /* Point compiler input to the new preprocessor output file (.pre) */ FlCloseFile (ASL_FILE_INPUT); Gbl_Files[ASL_FILE_INPUT].Handle = Gbl_Files[ASL_FILE_PREPROCESSOR].Handle; @@ -280,7 +288,10 @@ PrDoPreprocess ( /* Reset globals to allow compiler to run */ FlSeekFile (ASL_FILE_INPUT, 0); - Gbl_CurrentLineNumber = 1; + if (!Gbl_PreprocessOnly) + { + Gbl_CurrentLineNumber = 0; + } DbgPrint (ASL_DEBUG_OUTPUT, "Preprocessing phase complete \n\n"); } @@ -297,7 +308,8 @@ PrDoPreprocess ( * DESCRIPTION: Preprocess one entire file, line-by-line. * * Input: Raw user ASL from ASL_FILE_INPUT - * Output: Preprocessed file written to ASL_FILE_PREPROCESSOR + * Output: Preprocessed file written to ASL_FILE_PREPROCESSOR and + * (optionally) ASL_FILE_PREPROCESSOR_USER * ******************************************************************************/ @@ -305,7 +317,7 @@ static void PrPreprocessInputFile ( void) { - UINT32 Offset; + UINT32 Status; char *Token; char *ReplaceString; PR_DEFINE_INFO *DefineInfo; @@ -314,10 +326,21 @@ PrPreprocessInputFile ( int OffsetAdjust; + PrGetNextLineInit (); + /* Scan line-by-line. Comments and blank lines are skipped by this function */ - while ((Offset = DtGetNextLine (Gbl_Files[ASL_FILE_INPUT].Handle)) != ASL_EOF) + while ((Status = PrGetNextLine (Gbl_Files[ASL_FILE_INPUT].Handle)) != ASL_EOF) { + Gbl_CurrentLineNumber++; + Gbl_LogicalLineNumber++; + + if ((Status == ASL_WITHIN_COMMENT) || + (Status == ASL_BLANK_LINE)) + { + goto WriteEntireLine; + } + /* Need a copy of the input line for strok() */ strcpy (Gbl_MainTokenBuffer, Gbl_CurrentLineBuffer); @@ -397,24 +420,13 @@ PrPreprocessInputFile ( Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next); } - /* - * Emit a #line directive if necessary, to keep the line numbers in - * the (.i) file synchronized with the original source code file, so - * that the correct line number appears in any error messages - * generated by the actual compiler. - */ - if (Gbl_CurrentLineNumber > (Gbl_PreviousLineNumber + 1)) - { - FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u\n", - Gbl_CurrentLineNumber); - } - - Gbl_PreviousLineNumber = Gbl_CurrentLineNumber; Gbl_PreprocessorLineNumber++; + +WriteEntireLine: /* * Now we can write the possibly modified source line to the - * preprocessor (.i) file + * preprocessor file(s). */ FlWriteFile (ASL_FILE_PREPROCESSOR, Gbl_CurrentLineBuffer, strlen (Gbl_CurrentLineBuffer)); @@ -654,7 +666,7 @@ PrDoDirective ( { #ifndef MACROS_SUPPORTED AcpiOsPrintf ("%s ERROR - line %u: #define macros are not supported yet\n", - Gbl_CurrentLineBuffer, Gbl_CurrentLineNumber); + Gbl_CurrentLineBuffer, Gbl_LogicalLineNumber); exit(1); #else PrAddMacro (Token, Next); @@ -691,7 +703,7 @@ PrDoDirective ( #endif DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID "New #define: %s->%s\n", - Gbl_CurrentLineNumber, Token, Token2); + Gbl_LogicalLineNumber, Token, Token2); PrAddDefine (Token, Token2, FALSE); } @@ -760,10 +772,7 @@ PrDoDirective ( "User #line invocation %s\n", Gbl_CurrentLineNumber, Token); - /* Update local line numbers */ - Gbl_CurrentLineNumber = (UINT32) Value; - Gbl_PreviousLineNumber = 0; /* Emit #line into the preprocessor file */ @@ -839,6 +848,107 @@ SyntaxError: /******************************************************************************* * + * FUNCTION: PrGetNextLine, PrGetNextLineInit + * + * PARAMETERS: Handle - Open file handle for the source file + * + * RETURN: Status of the GetLine operation: + * AE_OK - Normal line, OK status + * ASL_WITHIN_COMMENT - Line is part of a multi-line comment + * ASL_EOF - End-of-file reached + * + * DESCRIPTION: Get the next text line from the input file. Does not strip + * comments. + * + ******************************************************************************/ + +#define PR_NORMAL_TEXT 0 +#define PR_WITHIN_COMMENT 1 + +static UINT8 AcpiGbl_LineScanState = PR_NORMAL_TEXT; + +static void +PrGetNextLineInit ( + void) +{ + AcpiGbl_LineScanState = 0; +} + +static UINT32 +PrGetNextLine ( + FILE *Handle) +{ + UINT32 i; + int c = 0; + int PreviousChar; + + + /* Always clear the global line buffer */ + + memset (Gbl_CurrentLineBuffer, 0, Gbl_LineBufferSize); + for (i = 0; ;) + { + /* + * If line is too long, expand the line buffers. Also increases + * Gbl_LineBufferSize. + */ + if (i >= Gbl_LineBufferSize) + { + UtExpandLineBuffers (); + } + + PreviousChar = c; + c = getc (Handle); + if (c == EOF) + { + return (ASL_EOF); + } + + /* We need to worry about multi-line slash-asterisk comments */ + + /* Check for comment open */ + + if ((AcpiGbl_LineScanState == PR_NORMAL_TEXT) && + (PreviousChar == '/') && (c == '*')) + { + AcpiGbl_LineScanState = PR_WITHIN_COMMENT; + } + + /* Check for comment close */ + + if ((AcpiGbl_LineScanState == PR_WITHIN_COMMENT) && + (PreviousChar == '*') && (c == '/')) + { + AcpiGbl_LineScanState = PR_NORMAL_TEXT; + } + + /* Always copy the character into line buffer */ + + Gbl_CurrentLineBuffer[i] = (char) c; + i++; + + /* Always exit on end-of-line */ + + if (c == '\n') + { + /* Handle multi-line comments */ + + if (AcpiGbl_LineScanState == PR_WITHIN_COMMENT) + { + return (ASL_WITHIN_COMMENT); + } + if (i == 1) + { + return (ASL_BLANK_LINE); + } + return (AE_OK); + } + } +} + + +/******************************************************************************* + * * FUNCTION: PrMatchDirective * * PARAMETERS: Directive - Pointer to directive name token |