From c5fcf682195b0b191d19a598844f734ebf5b2583 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 28 Dec 2009 20:55:18 +0000 Subject: Location data is being tracked (for the most part, filenames...not as much), but it isn't being used in errors yet, I should add some new exceptions for now. --- src/ast.cpp | 54 +++++++++++++++++--- src/ast.h | 8 +++ src/astbranch.cpp | 4 +- src/astbranch.h | 2 +- src/astleaf.cpp | 24 ++++----- src/astleaf.h | 12 ++--- src/astnode.cpp | 5 +- src/astnode.h | 4 +- src/build.y | 148 +++++++++++++++++++++++++++--------------------------- src/location.cpp | 35 +++++++++++++ src/location.h | 23 +++++++++ 11 files changed, 213 insertions(+), 106 deletions(-) create mode 100644 src/location.cpp create mode 100644 src/location.h (limited to 'src') diff --git a/src/ast.cpp b/src/ast.cpp index 03ed4b6..6b213ea 100644 --- a/src/ast.cpp +++ b/src/ast.cpp @@ -3,6 +3,8 @@ #include "astleaf.h" #include "astbranch.h" +#include "build.tab.h" + Ast::Ast() { } @@ -11,13 +13,13 @@ Ast::~Ast() { } -void Ast::addNode( AstNode::Type eType ) +void Ast::addNode( YYLTYPE &loc, AstNode::Type eType ) { switch( eType&AstNode::typeClassMask ) { case AstNode::typeBranch: { - AstBranch *pNode = new AstBranch( eType ); + AstBranch *pNode = new AstBranch( loc, eType ); addNode( pNode ); sBranch.push( pNode ); } @@ -25,7 +27,7 @@ void Ast::addNode( AstNode::Type eType ) case AstNode::typeLeaf: { - AstLeaf *pNode = new AstLeaf( eType ); + AstLeaf *pNode = new AstLeaf( loc, eType ); addNode( pNode ); } break; @@ -36,29 +38,65 @@ void Ast::addNode( AstNode::Type eType ) } } +void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, int iVal ) +{ + addNode( new AstLeaf( loc, eType, iVal ) ); +} + +void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, float fVal ) +{ + addNode( new AstLeaf( loc, eType, fVal ) ); +} + +void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, bool bVal ) +{ + addNode( new AstLeaf( loc, eType, bVal ) ); +} + +void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, const Bu::FString &sVal ) +{ + addNode( new AstLeaf( loc, eType, sVal ) ); +} + +void Ast::addNode( YYLTYPE &loc, AstNode::Type eType, const char *sVal ) +{ + addNode( new AstLeaf( loc, eType, sVal ) ); +} + +void Ast::addNode( AstNode::Type eType ) +{ + YYLTYPE none = {-1, -1, -1, -1}; + addNode( none, eType ); +} + void Ast::addNode( AstNode::Type eType, int iVal ) { - addNode( new AstLeaf( eType, iVal ) ); + YYLTYPE none = {-1, -1, -1, -1}; + addNode( none, eType, iVal ); } void Ast::addNode( AstNode::Type eType, float fVal ) { - addNode( new AstLeaf( eType, fVal ) ); + YYLTYPE none = {-1, -1, -1, -1}; + addNode( none, eType, fVal ); } void Ast::addNode( AstNode::Type eType, bool bVal ) { - addNode( new AstLeaf( eType, bVal ) ); + YYLTYPE none = {-1, -1, -1, -1}; + addNode( none, eType, bVal ); } void Ast::addNode( AstNode::Type eType, const Bu::FString &sVal ) { - addNode( new AstLeaf( eType, sVal ) ); + YYLTYPE none = {-1, -1, -1, -1}; + addNode( none, eType, sVal ); } void Ast::addNode( AstNode::Type eType, const char *sVal ) { - addNode( new AstLeaf( eType, sVal ) ); + YYLTYPE none = {-1, -1, -1, -1}; + addNode( none, eType, sVal ); } void Ast::addNode( AstNode *pNode ) diff --git a/src/ast.h b/src/ast.h index a4f9361..c62406b 100644 --- a/src/ast.h +++ b/src/ast.h @@ -19,6 +19,14 @@ public: Ast(); virtual ~Ast(); + void addNode( struct YYLTYPE &loc, AstNode::Type eType ); + void addNode( struct YYLTYPE &loc, AstNode::Type eType, int iVal ); + void addNode( struct YYLTYPE &loc, AstNode::Type eType, float fVal ); + void addNode( struct YYLTYPE &loc, AstNode::Type eType, bool bVal ); + void addNode( struct YYLTYPE &loc, AstNode::Type eType, + const Bu::FString &sVal ); + void addNode( struct YYLTYPE &loc, AstNode::Type eType, const char *sVal ); + void addNode( AstNode::Type eType ); void addNode( AstNode::Type eType, int iVal ); void addNode( AstNode::Type eType, float fVal ); diff --git a/src/astbranch.cpp b/src/astbranch.cpp index a6aa21c..d247b30 100644 --- a/src/astbranch.cpp +++ b/src/astbranch.cpp @@ -1,7 +1,7 @@ #include "astbranch.h" -AstBranch::AstBranch( Type eType ) : - AstNode( eType ) +AstBranch::AstBranch( const Location &loc, Type eType ) : + AstNode( loc, eType ) { } diff --git a/src/astbranch.h b/src/astbranch.h index 5ff8606..b582b9f 100644 --- a/src/astbranch.h +++ b/src/astbranch.h @@ -10,7 +10,7 @@ class AstBranch : public AstNode public: typedef Bu::List NodeList; typedef Bu::List BranchList; - AstBranch( Type eType ); + AstBranch( const Location &loc, Type eType ); virtual ~AstBranch(); void addBranch(); diff --git a/src/astleaf.cpp b/src/astleaf.cpp index 62773ce..5182a58 100644 --- a/src/astleaf.cpp +++ b/src/astleaf.cpp @@ -1,41 +1,41 @@ #include "astleaf.h" -AstLeaf::AstLeaf( Type eType ) : - AstNode( eType ), +AstLeaf::AstLeaf( const Location &loc, Type eType ) : + AstNode( loc, eType ), sVal( NULL ) { } -AstLeaf::AstLeaf( Type eType, int iNew ) : - AstNode( eType ), +AstLeaf::AstLeaf( const Location &loc, Type eType, int iNew ) : + AstNode( loc, eType ), sVal( NULL ) { setIntValue( iNew ); } -AstLeaf::AstLeaf( Type eType, float fNew ) : - AstNode( eType ), +AstLeaf::AstLeaf( const Location &loc, Type eType, float fNew ) : + AstNode( loc, eType ), sVal( NULL ) { setFloatValue( fNew ); } -AstLeaf::AstLeaf( Type eType, bool bNew ) : - AstNode( eType ), +AstLeaf::AstLeaf( const Location &loc, Type eType, bool bNew ) : + AstNode( loc, eType ), sVal( NULL ) { setBoolValue( bNew ); } -AstLeaf::AstLeaf( Type eType, const Bu::FString &sNew ) : - AstNode( eType ), +AstLeaf::AstLeaf( const Location &loc, Type eType, const Bu::FString &sNew ) : + AstNode( loc, eType ), sVal( NULL ) { setStrValue( sNew ); } -AstLeaf::AstLeaf( Type eType, const char *sNew ) : - AstNode( eType ), +AstLeaf::AstLeaf( const Location &loc, Type eType, const char *sNew ) : + AstNode( loc, eType ), sVal( NULL ) { setStrValue( sNew ); diff --git a/src/astleaf.h b/src/astleaf.h index 0c8911b..cdcb2ae 100644 --- a/src/astleaf.h +++ b/src/astleaf.h @@ -8,12 +8,12 @@ class AstLeaf : public AstNode { public: - AstLeaf( Type eType ); - AstLeaf( Type eType, int iNew ); - AstLeaf( Type eType, float fNew ); - AstLeaf( Type eType, bool bNew ); - AstLeaf( Type eType, const Bu::FString &sNew ); - AstLeaf( Type eType, const char *sNew ); + AstLeaf( const Location &loc, Type eType ); + AstLeaf( const Location &loc, Type eType, int iNew ); + AstLeaf( const Location &loc, Type eType, float fNew ); + AstLeaf( const Location &loc, Type eType, bool bNew ); + AstLeaf( const Location &loc, Type eType, const Bu::FString &sNew ); + AstLeaf( const Location &loc, Type eType, const char *sNew ); virtual ~AstLeaf(); void setIntValue( int iNew ); diff --git a/src/astnode.cpp b/src/astnode.cpp index 5adb3ee..87b9383 100644 --- a/src/astnode.cpp +++ b/src/astnode.cpp @@ -2,8 +2,9 @@ #include "astleaf.h" #include "astbranch.h" -AstNode::AstNode( Type eType ) : - eType( eType ) +AstNode::AstNode( const Location &loc, Type eType ) : + eType( eType ), + loc( loc ) { } diff --git a/src/astnode.h b/src/astnode.h index 6ade25b..843dba8 100644 --- a/src/astnode.h +++ b/src/astnode.h @@ -2,6 +2,7 @@ #define AST_NODE_H #include "bu/formatter.h" +#include "location.h" class AstNode { @@ -91,7 +92,7 @@ public: typeDataMask = 0x0F0000 }; public: - AstNode( Type eType ); + AstNode( const Location &loc, Type eType ); virtual ~AstNode(); Type getType() const { return eType; } @@ -100,6 +101,7 @@ public: private: Type eType; + Location loc; }; Bu::Formatter &operator<<( Bu::Formatter &f, const AstNode &n ); diff --git a/src/build.y b/src/build.y index 3e9c8fd..8cfc526 100644 --- a/src/build.y +++ b/src/build.y @@ -147,19 +147,19 @@ include: TOK_INCLUDE STRING ';' { bld.include( $2, yyscanner, &yylloc ); } * data related */ -string: STRING { bld.xAst.addNode( AstNode::typeString, $1 ); } +string: STRING { bld.xAst.addNode( @1, AstNode::typeString, $1 ); } ; -int: INT { bld.xAst.addNode( AstNode::typeInt, $1 ); } +int: INT { bld.xAst.addNode( @1, AstNode::typeInt, $1 ); } ; -float: FLOAT { bld.xAst.addNode( AstNode::typeFloat, $1 ); } +float: FLOAT { bld.xAst.addNode( @1, AstNode::typeFloat, $1 ); } ; -bool: BOOL { bld.xAst.addNode( AstNode::typeBool, (bool)$1 ); } +bool: BOOL { bld.xAst.addNode( @1, AstNode::typeBool, (bool)$1 ); } ; -null: TOK_NULL { bld.xAst.addNode( AstNode::typeNull ); } +null: TOK_NULL { bld.xAst.addNode( @1, AstNode::typeNull ); } literal: string | int @@ -168,7 +168,7 @@ literal: string | null ; -variable: UNDEF /*VARIABLE*/ { bld.xAst.addNode( AstNode::typeVariable, $1 ); } +variable: UNDEF { bld.xAst.addNode( @1, AstNode::typeVariable, $1 ); } list_core: | { bld.xAst.openBranch(); } expr @@ -176,7 +176,7 @@ list_core: ; list: '[' { - bld.xAst.addNode( AstNode::typeList ); + bld.xAst.addNode( @1, AstNode::typeList ); } list_core ']' { bld.xAst.closeNode(); } @@ -199,9 +199,9 @@ value: value_core value_mods * misc global things */ -notify: TOK_ERROR STRING ';' { bld.xAst.addNode( AstNode::typeError, $2 ); } - | TOK_WARNING STRING ';' { bld.xAst.addNode( AstNode::typeWarning, $2 ); } - | TOK_NOTICE STRING ';' { bld.xAst.addNode( AstNode::typeNotice, $2 ); } +notify: TOK_ERROR STRING ';' { bld.xAst.addNode( @$,AstNode::typeError, $2 ); } + | TOK_WARNING STRING ';' { bld.xAst.addNode( @$, AstNode::typeWarning, $2 ); } + | TOK_NOTICE STRING ';' { bld.xAst.addNode( @$, AstNode::typeNotice, $2 ); } ; /* set_rhs: '=' { bld.xAst.addNode( AstNode::typeOpEq ); } value @@ -218,7 +218,7 @@ set: TOK_SET { ;*/ unset: TOK_UNSET { - bld.xAst.addNode( AstNode::typeUnset ); + bld.xAst.addNode( @1, AstNode::typeUnset ); bld.xAst.openBranch(); } variable ';' { bld.xAst.closeNode(); @@ -230,7 +230,7 @@ export_rhs: '=' value ; export: TOK_EXPORT { - bld.xAst.addNode( AstNode::typeExport ); + bld.xAst.addNode( @1, AstNode::typeExport ); bld.xAst.openBranch(); } variable export_rhs ';' { bld.xAst.closeNode(); @@ -246,37 +246,37 @@ func_param_list: { bld.xAst.openBranch(); } value ; function: UNDEF '(' { - bld.xAst.addNode( AstNode::typeFunction ); + bld.xAst.addNode( @$, AstNode::typeFunction ); bld.xAst.openBranch(); - bld.xAst.addNode( AstNode::typeString, $1 ); + bld.xAst.addNode( @$, AstNode::typeString, $1 ); } func_params ')' { bld.xAst.closeNode(); } ; function_no_input: UNDEF '(' { - bld.xAst.addNode( AstNode::typeNull ); - bld.xAst.addNode( AstNode::typeFunction ); + bld.xAst.addNode( @$, AstNode::typeNull ); + bld.xAst.addNode( @$, AstNode::typeFunction ); bld.xAst.openBranch(); - bld.xAst.addNode( AstNode::typeString, $1 ); + bld.xAst.addNode( @$, AstNode::typeString, $1 ); } func_params ')' { bld.xAst.closeNode(); } ; requires: TOK_REQUIRES { - bld.xAst.addNode( AstNode::typeRequires ); + bld.xAst.addNode( @$, AstNode::typeRequires ); bld.xAst.openBranch(); } value ';' { bld.xAst.closeNode(); } ; -type: TOK_STRING { bld.xAst.addNode( AstNode::typeTypeString ); } - | TOK_INT { bld.xAst.addNode( AstNode::typeTypeInt ); } - | TOK_FLOAT { bld.xAst.addNode( AstNode::typeTypeFloat ); } - | TOK_BOOL { bld.xAst.addNode( AstNode::typeTypeBool ); } - | TOK_VERSION { bld.xAst.addNode( AstNode::typeTypeVersion ); } +type: TOK_STRING { bld.xAst.addNode( @1, AstNode::typeTypeString ); } + | TOK_INT { bld.xAst.addNode( @1, AstNode::typeTypeInt ); } + | TOK_FLOAT { bld.xAst.addNode( @1, AstNode::typeTypeFloat ); } + | TOK_BOOL { bld.xAst.addNode( @1, AstNode::typeTypeBool ); } + | TOK_VERSION { bld.xAst.addNode( @1, AstNode::typeTypeVersion ); } ; /* @@ -286,67 +286,67 @@ type: TOK_STRING { bld.xAst.addNode( AstNode::typeTypeString ); } expr: value | '(' expr ')' | UNDEF '=' { - bld.xAst.addNode( AstNode::typeVariableRef, $1 ); + bld.xAst.addNode( @$, AstNode::typeVariableRef, $1 ); } expr { - bld.xAst.addNode( AstNode::typeOpEq ); + bld.xAst.addNode( @3, AstNode::typeOpEq ); } | UNDEF OP_ADDSETP { - bld.xAst.addNode( AstNode::typeVariableRef, $1 ); + bld.xAst.addNode( @$, AstNode::typeVariableRef, $1 ); } expr { - bld.xAst.addNode( AstNode::typeOpPlusEq ); + bld.xAst.addNode( @3, AstNode::typeOpPlusEq ); } | expr OP_CMPEQUAL expr { - bld.xAst.addNode( AstNode::typeCmpEq ); + bld.xAst.addNode( @$, AstNode::typeCmpEq ); } | expr '<' expr { - bld.xAst.addNode( AstNode::typeCmpLt ); + bld.xAst.addNode( @$, AstNode::typeCmpLt ); } | expr '>' expr { - bld.xAst.addNode( AstNode::typeCmpGt ); + bld.xAst.addNode( @$, AstNode::typeCmpGt ); } | expr OP_INEQUAL expr { - bld.xAst.addNode( AstNode::typeCmpNe ); + bld.xAst.addNode( @$, AstNode::typeCmpNe ); } | expr OP_LTEQUAL expr { - bld.xAst.addNode( AstNode::typeCmpLtEq ); + bld.xAst.addNode( @$, AstNode::typeCmpLtEq ); } | expr OP_GTEQUAL expr { - bld.xAst.addNode( AstNode::typeCmpGtEq ); + bld.xAst.addNode( @$, AstNode::typeCmpGtEq ); } | expr '+' expr { - bld.xAst.addNode( AstNode::typeOpPlus ); + bld.xAst.addNode( @$, AstNode::typeOpPlus ); } | expr '-' expr { - bld.xAst.addNode( AstNode::typeOpMinus ); + bld.xAst.addNode( @$, AstNode::typeOpMinus ); } | expr '*' expr { - bld.xAst.addNode( AstNode::typeOpMultiply ); + bld.xAst.addNode( @$, AstNode::typeOpMultiply ); } | expr '/' expr { - bld.xAst.addNode( AstNode::typeOpDivide ); + bld.xAst.addNode( @$, AstNode::typeOpDivide ); } | '-' expr %prec IINEG { - bld.xAst.addNode( AstNode::typeOpNegate ); + bld.xAst.addNode( @$, AstNode::typeOpNegate ); } | '!' expr %prec IINOT { - bld.xAst.addNode( AstNode::typeOpNot ); + bld.xAst.addNode( @$, AstNode::typeOpNot ); } ; line_expr: { - bld.xAst.addNode( AstNode::typeExpr ); + bld.xAst.addNode( @$, AstNode::typeExpr ); bld.xAst.openBranch(); } expr ';' { @@ -355,9 +355,9 @@ line_expr: { ; if_core: TOK_IF { - bld.xAst.addNode( AstNode::typeIf ); + bld.xAst.addNode( @$, AstNode::typeIf ); bld.xAst.openBranch(); -// bld.xAst.addNode( AstNode::typeExpr ); +// bld.xAst.addNode( @$, AstNode::typeExpr ); // bld.xAst.openBranch(); } expr TOK_THEN { // bld.xAst.closeNode(); @@ -406,7 +406,7 @@ function_else: */ for_base: TOK_FOR { - bld.xAst.addNode( AstNode::typeFor ); + bld.xAst.addNode( @$, AstNode::typeFor ); bld.xAst.openBranch(); } variable TOK_IN { bld.xAst.openBranch(); @@ -432,9 +432,9 @@ function_for: for_base '{' function_exprs '}' { bld.xAst.closeNode(); } */ function_def: TOK_FUNCTION UNDEF { - bld.xAst.addNode( AstNode::typeFunctionDef ); + bld.xAst.addNode( @1, AstNode::typeFunctionDef ); bld.xAst.openBranch(); - bld.xAst.addNode( AstNode::typeString, $2 ); + bld.xAst.addNode( @2, AstNode::typeString, $2 ); bld.xAst.openBranch(); } '(' param_defs ')' { bld.xAst.openBranch(); @@ -465,7 +465,7 @@ function_exprs: ; return: TOK_RETURN { - bld.xAst.addNode( AstNode::typeReturn ); + bld.xAst.addNode( @$, AstNode::typeReturn ); bld.xAst.openBranch(); } expr { bld.xAst.closeNode(); @@ -477,9 +477,9 @@ return: TOK_RETURN { */ action_def: TOK_ACTION STRING { - bld.xAst.addNode( AstNode::typeActionDef ); + bld.xAst.addNode( @$, AstNode::typeActionDef ); bld.xAst.openBranch(); - bld.xAst.addNode( AstNode::typeString, $2 ); + bld.xAst.addNode( @1, AstNode::typeString, $2 ); bld.xAst.openBranch(); } '{' function_exprs '}' { bld.xAst.closeNode(); @@ -491,7 +491,7 @@ action_def: TOK_ACTION STRING { */ profile: TOK_PROFILE { - bld.xAst.addNode( AstNode::typeProfile ); + bld.xAst.addNode( @$, AstNode::typeProfile ); bld.xAst.openBranch(); } string { bld.xAst.openBranch(); @@ -518,7 +518,7 @@ profile_exprs: */ target: TOK_TARGET { - bld.xAst.addNode( AstNode::typeTarget ); + bld.xAst.addNode( @$, AstNode::typeTarget ); bld.xAst.openBranch(); } expr { bld.xAst.openBranch(); @@ -544,7 +544,7 @@ target_exprs: ; target_input: TOK_INPUT { - bld.xAst.addNode( AstNode::typeInput ); + bld.xAst.addNode( @$, AstNode::typeInput ); bld.xAst.openBranch(); } expr ';' { bld.xAst.closeNode(); @@ -552,7 +552,7 @@ target_input: TOK_INPUT { ; target_rule: TOK_RULE { - bld.xAst.addNode( AstNode::typeRule ); + bld.xAst.addNode( @$, AstNode::typeRule ); bld.xAst.openBranch(); } string ';' { bld.xAst.closeNode(); @@ -560,13 +560,13 @@ target_rule: TOK_RULE { ; condition: TOK_CONDITION CONDITION ';' { - bld.xAst.addNode( AstNode::typeCondition, $2 ); + bld.xAst.addNode( @$, AstNode::typeCondition, $2 ); } | TOK_CONDITION TOK_ALWAYS ';'{ - bld.xAst.addNode( AstNode::typeCondition, "always" ); + bld.xAst.addNode( @$, AstNode::typeCondition, "always" ); } | TOK_CONDITION TOK_NEVER ';'{ - bld.xAst.addNode( AstNode::typeCondition, "never" ); + bld.xAst.addNode( @$, AstNode::typeCondition, "never" ); } ; @@ -575,7 +575,7 @@ condition: TOK_CONDITION CONDITION ';' { */ rule: TOK_RULE { - bld.xAst.addNode( AstNode::typeRuleDef ); + bld.xAst.addNode( @$, AstNode::typeRuleDef ); bld.xAst.openBranch(); } string { bld.xAst.openBranch(); @@ -602,18 +602,18 @@ rule_input_func: function /* In this case, when the input is just a string, lets actually turn it into a call to the matches function. */ - bld.xAst.addNode( AstNode::typeFunction ); + bld.xAst.addNode( @1, AstNode::typeFunction ); bld.xAst.openBranch(); - bld.xAst.addNode( AstNode::typeString, "matches" ); + bld.xAst.addNode( @1, AstNode::typeString, "matches" ); bld.xAst.openBranch(); - bld.xAst.addNode( AstNode::typeString, $1 ); + bld.xAst.addNode( @1, AstNode::typeString, $1 ); bld.xAst.closeNode(); } /* | string */ ; rule_input: TOK_INPUT { - bld.xAst.addNode( AstNode::typeInput ); + bld.xAst.addNode( @$, AstNode::typeInput ); bld.xAst.openBranch(); } rule_input_func ';' { bld.xAst.closeNode(); @@ -621,7 +621,7 @@ rule_input: TOK_INPUT { ; output: TOK_OUTPUT { - bld.xAst.addNode( AstNode::typeOutput ); + bld.xAst.addNode( @$, AstNode::typeOutput ); bld.xAst.openBranch(); } value ';' { bld.xAst.closeNode(); @@ -632,7 +632,7 @@ output: TOK_OUTPUT { * config */ config: TOK_CONFIG { - bld.xAst.addNode( AstNode::typeConfig ); + bld.xAst.addNode( @$, AstNode::typeConfig ); bld.xAst.openBranch(); } string { bld.xAst.openBranch(); @@ -640,7 +640,7 @@ config: TOK_CONFIG { bld.xAst.closeNode(); } | TOK_AUTO TOK_CONFIG { - bld.xAst.addNode( AstNode::typeAutoConfig ); + bld.xAst.addNode( @$, AstNode::typeAutoConfig ); bld.xAst.openBranch(); } string { bld.xAst.openBranch(); @@ -648,7 +648,7 @@ config: TOK_CONFIG { bld.xAst.closeNode(); } | TOK_GLOBAL TOK_CONFIG { - bld.xAst.addNode( AstNode::typeGlobalConfig ); + bld.xAst.addNode( @$, AstNode::typeGlobalConfig ); bld.xAst.openBranch(); } string { bld.xAst.openBranch(); @@ -667,12 +667,12 @@ config_exprs: ; display: TOK_DISPLAY STRING ';' { - bld.xAst.addNode( AstNode::typeDisplay, $2 ); + bld.xAst.addNode( @$, AstNode::typeDisplay, $2 ); } ; config_type: TOK_TYPE { - bld.xAst.addNode( AstNode::typeType ); + bld.xAst.addNode( @$, AstNode::typeType ); bld.xAst.openBranch(); } type ';' { bld.xAst.closeNode(); @@ -680,7 +680,7 @@ config_type: TOK_TYPE { ; default: TOK_DEFAULT { - bld.xAst.addNode( AstNode::typeDefault ); + bld.xAst.addNode( @$, AstNode::typeDefault ); bld.xAst.openBranch(); } literal ';' { bld.xAst.closeNode(); @@ -691,7 +691,7 @@ value_key_val: value ';' | '{' function_exprs '}' /* inline function */ value_key: TOK_VALUE { - bld.xAst.addNode( AstNode::typeValue ); + bld.xAst.addNode( @$, AstNode::typeValue ); bld.xAst.openBranch(); } value_key_val { bld.xAst.closeNode(); @@ -699,7 +699,7 @@ value_key: TOK_VALUE { ; allow: TOK_ALLOW { - bld.xAst.addNode( AstNode::typeAllow ); + bld.xAst.addNode( @$, AstNode::typeAllow ); bld.xAst.openBranch(); } value ';' { bld.xAst.closeNode(); @@ -707,9 +707,9 @@ allow: TOK_ALLOW { ; cache: TOK_CACHE TOK_ALWAYS ';' - { bld.xAst.addNode( AstNode::typeCache, true ); } + { bld.xAst.addNode( @$, AstNode::typeCache, true ); } | TOK_CACHE TOK_NEVER ';' - { bld.xAst.addNode( AstNode::typeCache, false ); } + { bld.xAst.addNode( @$, AstNode::typeCache, false ); } ; /* @@ -717,9 +717,9 @@ cache: TOK_CACHE TOK_ALWAYS ';' */ process_target: PROFILE { - bld.xAst.addNode( AstNode::typeProcessTarget ); + bld.xAst.addNode( @$, AstNode::typeProcessTarget ); bld.xAst.openBranch(); - bld.xAst.addNode( AstNode::typeString, $1 ); + bld.xAst.addNode( @$, AstNode::typeString, $1 ); bld.xAst.openBranch(); } value ';' { bld.xAst.closeNode(); @@ -728,7 +728,7 @@ process_target: PROFILE tag: TOK_TAG { - bld.xAst.addNode( AstNode::typeTag ); + bld.xAst.addNode( @$, AstNode::typeTag ); bld.xAst.openBranch(); } value ';' { bld.xAst.closeNode(); diff --git a/src/location.cpp b/src/location.cpp new file mode 100644 index 0000000..03b8b43 --- /dev/null +++ b/src/location.cpp @@ -0,0 +1,35 @@ +#include "location.h" +#include "build.tab.h" + +Location::Location() : + sFile("none"), + iStartRow( -1 ), + iStartCol( -1 ), + iEndRow( -1 ), + iEndCol( -1 ) +{ +} + +Location::Location( struct YYLTYPE &loc ) : + sFile("???"), + iStartRow( loc.first_line ), + iStartCol( loc.first_column ), + iEndRow( loc.last_line ), + iEndCol( loc.last_column ) +{ +} + +Location::Location( const Bu::FString &sFile, int iStartRow, int iStartCol, + int iEndRow, int iEndCol ) : + sFile( sFile ), + iStartRow( iStartRow ), + iStartCol( iStartCol ), + iEndRow( iEndRow ), + iEndCol( iEndCol ) +{ +} + +Location::~Location() +{ +} + diff --git a/src/location.h b/src/location.h new file mode 100644 index 0000000..76699e3 --- /dev/null +++ b/src/location.h @@ -0,0 +1,23 @@ +#ifndef LOCATION_H +#define LOCATION_H + +#include + +class Location +{ +public: + Location(); + Location( struct YYLTYPE &loc ); + Location( const Bu::FString &sFile, int iStartRow, int iStartCol, + int iEndRow, int iEndCol ); + virtual ~Location(); + +private: + const Bu::FString sFile; + int iStartRow; + int iStartCol; + int iEndRow; + int iEndCol; +}; + +#endif -- cgit v1.2.3