public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
From: pmachata@sourceware.org
To: frysk-cvs@sourceware.org
Subject: [SCM]  master: Communicate details on fully qualified identifier to parser
Date: Wed, 28 May 2008 15:22:00 -0000	[thread overview]
Message-ID: <20080528152231.20724.qmail@sourceware.org> (raw)

The branch, master has been updated
       via  7391aeb00d8f701dbfb30f026ec050cda6731f3c (commit)
      from  9c76bab74da6115985f57ad5383fb7415eb0be25 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 7391aeb00d8f701dbfb30f026ec050cda6731f3c
Author: Petr Machata <pmachata@redhat.com>
Date:   Wed May 28 17:04:05 2008 +0200

    Communicate details on fully qualified identifier to parser
    
    * IDENT and IDENT_TAB rules now pass up FqIdentToken tokens, with detailed
      info on components of identifier (symbol name, dso, etc.)

-----------------------------------------------------------------------

Summary of changes:
 frysk-core/frysk/expr/CExpr.g                      |   81 ++++++++++----------
 frysk-core/frysk/expr/ChangeLog                    |    6 ++
 ...eIdentifierException.java => FqIdentToken.java} |   42 +++++------
 .../frysk/expr/IncompleteIdentifierException.java  |    2 +-
 4 files changed, 68 insertions(+), 63 deletions(-)
 copy frysk-core/frysk/expr/{IncompleteIdentifierException.java => FqIdentToken.java} (74%)

