This is the mail archive of the frysk-cvs@sources.redhat.com mailing list for the frysk project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[SCM] master: Test cases for array access and slice


The branch, master has been updated
       via  09ad908a40a267c243caa418f18cb40b98991694 (commit)
       via  e8db017084db58c4c94169718a5c0022dd17ead4 (commit)
       via  81f6ee38b3a97da2d3e764e575aa179e76e04af4 (commit)
       via  989550d7e43463e7008ce706335f38257e97293c (commit)
      from  e9ea00b225af9daaeb8e705d750c1331b912976a (commit)

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

- Log -----------------------------------------------------------------
commit 09ad908a40a267c243caa418f18cb40b98991694
Author: Petr Machata <pmachata@redhat.com>
Date:   Thu Jun 12 15:41:16 2008 +0200

    Test cases for array access and slice

commit e8db017084db58c4c94169718a5c0022dd17ead4
Author: Petr Machata <pmachata@redhat.com>
Date:   Thu Jun 12 13:50:26 2008 +0200

    Fix 6629 lex error when printing an slice such as: print array[1:2]
    
    * "[1" was wrongly classified as a beginning of the [1.2#3] symbol prefix

commit 81f6ee38b3a97da2d3e764e575aa179e76e04af4
Author: Petr Machata <pmachata@redhat.com>
Date:   Thu Jun 12 12:26:40 2008 +0200

    Glob support in FQIdentifier and ftrace

commit 989550d7e43463e7008ce706335f38257e97293c
Author: Petr Machata <pmachata@redhat.com>
Date:   Tue Jun 10 16:34:52 2008 +0200

    FQIdentParser can parse glob expressions
    
    * ... or rather match identifier names etc. that contain globs in them.
      Globs still need to be parsed/translated to regular expressions in higher
      layers.  FQIdentifier will do that.

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

Summary of changes:
 frysk-core/frysk/expr/CExpr.g                      |   23 +++--
 frysk-core/frysk/expr/ChangeLog                    |   23 ++++
 frysk-core/frysk/expr/FQIdentParser.java           |   94 ++++++++++++------
 .../{FQIdentToken.java => FQIdentPattern.java}     |   44 ++++-----
 .../{FQIdentToken.java => FQIdentPatternAll.java}  |   41 +++----
 ...{FQIdentToken.java => FQIdentPatternExact.java} |   40 +++----
 .../{FQIdentToken.java => FQIdentPatternGlob.java} |   41 ++++----
 frysk-core/frysk/expr/FQIdentToken.java            |    3 +
 frysk-core/frysk/expr/FQIdentifier.java            |  109 ++++++++++++--------
 frysk-core/frysk/expr/TestArithmetics.java         |   16 +++-
 frysk-core/frysk/expr/TestbedSymTab.java           |   22 ++++-
 frysk-core/frysk/ftrace/SymbolRule.java            |    5 +-
 12 files changed, 281 insertions(+), 180 deletions(-)
 copy frysk-core/frysk/expr/{FQIdentToken.java => FQIdentPattern.java} (70%)
 copy frysk-core/frysk/expr/{FQIdentToken.java => FQIdentPatternAll.java} (71%)
 copy frysk-core/frysk/expr/{FQIdentToken.java => FQIdentPatternExact.java} (71%)
 copy frysk-core/frysk/expr/{FQIdentToken.java => FQIdentPatternGlob.java} (71%)

First 500 lines of diff:
diff --git a/frysk-core/frysk/expr/CExpr.g b/frysk-core/frysk/expr/CExpr.g
index 3ea45b6..0f528be 100644
--- a/frysk-core/frysk/expr/CExpr.g
+++ b/frysk-core/frysk/expr/CExpr.g
@@ -441,15 +441,20 @@ LCURLY          : '{' ;
 LESSTHAN        : "<" ;
 LESSTHANOREQUALTO     : "<=" ;
 LPAREN          : '('   ;
-LSQUARE         : '[' (('0'..'9') {
-                      try {
-                          Token tok = fqIdParser.parse($getText);
-                          if (tok != null) {
-                              $setToken(tok);
-                              $setType(IDENT);
-                          }
-                      } catch (RecognitionException exc) { }
-                  } )? ;
+LSQUARE         : '[' {
+                        // We can't use ('0'..'9')? here, because even
+                        // if there is 0..9, it still doesn't have to
+                        // parse correctly as [a.b#c] syntax.  But
+                        // antlr would already match the digit.
+                        if (((LA(1) >= '0' && LA(1) <= '9')))
+                            try {
+                                Token tok = fqIdParser.parse($getText);
+                                if (tok != null) {
+                                    $setToken(tok);
+                                    $setType(IDENT);
+                                }
+                            } catch (RecognitionException exc) { }
+                       } ;
 MINUS           : '-' ;
 MINUSEQUAL      : "-=" ;
 MINUSMINUS      : "--" ;
diff --git a/frysk-core/frysk/expr/ChangeLog b/frysk-core/frysk/expr/ChangeLog
index 9b25bfc..b35f777 100644
--- a/frysk-core/frysk/expr/ChangeLog
+++ b/frysk-core/frysk/expr/ChangeLog
@@ -1,3 +1,26 @@
+2008-06-12  Petr Machata  <pmachata@redhat.com>
+
+	* TestbedSymTab.java: Add "arr", an array variable
+	* TestArithmetics.java (testArrayAccess, testArraySlice): New tests.
+
+2008-06-12  Petr Machata  <pmachata@redhat.com>
+
+	* CExpr.g (LSQUARE): Don't use "('0'..'9')?" construct, instead
+	test the same in inline java code.
+
+2008-06-12  Petr Machata  <pmachata@redhat.com>
+
+	* FQIdentParser.java (containsGlobChar): New method.
+	* FQIdentPattern.java, FQIdentPatternAll.java: New files.
+	* FQIdentPatternExact.java, FQIdentPatternGlob.java: New files.
+	* FQIdentToken.java (globs): New field.
+	* FQIdentifier.java (soname, file, proc, symbol, version): Changed
+	type from String to FQIdentPattern.
+
+2008-06-10  Petr Machata  <pmachata@redhat.com>
+
+	* FQIdentParser.java: Implement glob parsing.
+
 2008-06-09  Petr Machata  <pmachata@redhat.com>
 
 	* FQIdentParser.java: Introduce parsing options.
diff --git a/frysk-core/frysk/expr/FQIdentParser.java b/frysk-core/frysk/expr/FQIdentParser.java
index 63035b9..86ed85a 100644
--- a/frysk-core/frysk/expr/FQIdentParser.java
+++ b/frysk-core/frysk/expr/FQIdentParser.java
@@ -52,6 +52,15 @@ import antlr.TokenStreamException;
 import antlr.InputBuffer;
 import antlr.CharBuffer;
 
+/**
+ * Funky HPD #-syntax doesn't map very well to LL-k type parser (for
+ * constant 'k').  When written directly in antlr, we obviously get
+ * lots of lexical ambiguities.  We work around that by doing
+ * arbitrary manual look-ahead and just parsing the tokens ourselves.
+ * FQIdentParser is where that parsing takes place.  Besides
+ * supporting antlr lexical analyzer, the class can be used standalone
+ * to parse arbitrary strings.
+ */
 public class FQIdentParser {
 
     private int i;
@@ -61,6 +70,18 @@ public class FQIdentParser {
     private final boolean allowGlobs;
     private final boolean expectMoreTokens;
 
+    // This pattern deliberately doesn't check for initial letter.
+    // Relevant code checks this explicitly.  This way, if user makes
+    // a mistake and writes e.g. something#123+b, we recognize "123"
+    // as a typo, while leaving out the part after a "+", which is
+    // certainly irrelevant.
+    final static String symbolRe = "[a-zA-Z0-9_$]+";
+
+    private final static Pattern symbolPattern = Pattern.compile(symbolRe);
+    private final static Pattern globPattern
+	= Pattern.compile("(\\[(\\^?\\][^\\]]*|\\^[^\\]]+|[^^\\]][^\\]]*|\\^?\\[:[^:]+:\\])\\]|"
+			  + symbolRe + "|\\*)+");
+
     /**
      * @param allowDynamic Whether the [pid.tid#frame] portion of the
      *        FQ syntax makes sense in given context.  For example it
@@ -137,6 +158,28 @@ public class FQIdentParser {
 	return matched.toString();
     }
 
+    public static boolean isGlobChar(char c) {
+	return c == '*' || c == '?' || c == '['
+	    || c == ']' || c == '^' || c == ':'
+	    || c == '-';
+    }
+
+    public static boolean containsGlobChar(String str) {
+	// If anyone finds this code stupid, and the duplication to
+	// the isGlobChar outrageous, I've chosen to do so for
+	// performance reasons.  Other tested variants include:
+	//  * iterate the string and call isGlobChar for each char
+	//  * call Matcher.find over str and regexp "[*?etc]"
+	//  * and a couple more
+	return str.indexOf('*') != -1
+	    || str.indexOf('?') != -1
+	    || str.indexOf('[') != -1
+	    || str.indexOf(']') != -1
+	    || str.indexOf('^') != -1
+	    || str.indexOf(':') != -1
+	    || str.indexOf('-') != -1;
+    }
+
     /**
      * @param initial Portion of the character stream that is part of
      *        the identifier, but was already consumed by lexer.
@@ -144,22 +187,9 @@ public class FQIdentParser {
     public FQIdentToken parse(String initial)
         throws RecognitionException, CharStreamException, TokenStreamException
     {
-	if (allowGlobs)
-	    // XXX to fool java into thinking that we use allowGlobs
-	    // when we actually don't.
-	    System.out.print("");
-
 	fqinit = initial;
 	i = 0;
 
-        /*
-         * Funky HPD #-syntax doesn't map very well to LL-k type parser (for
-         * constant 'k').  When written directly, we get lots of lexical
-         * ambiguities.  We work around that by doing arbitrary manual
-         * look-ahead and just parsing the tokens ourselves.  Any whitespace
-         * or EOF stops the lookahead.
-         */
-
         String matched = "";
         String part;
 
@@ -259,7 +289,8 @@ public class FQIdentParser {
                         if (!(Character.isJavaIdentifierStart(c)
                               || c == '@'
                               || (c == ':' && part.length() == 4
-                                  && part.equals("plt:")))) {
+                                  && part.equals("plt:"))
+			      || (allowGlobs && isGlobChar(c)))) {
 
                             // Break out early if we are already
                             // just waiting for symbol.
@@ -296,22 +327,24 @@ public class FQIdentParser {
             part = part.substring(0, v);
         }
 
-        // This is delibaretely simplified and ignores request for initial letter.
-        // This is for better error reporting below, we first snip off irrelevant
-        // parts before yelling at user that his identifier sucks.
-        Matcher m = Pattern.compile("[a-zA-Z0-9_$]+").matcher(part);
-        if (m.lookingAt()) {
-            int diff = part.length() - m.end();
-            if (diff > 0) {
-                matched = matched.substring(0, matched.length() - diff);
-                part = part.substring(0, m.end());
-            }
-        }
-        else
-            throw new RecognitionException("Expected symbol name, got `" + part + "'.");
-
-        if (!Character.isJavaIdentifierStart(part.charAt(0)))
-            throw new RecognitionException("Invalid symbol `" + part + "'.");
+	Matcher m = (allowGlobs ? globPattern : symbolPattern).matcher(part);
+	if (m.lookingAt()) {
+	    int diff = part.length() - m.end();
+	    if (diff > 0) {
+		matched = matched.substring(0, matched.length() - diff);
+		part = part.substring(0, m.end());
+	    }
+	} else
+	    throw new RecognitionException("Expected "
+					   + (allowGlobs ? "glob" : "symbol name")
+					   + ", got `" + part + "'.");
+
+	c = part.charAt(0);
+	if (!(Character.isJavaIdentifierStart(c)
+	      || (allowGlobs && isGlobChar(c))))
+	    throw new RecognitionException("Invalid symbol"
+					   + (allowGlobs ? " glob" : "" )
+					   + " `" + part + "'.");
 
         FQIdentToken tok = new FQIdentToken(CExprParserTokenTypes.IDENT, matched);
         tok.dso = partDso;
@@ -325,6 +358,7 @@ public class FQIdentParser {
         tok.threadId = partThreadId;
         tok.frameNumber = partFrameNum;
         tok.setLine(scanner.getLine());
+	tok.globs = allowGlobs;
 
         fqmatch(matched);
         tok.setColumn(scanner.getColumn() - matched.length());
diff --git a/frysk-core/frysk/expr/FQIdentToken.java b/frysk-core/frysk/expr/FQIdentPattern.java
similarity index 70%
copy from frysk-core/frysk/expr/FQIdentToken.java
copy to frysk-core/frysk/expr/FQIdentPattern.java
index fdb5f42..03e0605 100644
--- a/frysk-core/frysk/expr/FQIdentToken.java
+++ b/frysk-core/frysk/expr/FQIdentPattern.java
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2005, 2007, 2008 Red Hat Inc.
+// Copyright 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;
 
-public class FQIdentToken
-    extends antlr.CommonToken
-{
-    public String dso = null, file = null, line = null,
-	proc = null, symbol = null, version = null,
-	processId = null, threadId = null, frameNumber = null;
-    public boolean wantPlt = false;
+public interface FQIdentPattern {
+    /** Pattern will never match anything. */
+    public static final int CARD_NONE = 0;
+    /** Pattern will match at most one string. */
+    public static final int CARD_ONE = 1;
+    /** Pattern may match more than one string. */
+    public static final int CARD_MANY = 2;
+    /** Pattern will always match everything. */
+    public static final int CARD_ALL = 3;
 
-    public FQIdentToken(int t, String txt) {
-	super (t, txt);
-    }
+    /**
+     * Cardinality of this pattern.  See various CARD_ constants for
+     * possible values.
+     */
+    int cardinality();
 
-    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 : "")
-	    + (processId != null ? (", dynamic:" + processId
-				    + "." + threadId + "#" + frameNumber) : "")
-	    + "]";
-    }
+    /**
+     * Whether given string matches this pattern.  STR can be a symbol
+     * name, soname, etc.
+     */
+    boolean matches(String str);
 }
diff --git a/frysk-core/frysk/expr/FQIdentToken.java b/frysk-core/frysk/expr/FQIdentPatternAll.java
similarity index 71%
copy from frysk-core/frysk/expr/FQIdentToken.java
copy to frysk-core/frysk/expr/FQIdentPatternAll.java
index fdb5f42..4e2ad9e 100644
--- a/frysk-core/frysk/expr/FQIdentToken.java
+++ b/frysk-core/frysk/expr/FQIdentPatternAll.java
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2005, 2007, 2008 Red Hat Inc.
+// Copyright 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,24 @@
 
 package frysk.expr;
 
-public class FQIdentToken
-    extends antlr.CommonToken
-{
-    public String dso = null, file = null, line = null,
-	proc = null, symbol = null, version = null,
-	processId = null, threadId = null, frameNumber = null;
-    public boolean wantPlt = false;
-
-    public FQIdentToken(int t, String txt) {
-	super (t, txt);
+/**
+ * Pattern for part of the FQ identifier that is missing.  Missing
+ * parts match everything.
+ */
+class FQIdentPatternAll implements FQIdentPattern {
+    public int cardinality() {
+	return CARD_ALL;
+    }
+    public boolean matches(String symbolName) {
+	return true;
     }
-
     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 : "")
-	    + (processId != null ? (", dynamic:" + processId
-				    + "." + threadId + "#" + frameNumber) : "")
-	    + "]";
+	return "*";
     }
+
+    /**
+     * Since we only ever need one instance of FQIdentPatternAll
+     * class, have it handy here.
+     */
+    public static final FQIdentPatternAll instance = new FQIdentPatternAll();
 }
diff --git a/frysk-core/frysk/expr/FQIdentToken.java b/frysk-core/frysk/expr/FQIdentPatternExact.java
similarity index 71%
copy from frysk-core/frysk/expr/FQIdentToken.java
copy to frysk-core/frysk/expr/FQIdentPatternExact.java
index fdb5f42..8cdc75f 100644
--- a/frysk-core/frysk/expr/FQIdentToken.java
+++ b/frysk-core/frysk/expr/FQIdentPatternExact.java
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2005, 2007, 2008 Red Hat Inc.
+// Copyright 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,23 @@
 
 package frysk.expr;
 
-public class FQIdentToken
-    extends antlr.CommonToken
-{
-    public String dso = null, file = null, line = null,
-	proc = null, symbol = null, version = null,
-	processId = null, threadId = null, frameNumber = null;
-    public boolean wantPlt = false;
-
-    public FQIdentToken(int t, String txt) {
-	super (t, txt);
+/**
+ * Pattern for exactly specified part of FQ identifier.  Always
+ * matches at most one symbol.  If matches(a) and matches(b), then
+ * a.equals(b).
+ */
+class FQIdentPatternExact implements FQIdentPattern {
+    private final String symbolName;
+    public FQIdentPatternExact(String symbolName) {
+	this.symbolName = symbolName;
+    }
+    public int cardinality() {
+	return CARD_ONE;
+    }
+    public boolean matches(String symbolName) {
+	return symbolName.equals(this.symbolName);
     }
-
     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 : "")
-	    + (processId != null ? (", dynamic:" + processId
-				    + "." + threadId + "#" + frameNumber) : "")
-	    + "]";
+	return symbolName;
     }
 }
diff --git a/frysk-core/frysk/expr/FQIdentToken.java b/frysk-core/frysk/expr/FQIdentPatternGlob.java
similarity index 71%
copy from frysk-core/frysk/expr/FQIdentToken.java
copy to frysk-core/frysk/expr/FQIdentPatternGlob.java
index fdb5f42..918f11e 100644
--- a/frysk-core/frysk/expr/FQIdentToken.java
+++ b/frysk-core/frysk/expr/FQIdentPatternGlob.java
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2005, 2007, 2008 Red Hat Inc.
+// Copyright 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,26 @@
 
 package frysk.expr;
 
-public class FQIdentToken
-    extends antlr.CommonToken
-{
-    public String dso = null, file = null, line = null,
-	proc = null, symbol = null, version = null,
-	processId = null, threadId = null, frameNumber = null;
-    public boolean wantPlt = false;
+import java.util.regex.Pattern;
+import frysk.util.Glob;
 
-    public FQIdentToken(int t, String txt) {
-	super (t, txt);
+/**
+ * Pattern for part of FQ identifier specified by a glob.
+ */
+class FQIdentPatternGlob implements FQIdentPattern {
+    private final Pattern pattern;
+    private final String glob;
+    public FQIdentPatternGlob(String glob) {
+	this.pattern = Glob.compile(glob);
+	this.glob = glob;
+    }
+    public int cardinality() {
+	return CARD_MANY;
+    }
+    public boolean matches(String symbolName) {
+	return pattern.matcher(symbolName).matches();
     }
-
     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 : "")
-	    + (processId != null ? (", dynamic:" + processId
-				    + "." + threadId + "#" + frameNumber) : "")
-	    + "]";
+	return glob;
     }
 }
diff --git a/frysk-core/frysk/expr/FQIdentToken.java b/frysk-core/frysk/expr/FQIdentToken.java
index fdb5f42..81a56ec 100644
--- a/frysk-core/frysk/expr/FQIdentToken.java
+++ b/frysk-core/frysk/expr/FQIdentToken.java
@@ -47,6 +47,9 @@ public class FQIdentToken
 	processId = null, threadId = null, frameNumber = null;
     public boolean wantPlt = false;
 
+    /** Whether the token may contain glob expressions. */
+    public boolean globs = false;
+
     public FQIdentToken(int t, String txt) {
 	super (t, txt);
     }
diff --git a/frysk-core/frysk/expr/FQIdentifier.java b/frysk-core/frysk/expr/FQIdentifier.java
index 0859363..3b01028 100644
--- a/frysk-core/frysk/expr/FQIdentifier.java
+++ b/frysk-core/frysk/expr/FQIdentifier.java
@@ -47,30 +47,42 @@ import frysk.proc.Task;
 
 public class FQIdentifier {
 
-    final public String soname;
-    final public String file;
-    final public Long line;
-    final public String proc;
-    final public String symbol;
-    final public String version;
+    final public FQIdentPattern soname;
+    final public FQIdentPattern file;
+    final public FQIdentPattern proc;
+    final public FQIdentPattern symbol;
+    final public FQIdentPattern version;
+
     final public boolean wantPlt;


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]