From 8eb9e27bccca4a0cd6a0b1b15bee76576ce030c3 Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Fri, 6 Mar 2015 07:28:35 +0100
Subject: Bug 1134 - Add ASTLocationTag, locating source of [semantic] errors
 while parsing / analyzing

New GlueGenException supports ASTLocationTag,
which will be throws in case of semantic and/or parsing errors.
---
 src/java/com/jogamp/gluegen/cgram/TNode.java | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

(limited to 'src/java/com/jogamp/gluegen/cgram/TNode.java')

diff --git a/src/java/com/jogamp/gluegen/cgram/TNode.java b/src/java/com/jogamp/gluegen/cgram/TNode.java
index a564c54..70dc2c4 100644
--- a/src/java/com/jogamp/gluegen/cgram/TNode.java
+++ b/src/java/com/jogamp/gluegen/cgram/TNode.java
@@ -3,10 +3,14 @@ package com.jogamp.gluegen.cgram;
 import antlr.collections.AST;
 import antlr.CommonAST;
 import antlr.Token;
+
 import java.lang.reflect.*;
 import java.util.Hashtable;
 import java.util.Enumeration;
 
+import com.jogamp.gluegen.ASTLocusTag;
+import com.jogamp.gluegen.ASTLocusTag.ASTLocusTagProvider;
+
 /**
   Class TNode is an implementation of the AST interface
   and adds many useful features:
@@ -29,7 +33,8 @@ import java.util.Enumeration;
 
 
  */
-public class TNode extends CommonAST {
+@SuppressWarnings("serial")
+public class TNode extends CommonAST implements ASTLocusTagProvider {
   protected int ttype;
   protected String text;
   protected int lineNum = 0;
@@ -40,7 +45,22 @@ public class TNode extends CommonAST {
   protected Hashtable<String, Object> attributes = null;
   static String tokenVocabulary;
 
-
+  /**
+   * {@inheritDoc}
+   * <p>
+   * If <i>source</i> is not available,
+   * implementation returns {@code null}.
+   * </p>
+   */
+  @Override
+  public ASTLocusTag getASTLocusTag() {
+      final Object s = getAttribute("source");
+      if( null != s ) {
+          return new ASTLocusTag(s, getLineNum(), -1, getText());
+      } else {
+          return null;
+      }
+  }
 
 
   /** Set the token vocabulary to a tokentypes class
-- 
cgit v1.2.3