First 500 lines of diff:
diff --git a/frysk-core/frysk/expr/CExpr.g b/frysk-core/frysk/expr/CExpr.g
index 98cfdba..816e8d5 100644
--- a/frysk-core/frysk/expr/CExpr.g
+++ b/frysk-core/frysk/expr/CExpr.g
@@ -423,12 +423,14 @@ tokens
 
 {
     private String fqinit;
+
     private char fqLA(int i) throws CharStreamException {
         if (i >= fqinit.length())
             return LA(i - fqinit.length() + 1);
         else
             return fqinit.charAt(i);
     }
+
     private void fqmatch(String s) throws MismatchedCharException, CharStreamException {
         while (fqinit.length() > 0) {
             char c = s.charAt(0);
@@ -503,22 +505,16 @@ ELLIPSIS  : "..." ;
  * or EOF stops the lookahead.
  */
 
-private
+protected
 PARSE_FQIDENT
     : {
-            // Automaton state is composed of following sub-states:
-            final int FILE = 1;
-            final int LINE = 2;
-            final int SYMB = 4;
-            int state = LINE | SYMB;
-
             String matched = "";
             String part = "";
 
-            String dso = null;
-            String file = null;
-            String proc = null;
-            String line = null;
+            String partDso = null;
+            String partFile = null;
+            String partProc = null;
+            String partLine = null;
 
             int i = 0;
             char c;
@@ -539,10 +535,15 @@ PARSE_FQIDENT
                 if (part.length() == 0)
                     throw new RecognitionException("Empty DSO part `" + matched
                                                    + "' in fully qualified notation.");
-                dso = part;
+                partDso = part;
                 part = "";
             }
 
+            // Automaton state is composed of following sub-states:
+            final int FILE = 1;
+            final int LINE = 2;
+            final int SYMB = 4;
+            int state = LINE | SYMB;
             loop: while(true) {
                 c = fqLA(i++);
                 if (Character.isWhitespace(c) || c == EOF_CHAR)
@@ -558,15 +559,15 @@ PARSE_FQIDENT
                     }
 
                     case '#': {
-                        if (line == null && proc == null) {
-                            if ((state & FILE) != 0 && file == null)
-                                file = part.substring(0, part.length() - 1);
+                        if (partLine == null && partProc == null) {
+                            if ((state & FILE) != 0 && partFile == null)
+                                partFile = part.substring(0, part.length() - 1);
                             else if ((state & LINE) != 0)
-                                line = part.substring(0, part.length() - 1);
+                                partLine = part.substring(0, part.length() - 1);
                             else if ((state & SYMB) != 0) {
-                                proc = part.substring(0, part.length() - 1);
-                                if (!Character.isJavaIdentifierStart(proc.charAt(0)))
-                                    throw new RecognitionException("Procedure part (`" + proc + "') in fully "
+                                partProc = part.substring(0, part.length() - 1);
+                                if (!Character.isJavaIdentifierStart(partProc.charAt(0)))
+                                    throw new RecognitionException("Procedure part (`" + partProc + "') in fully "
                                                                    + "qualified notation has to be valid identifier.");
                             } else
                                 // This # could belong to the next symbol.
@@ -576,7 +577,7 @@ PARSE_FQIDENT
                             throw new RecognitionException("Unexpected `#' after line or proc name was defined.");
 
                         state = SYMB;
-                        if (line == null && proc == null)
+                        if (partLine == null && partProc == null)
                             state |= LINE;
                         part = "";
                         break;
@@ -588,11 +589,12 @@ PARSE_FQIDENT
 
                             if (!(Character.isJavaIdentifierStart(c)
                                   || c == '@'
-                                  || (c == ':' && part.equals("plt:")))) {
+                                  || (c == ':' && part.length() == 4
+                                      && part.equals("plt:")))) {
 
                                 // Break out early if we are already
                                 // just waiting for symbol.
-                                if (line != null || proc != null)
+                                if (partLine != null || partProc != null)
                                     break loop;
                                 else
                                     state &= ~SYMB;
@@ -629,7 +631,6 @@ PARSE_FQIDENT
             // parts before yelling at user that his identifier sucks.
             Matcher m = Pattern.compile("[a-zA-Z0-9_$]*").matcher(part);
             if (m.lookingAt()) {
-                // XXX This accepts also e.g. "plt:something" (i.e. without the "#" part). Ok?
                 int diff = part.length() - m.end();
                 if (diff > 0) {
                     matched = matched.substring(0, matched.length() - diff);
@@ -640,26 +641,25 @@ PARSE_FQIDENT
             if (!Character.isJavaIdentifierStart(part.charAt(0)))
                 throw new RecognitionException("Invalid symbol `" + part + "'.");
 
-            if (false) {
-            if (dso != null)
-                System.err.println("DSO:  " + dso);
-            if (file != null)
-                System.err.println("File: " + file);
-            if (line != null)
-                System.err.println("Line: " + line);
-            if (proc != null)
-                System.err.println("Proc: " + proc);
-            System.err.println("Symb: " + (wantPlt ? "plt:" : "")
-                               + part + (version != null ? "@" + version : ""));
-            }
+            FqIdentToken tok = new FqIdentToken(IDENT, matched);
+            tok.dso = partDso;
+            tok.file = partFile;
+            tok.line = partLine;
+            tok.proc = partProc;
+            tok.symbol = part;
+            tok.version = version;
+            tok.wantPlt = wantPlt;
+            tok.setLine(getLine());
+            $setToken(tok);
 
             fqmatch(matched);
-            //System.out.println("matched = " + matched);
+            tok.setColumn(getColumn() - matched.length());
         } ;
 
 protected
 IDENT
-    : ('$'|'#'|'a'..'z'|'A'..'Z'|'_') { fqinit = $getText; } PARSE_FQIDENT ;
+    : ('$'|'#'|'a'..'z'|'A'..'Z'|'_') { fqinit = $getText; }
+      fqident:PARSE_FQIDENT { $setToken(fqident); } ;
 
 /**
  *  A <TAB> token is returned not only on regular tabs
@@ -668,7 +668,10 @@ IDENT
 
 IDENT_TAB 
     :   '\t'
-    |   IDENT {$setType(IDENT);} ('\t' {$setType(IDENT_TAB);})? 
+    |   ident:IDENT { $setType(IDENT); $setToken(ident); }
+        ('\t' { $setType(IDENT_TAB);
+                ident.setText($getText);
+                ident.setType(IDENT_TAB); })?
     ;
 
 protected
@@ -807,7 +810,7 @@ NUM
 			)?
 		|	(('1'..'9') ('0'..'9')* {_ttype = DECIMALINT;})
              ( '#' {fqinit = $getText;}
-               PARSE_FQIDENT { $setType(IDENT); } )?
+               fqident:PARSE_FQIDENT { $setType(IDENT); $setToken(fqident); } )?
 		)
 		(	('l'|'L') { _ttype = DECIMALINT; }
 
diff --git a/frysk-core/frysk/expr/ChangeLog b/frysk-core/frysk/expr/ChangeLog
index 6e97358..a2d954a 100644
--- a/frysk-core/frysk/expr/ChangeLog
+++ b/frysk-core/frysk/expr/ChangeLog
@@ -1,3 +1,9 @@
+2008-05-28  Petr Machata  <pmachata@redhat.com>
+
+	* FqIdentToken.java: New file.
+	* CExpr.g: Use custom token to communicate fully qualified
+	identifier info to parser (or whomever is asking).
+
 2008-05-26  Petr Machata  <pmachata@redhat.com>
 
 	* CExpr.g: Implement #-syntax parser.
diff --git a/frysk-core/frysk/expr/IncompleteIdentifierException.java b/frysk-core/frysk/expr/FqIdentToken.java
similarity index 74%
copy from frysk-core/frysk/expr/IncompleteIdentifierException.java
copy to frysk-core/frysk/expr/FqIdentToken.java
index fa8ad68..72d81e3 100644
--- a/frysk-core/frysk/expr/IncompleteIdentifierException.java
+++ b/frysk-core/frysk/expr/FqIdentToken.java
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2007, Red Hat Inc.
+// Copyright 2005, 2007, 2008 Red Hat Inc.
 //
 // FRYSK is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by
@@ -39,29 +39,25 @@
 
 package frysk.expr;
 
-import antlr.collections.AST;
-import java.util.List;
+public class FqIdentToken
+    extends antlr.CommonToken
+{
+    public String dso = null, file = null, line = null,
+		  proc = null, symbol = null, version = null;
+    boolean wantPlt = false;
 
-/** 
- * An incomplete identifier; e.g.: foo<tab>
- */
-class IncompleteIdentifierException extends CompletionException {
-    static final long serialVersionUID = 1;
-    IncompleteIdentifierException(AST identifier) {
-	super(identifier);
+    public FqIdentToken(int t, String txt) {
+	super (t, txt);
     }
-    public String getMessage() {
-	return ("complete identifier <<"
-		+ getText()
-		+ ">> at "
-		+ getColumn()
-		);
-    }
-    int complete(ExprSymTab symTab, List candidates) {
-	symTab.complete(getText(), candidates);
-	if (candidates.size() == 0)
-	    return -1;
-	else
-	    return getColumn();
+
+    public String toString() {
+        return "[" + super.toString()
+	    + (dso != null ? ", dso:" + dso : "")
+	    + (file != null ? ", file:" + file : "")
+	    + (line != null ? ", line:" + line : "")
+	    + (proc != null ? ", proc:" + proc : "")
+	    + (wantPlt ? ", pltref" : "")
+	    + (symbol != null ? ", symbol:" + symbol : "")
+	    + (version != null ? ", version:" + symbol : "") + "]";
     }
 }
diff --git a/frysk-core/frysk/expr/IncompleteIdentifierException.java b/frysk-core/frysk/expr/IncompleteIdentifierException.java
index fa8ad68..30afa28 100644
--- a/frysk-core/frysk/expr/IncompleteIdentifierException.java
+++ b/frysk-core/frysk/expr/IncompleteIdentifierException.java
@@ -43,7 +43,7 @@ import antlr.collections.AST;
 import java.util.List;
 
 /** 
- * An incomplete identifier; e.g.: foo<tab>
+ * An incomplete identifier; e.g.: foo&lt;tab&gt;
  */
 class IncompleteIdentifierException extends CompletionException {
     static final long serialVersionUID = 1;


hooks/post-receive
--
frysk system monitor/debugger


                 reply	other threads:[~2008-05-28 15:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080528152231.20724.qmail@sourceware.org \
    --to=pmachata@sourceware.org \
    --cc=frysk-cvs@sourceware.org \
    --cc=frysk@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).