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