Home | History | Annotate | Line # | Download | only in compiler
dtcompilerparser.l revision 1.1.1.3.4.2
      1  1.1.1.3.4.2  martin %{
      2  1.1.1.3.4.2  martin /******************************************************************************
      3  1.1.1.3.4.2  martin  *
      4  1.1.1.3.4.2  martin  * Module Name: dtcompilerparser.l - Flex input file for table compiler lexer
      5  1.1.1.3.4.2  martin  *
      6  1.1.1.3.4.2  martin  *****************************************************************************/
      7  1.1.1.3.4.2  martin 
      8  1.1.1.3.4.2  martin /*
      9  1.1.1.3.4.2  martin  * Copyright (C) 2000 - 2020, Intel Corp.
     10  1.1.1.3.4.2  martin  * All rights reserved.
     11  1.1.1.3.4.2  martin  *
     12  1.1.1.3.4.2  martin  * Redistribution and use in source and binary forms, with or without
     13  1.1.1.3.4.2  martin  * modification, are permitted provided that the following conditions
     14  1.1.1.3.4.2  martin  * are met:
     15  1.1.1.3.4.2  martin  * 1. Redistributions of source code must retain the above copyright
     16  1.1.1.3.4.2  martin  *    notice, this list of conditions, and the following disclaimer,
     17  1.1.1.3.4.2  martin  *    without modification.
     18  1.1.1.3.4.2  martin  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     19  1.1.1.3.4.2  martin  *    substantially similar to the "NO WARRANTY" disclaimer below
     20  1.1.1.3.4.2  martin  *    ("Disclaimer") and any redistribution must be conditioned upon
     21  1.1.1.3.4.2  martin  *    including a substantially similar Disclaimer requirement for further
     22  1.1.1.3.4.2  martin  *    binary redistribution.
     23  1.1.1.3.4.2  martin  * 3. Neither the names of the above-listed copyright holders nor the names
     24  1.1.1.3.4.2  martin  *    of any contributors may be used to endorse or promote products derived
     25  1.1.1.3.4.2  martin  *    from this software without specific prior written permission.
     26  1.1.1.3.4.2  martin  *
     27  1.1.1.3.4.2  martin  * Alternatively, this software may be distributed under the terms of the
     28  1.1.1.3.4.2  martin  * GNU General Public License ("GPL") version 2 as published by the Free
     29  1.1.1.3.4.2  martin  * Software Foundation.
     30  1.1.1.3.4.2  martin  *
     31  1.1.1.3.4.2  martin  * NO WARRANTY
     32  1.1.1.3.4.2  martin  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     33  1.1.1.3.4.2  martin  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     34  1.1.1.3.4.2  martin  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     35  1.1.1.3.4.2  martin  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     36  1.1.1.3.4.2  martin  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  1.1.1.3.4.2  martin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  1.1.1.3.4.2  martin  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  1.1.1.3.4.2  martin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     40  1.1.1.3.4.2  martin  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     41  1.1.1.3.4.2  martin  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     42  1.1.1.3.4.2  martin  * POSSIBILITY OF SUCH DAMAGES.
     43  1.1.1.3.4.2  martin  */
     44  1.1.1.3.4.2  martin 
     45  1.1.1.3.4.2  martin #include "aslcompiler.h"
     46  1.1.1.3.4.2  martin #include "dtcompilerparser.y.h"
     47  1.1.1.3.4.2  martin 
     48  1.1.1.3.4.2  martin 
     49  1.1.1.3.4.2  martin #define _COMPONENT          ACPI_COMPILER
     50  1.1.1.3.4.2  martin         ACPI_MODULE_NAME    ("dtcompilerscanner")
     51  1.1.1.3.4.2  martin 
     52  1.1.1.3.4.2  martin /* handle locations */
     53  1.1.1.3.4.2  martin 
     54  1.1.1.3.4.2  martin int DtCompilerParsercolumn = 1;
     55  1.1.1.3.4.2  martin int DtLabelByteOffset = 0;
     56  1.1.1.3.4.2  martin int DtCompilerParserByteOffset = 0;
     57  1.1.1.3.4.2  martin 
     58  1.1.1.3.4.2  martin UINT32 DtTokenFirstLine = 0;
     59  1.1.1.3.4.2  martin UINT32 DtTokenFirstColumn = 0;
     60  1.1.1.3.4.2  martin 
     61  1.1.1.3.4.2  martin #define YY_USER_ACTION \
     62  1.1.1.3.4.2  martin             DtTokenFirstLine = DtCompilerParserlineno; \
     63  1.1.1.3.4.2  martin             DtTokenFirstColumn = DtCompilerParsercolumn; \
     64  1.1.1.3.4.2  martin             DtCompilerParsercolumn += DtCompilerParserleng; \
     65  1.1.1.3.4.2  martin             DtCompilerParserByteOffset += DtCompilerParserleng; \
     66  1.1.1.3.4.2  martin             DbgPrint (ASL_PARSE_OUTPUT,\
     67  1.1.1.3.4.2  martin                 "user action occurred. DtCompilerParserlloc.first_line: %u\n",\
     68  1.1.1.3.4.2  martin                 DtTokenFirstLine);
     69  1.1.1.3.4.2  martin %}
     70  1.1.1.3.4.2  martin 
     71  1.1.1.3.4.2  martin %option nounput noinput yylineno
     72  1.1.1.3.4.2  martin 
     73  1.1.1.3.4.2  martin     /* Indicates a state used for parsing multiline C comments */
     74  1.1.1.3.4.2  martin %x ML_COMMENT
     75  1.1.1.3.4.2  martin %x DATA_STATE
     76  1.1.1.3.4.2  martin 
     77  1.1.1.3.4.2  martin WhiteSpace      [ \t\v\r]+
     78  1.1.1.3.4.2  martin NewLines        [\n]+
     79  1.1.1.3.4.2  martin 
     80  1.1.1.3.4.2  martin     /* Avoid ", \n, and [] as a part of label name. These are not valid characters of a label name */
     81  1.1.1.3.4.2  martin LabelName       [^ ":\n\[\]]([^":\n\[\]]*[^" :\n\[\]])?
     82  1.1.1.3.4.2  martin 
     83  1.1.1.3.4.2  martin     /* Avoid ", \n, \\, and [] as a part of data. These are not valid characters of data */
     84  1.1.1.3.4.2  martin Data            [^ \\":\n\[\]]([^":\n\[\]\\]*[^" :\n\[\]\\])?
     85  1.1.1.3.4.2  martin 
     86  1.1.1.3.4.2  martin Text            [^ ":\n][^":\n]*
     87  1.1.1.3.4.2  martin Comment         \[[^\n\[\]]*\]
     88  1.1.1.3.4.2  martin CommentField    {LabelName}{WhiteSpace}*:{WhiteSpace}{Comment}?$
     89  1.1.1.3.4.2  martin 
     90  1.1.1.3.4.2  martin 
     91  1.1.1.3.4.2  martin %%
     92  1.1.1.3.4.2  martin 
     93  1.1.1.3.4.2  martin <DATA_STATE>{WhiteSpace}"\\\n" {
     94  1.1.1.3.4.2  martin         DbgPrint(ASL_PARSE_OUTPUT,"Continuation matched\n");
     95  1.1.1.3.4.2  martin         return (DT_PARSEOP_LINE_CONTINUATION);
     96  1.1.1.3.4.2  martin     }
     97  1.1.1.3.4.2  martin 
     98  1.1.1.3.4.2  martin ":" {
     99  1.1.1.3.4.2  martin         DbgPrint(ASL_PARSE_OUTPUT, ": Matched\n");
    100  1.1.1.3.4.2  martin         BEGIN (DATA_STATE);
    101  1.1.1.3.4.2  martin         return (':');
    102  1.1.1.3.4.2  martin     }
    103  1.1.1.3.4.2  martin 
    104  1.1.1.3.4.2  martin <INITIAL,DATA_STATE>{WhiteSpace} { DbgPrint(ASL_PARSE_OUTPUT,"Whitespace matched\n"); }
    105  1.1.1.3.4.2  martin 
    106  1.1.1.3.4.2  martin <INITIAL,DATA_STATE>{Comment}    { DbgPrint(ASL_PARSE_OUTPUT,"Comment matched\n"); }
    107  1.1.1.3.4.2  martin 
    108  1.1.1.3.4.2  martin "/*"                     { BEGIN (ML_COMMENT); }
    109  1.1.1.3.4.2  martin <ML_COMMENT>"*/"         { BEGIN (INITIAL); }
    110  1.1.1.3.4.2  martin <ML_COMMENT>"*/\n"       { BEGIN (INITIAL); }
    111  1.1.1.3.4.2  martin <ML_COMMENT>([^*]|\n)+|. /* Ignore */
    112  1.1.1.3.4.2  martin "//".*                   /* Ignore */
    113  1.1.1.3.4.2  martin 
    114  1.1.1.3.4.2  martin 
    115  1.1.1.3.4.2  martin <DATA_STATE>{Data} {
    116  1.1.1.3.4.2  martin       char *s;
    117  1.1.1.3.4.2  martin       int size = strlen (DtCompilerParsertext);
    118  1.1.1.3.4.2  martin       s=UtLocalCacheCalloc (size + 1);
    119  1.1.1.3.4.2  martin       AcpiUtSafeStrncpy (s, DtCompilerParsertext, size + 1);
    120  1.1.1.3.4.2  martin       DtCompilerParserlval.s = s;
    121  1.1.1.3.4.2  martin       DbgPrint (ASL_PARSE_OUTPUT, "Data: %s\n", s);
    122  1.1.1.3.4.2  martin       return (DT_PARSEOP_DATA);
    123  1.1.1.3.4.2  martin }
    124  1.1.1.3.4.2  martin 
    125  1.1.1.3.4.2  martin {CommentField}  /* ignore */
    126  1.1.1.3.4.2  martin 
    127  1.1.1.3.4.2  martin {LabelName} {
    128  1.1.1.3.4.2  martin     char *s;
    129  1.1.1.3.4.2  martin     int size = strlen (DtCompilerParsertext);
    130  1.1.1.3.4.2  martin     s=UtLocalCacheCalloc (size + 1);
    131  1.1.1.3.4.2  martin     AcpiUtSafeStrncpy (s, DtCompilerParsertext, size + 1);
    132  1.1.1.3.4.2  martin     DtCompilerParserlval.u = (DT_TABLE_UNIT *) UtLocalCacheCalloc (sizeof (DT_TABLE_UNIT));
    133  1.1.1.3.4.2  martin     DtCompilerParserlval.u->Value = s;
    134  1.1.1.3.4.2  martin     DtCompilerParserlval.u->Line = DtCompilerParserlineno;
    135  1.1.1.3.4.2  martin     DtCompilerParserlval.u->Column = DtCompilerParsercolumn;
    136  1.1.1.3.4.2  martin     DtLabelByteOffset = DtCompilerParserByteOffset;
    137  1.1.1.3.4.2  martin     DbgPrint (ASL_PARSE_OUTPUT, "Label: %s\n", s);
    138  1.1.1.3.4.2  martin     return (DT_PARSEOP_LABEL);
    139  1.1.1.3.4.2  martin }
    140  1.1.1.3.4.2  martin 
    141  1.1.1.3.4.2  martin 
    142  1.1.1.3.4.2  martin <DATA_STATE>\"{Text}?\" { // remove outer quotes from the string, they are unnecessary
    143  1.1.1.3.4.2  martin     char *s;
    144  1.1.1.3.4.2  martin     int size = strlen (DtCompilerParsertext);
    145  1.1.1.3.4.2  martin     s=UtLocalCacheCalloc (size - 1);
    146  1.1.1.3.4.2  martin     AcpiUtSafeStrncpy (s, DtCompilerParsertext + 1, size - 1);
    147  1.1.1.3.4.2  martin     DtCompilerParserlval.s = s;
    148  1.1.1.3.4.2  martin     DbgPrint (ASL_PARSE_OUTPUT, "String Data: %s\n", s);
    149  1.1.1.3.4.2  martin     BEGIN (INITIAL);
    150  1.1.1.3.4.2  martin     return (DT_PARSEOP_STRING_DATA);
    151  1.1.1.3.4.2  martin }
    152  1.1.1.3.4.2  martin 
    153  1.1.1.3.4.2  martin 
    154  1.1.1.3.4.2  martin <INITIAL,DATA_STATE>{NewLines} {
    155  1.1.1.3.4.2  martin     DbgPrint(ASL_PARSE_OUTPUT,
    156  1.1.1.3.4.2  martin         "Newline matched (data state). Current line number: %u\n",DtCompilerParserlineno);
    157  1.1.1.3.4.2  martin     BEGIN (INITIAL); DtCompilerParsercolumn = 1;
    158  1.1.1.3.4.2  martin }
    159  1.1.1.3.4.2  martin 
    160  1.1.1.3.4.2  martin 
    161  1.1.1.3.4.2  martin %%
    162  1.1.1.3.4.2  martin 
    163  1.1.1.3.4.2  martin 
    164  1.1.1.3.4.2  martin /*
    165  1.1.1.3.4.2  martin  * Local support functions
    166  1.1.1.3.4.2  martin  */
    167  1.1.1.3.4.2  martin 
    168  1.1.1.3.4.2  martin void
    169  1.1.1.3.4.2  martin DtCompilerInitLexer (
    170  1.1.1.3.4.2  martin     FILE                *inFile)
    171  1.1.1.3.4.2  martin {
    172  1.1.1.3.4.2  martin     yyin = inFile;
    173  1.1.1.3.4.2  martin }
    174  1.1.1.3.4.2  martin 
    175  1.1.1.3.4.2  martin void
    176  1.1.1.3.4.2  martin DtCompilerTerminateLexer (
    177  1.1.1.3.4.2  martin     void)
    178  1.1.1.3.4.2  martin {
    179  1.1.1.3.4.2  martin     /*
    180  1.1.1.3.4.2  martin      * Flex/Bison increments the lineno for the EOF so decrement by 1 to get
    181  1.1.1.3.4.2  martin      * the correct number of lines.
    182  1.1.1.3.4.2  martin      */
    183  1.1.1.3.4.2  martin     AslGbl_CurrentLineNumber = DtCompilerParserlineno - 1;
    184  1.1.1.3.4.2  martin     AslGbl_InputByteCount = DtCompilerParserByteOffset;
    185  1.1.1.3.4.2  martin }
    186