diff options
author | Adrian Thurston <thurston@complang.org> | 2012-05-16 14:17:15 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2012-05-16 14:17:15 -0400 |
commit | b6f4f9431a9a907ca9d022b9d12b69524d1401ee (patch) | |
tree | e83161890d13ab96f76e556560f009307a495cc8 | |
parent | 3d4c50d7ce8584016e4a1849b57e4d49f32dea46 (diff) | |
download | colm-b6f4f9431a9a907ca9d022b9d12b69524d1401ee.tar.gz |
Added token.line for fetching line information.
-rw-r--r-- | colm/bytecode.c | 13 | ||||
-rw-r--r-- | colm/bytecode.h | 1 | ||||
-rw-r--r-- | colm/compile.cc | 19 | ||||
-rw-r--r-- | colm/parsedata.h | 1 |
4 files changed, 34 insertions, 0 deletions
diff --git a/colm/bytecode.c b/colm/bytecode.c index e8939d15..76d1df22 100644 --- a/colm/bytecode.c +++ b/colm/bytecode.c @@ -2852,6 +2852,19 @@ again: treeDownref( prg, sp, tree ); break; } + case IN_GET_TOKEN_LINE_R: { + debug( REALM_BYTECODE, "IN_GET_TOKEN_LINE_R\n" ); + + Tree *tree = (Tree*) vm_pop(); + Tree *integer = 0; + if ( tree->tokdata->location ) { + integer = constructInteger( prg, tree->tokdata->location->line ); + treeUpref( integer ); + } + vm_push( integer ); + treeDownref( prg, sp, tree ); + break; + } case IN_GET_MATCH_LENGTH_R: { debug( REALM_BYTECODE, "IN_GET_MATCH_LENGTH_R\n" ); diff --git a/colm/bytecode.h b/colm/bytecode.h index 72cf8f95..89adc839 100644 --- a/colm/bytecode.h +++ b/colm/bytecode.h @@ -107,6 +107,7 @@ typedef unsigned char uchar; #define IN_SET_TOKEN_DATA_BKT 0x36 #define IN_GET_TOKEN_POS_R 0x37 +#define IN_GET_TOKEN_LINE_R 0xf6 #define IN_INIT_RHS_EL 0x38 #define IN_INIT_LHS_EL 0xef diff --git a/colm/compile.cc b/colm/compile.cc index 7617ead5..11ae091e 100644 --- a/colm/compile.cc +++ b/colm/compile.cc @@ -2468,6 +2468,23 @@ ObjField *ParseData::makePosEl() return el; } +ObjField *ParseData::makeLineEl() +{ + /* Create the "data" field. */ + TypeRef *typeRef = new TypeRef( InputLoc(), uniqueTypeInt ); + ObjField *el = new ObjField( InputLoc(), typeRef, "line" ); + + /* Setting beenReferenced to true prevents us from assigning instructions + * and an offset to the field. */ + + el->isConst = true; + el->beenReferenced = true; + el->beenInitialized = true; + el->useOffset = false; + el->inGetR = IN_GET_TOKEN_LINE_R; + return el; +} + void ParseData::initTokenObjects( ) { /* Make a default object Definition. */ @@ -2479,6 +2496,8 @@ void ParseData::initTokenObjects( ) ObjField *posEl = makePosEl(); tokenObj->insertField( posEl->name, posEl ); + ObjField *lineEl = makeLineEl(); + tokenObj->insertField( posEl->name, lineEl ); /* Give all user terminals the token object type. */ for ( LelList::Iter lel = langEls; lel.lte(); lel++ ) { diff --git a/colm/parsedata.h b/colm/parsedata.h index 22a0cf51..8d2f4014 100644 --- a/colm/parsedata.h +++ b/colm/parsedata.h @@ -987,6 +987,7 @@ struct ParseData ObjField *makeDataEl(); ObjField *makePosEl(); + ObjField *makeLineEl(); IterDef *findIterDef( IterDef::Type type, GenericType *generic ); IterDef *findIterDef( IterDef::Type type, Function *func ); |