Changeset d48e529 for src/Parser


Ignore:
Timestamp:
Sep 19, 2017, 1:22:51 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
a9a4771
Parents:
4e8949f
Message:

Begin to introduce support for yylloc in the parser and extend CodeLocation to include start column and end column/line number information

Location:
src/Parser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ParseNode.h

    r4e8949f rd48e529  
    4444//##############################################################################
    4545
     46typedef CodeLocation YYLTYPE;
     47#define YYLTYPE_IS_DECLARED 1 /* alert the parser that we have our own definition */
     48
    4649extern char * yyfilename;
    4750extern int yylineno;
     51extern YYLTYPE yylloc;
    4852
    4953class ParseNode {
     
    7377        ParseNode * next = nullptr;
    7478        std::string * name = nullptr;
    75         CodeLocation location = { yyfilename, yylineno };
     79        CodeLocation location = yylloc;
    7680}; // ParseNode
    7781
  • src/Parser/lex.ll

    r4e8949f rd48e529  
    2626
    2727unsigned int column = 0;                                                                // position of the end of the last token parsed
    28 #define YY_USER_ACTION column += yyleng;                                // trigger before each matching rule's action
     28#define YY_USER_ACTION yylloc.first_line = yylineno; yylloc.first_column = column; column += yyleng; yylloc.last_column = column; yylloc.last_line = yylineno; yylloc.filename = yyfilename ? yyfilename : "";                          // trigger before each matching rule's action
    2929
    3030#include <string>
  • src/Parser/parser.yy

    r4e8949f rd48e529  
    116116
    117117bool forall = false;                                                                    // aggregate have one or more forall qualifiers ?
     118
     119# define YYLLOC_DEFAULT(Cur, Rhs, N)                            \
     120do                                                              \
     121        if (N) {                                                      \
     122                (Cur).first_line   = YYRHSLOC(Rhs, 1).first_line;           \
     123                (Cur).first_column = YYRHSLOC(Rhs, 1).first_column;         \
     124                (Cur).last_line    = YYRHSLOC(Rhs, N).last_line;            \
     125                (Cur).last_column  = YYRHSLOC(Rhs, N).last_column;          \
     126                (Cur).filename     = YYRHSLOC(Rhs, 1).filename;             \
     127        } else {                                                      \
     128                (Cur).first_line   = (Cur).last_line   =                    \
     129                        YYRHSLOC(Rhs, 0).last_line;                               \
     130                (Cur).first_column = (Cur).last_column =                    \
     131                        YYRHSLOC(Rhs, 0).last_column;                             \
     132                (Cur).filename     = YYRHSLOC(Rhs, 0).filename;             \
     133        }                                                             \
     134while (0)
    118135%}
    119136
     
    346363%precedence ELSE        // token precedence for start of else clause in IF/WAITFOR statement
    347364
     365%locations
    348366
    349367%start translation_unit                                                                 // parse-tree root
Note: See TracChangeset for help on using the changeset viewer.