public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Eliminate Input.getAction(); and the last command controlled by "argv[0]".
@ 2007-11-14  0:15 cagney
  0 siblings, 0 replies; only message in thread
From: cagney @ 2007-11-14  0:15 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  7d8807565260d2a245e35af7ee1e06473e48588c (commit)
      from  fc228ee2d3554182856206ca08158e551ed5dfcb (commit)

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

- Log -----------------------------------------------------------------
commit 7d8807565260d2a245e35af7ee1e06473e48588c
Author: Andrew Cagney <cagney@redhat.com>
Date:   Tue Nov 13 19:14:25 2007 -0500

    Eliminate Input.getAction(); and the last command controlled by "argv[0]".
    
    frysk-core/frysk/hpd/ChangeLog
    2007-11-13  Andrew Cagney  <cagney@redhat.com>
    
    	* Input.java (getAction): Delete.
    	* TestInput.java: Update.
    	* TestEvalCommands.java: Rename TestPrint.java.
    	* AssignCommand.java: Delete.
    	* PrintCommand.java: Rename to ...
    	* EvalCommands.java: ... this.  Implement "assign" as a class.
    	* TopLevelCommand.java: Update.

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

Summary of changes:
 frysk-core/frysk/hpd/AssignCommand.java            |   56 ----------
 frysk-core/frysk/hpd/ChangeLog                     |   10 ++
 .../hpd/{PrintCommand.java => EvalCommands.java}   |  114 +++++++++++---------
 frysk-core/frysk/hpd/Input.java                    |   17 +---
 .../hpd/{TestPrint.java => TestEvalCommands.java}  |    4 +-
 frysk-core/frysk/hpd/TestInput.java                |    4 -
 frysk-core/frysk/hpd/TopLevelCommand.java          |    4 +-
 7 files changed, 82 insertions(+), 127 deletions(-)
 delete mode 100644 frysk-core/frysk/hpd/AssignCommand.java
 rename frysk-core/frysk/hpd/{PrintCommand.java => EvalCommands.java} (61%)
 rename frysk-core/frysk/hpd/{TestPrint.java => TestEvalCommands.java} (98%)

First 500 lines of diff:
diff --git a/frysk-core/frysk/hpd/AssignCommand.java b/frysk-core/frysk/hpd/AssignCommand.java
deleted file mode 100644
index cf2a7e4..0000000
--- a/frysk-core/frysk/hpd/AssignCommand.java
+++ /dev/null
@@ -1,56 +0,0 @@
-// This file is part of the program FRYSK.
-//
-// Copyright 2007, 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
-// the Free Software Foundation; version 2 of the License.
-//
-// FRYSK is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-// 
-// You should have received a copy of the GNU General Public License
-// along with FRYSK; if not, write to the Free Software Foundation,
-// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-// 
-// In addition, as a special exception, Red Hat, Inc. gives You the
-// additional right to link the code of FRYSK with code not covered
-// under the GNU General Public License ("Non-GPL Code") and to
-// distribute linked combinations including the two, subject to the
-// limitations in this paragraph. Non-GPL Code permitted under this
-// exception must only link to the code of FRYSK through those well
-// defined interfaces identified in the file named EXCEPTION found in
-// the source code files (the "Approved Interfaces"). The files of
-// Non-GPL Code may instantiate templates or use macros or inline
-// functions from the Approved Interfaces without causing the
-// resulting work to be covered by the GNU General Public
-// License. Only Red Hat, Inc. may make changes or additions to the
-// list of Approved Interfaces. You must obey the GNU General Public
-// License in all respects for all of the FRYSK code and other code
-// used in conjunction with FRYSK except the Non-GPL Code covered by
-// this exception. If you modify this file, you may extend this
-// exception to your version of the file, but you are not obligated to
-// do so. If you do not wish to provide this exception without
-// modification, you must delete this exception statement from your
-// version and license this file solely under the GPL without
-// exception.
-
-package frysk.hpd;
-
-public class AssignCommand extends PrintCommand {
-
-    static String full = "The assign command evaluates a scalar expression and "
-	    + "uses the result to\n"
-	    + "replace the previous contents of a program variable. The target "
-	    + "location\n"
-	    + "may be a scalar variable, an element of an array or "
-	    + "structure/record, or\n" + "a de-referenced pointer variable.";
-
-    AssignCommand() {
-	super("assign", "Change the value of a scalar program variable.",
-	      "assign scalar-target scalar-value [-force]", full);
-    }
-
-}
diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog
index 3f07abb..6115ec8 100644
--- a/frysk-core/frysk/hpd/ChangeLog
+++ b/frysk-core/frysk/hpd/ChangeLog
@@ -1,3 +1,13 @@
+2007-11-13  Andrew Cagney  <cagney@redhat.com>
+
+	* Input.java (getAction): Delete.
+	* TestInput.java: Update.
+	* TestEvalCommands.java: Rename TestPrint.java.
+	* AssignCommand.java: Delete.
+	* PrintCommand.java: Rename to ...
+	* EvalCommands.java: ... this.  Implement "assign" as a class.
+	* TopLevelCommand.java: Update.
+
 2007-11-13  Sami Wagiaalla  <swagiaal@redhat.com>
 
 	* TestBreakpoints.java (testHpdBreakMultiThreadedContinue): Marked
diff --git a/frysk-core/frysk/hpd/PrintCommand.java b/frysk-core/frysk/hpd/EvalCommands.java
similarity index 61%
rename from frysk-core/frysk/hpd/PrintCommand.java
rename to frysk-core/frysk/hpd/EvalCommands.java
index e7b62ed..5c69032 100644
--- a/frysk-core/frysk/hpd/PrintCommand.java
+++ b/frysk-core/frysk/hpd/EvalCommands.java
@@ -47,7 +47,10 @@ import frysk.value.PointerType;
 import frysk.value.Type;
 import java.util.List;
 
-class PrintCommand extends ParameterizedCommand {
+/**
+ * Evaluate an expression; in various forms.
+ */
+abstract class EvalCommands extends ParameterizedCommand {
     private class Options {
 	Format format = Format.NATURAL;
 	boolean dumpTree = false;
@@ -56,16 +59,8 @@ class PrintCommand extends ParameterizedCommand {
 	return new Options();
     }
 
-    PrintCommand() {
-	this("print",
-	     "Evaluate and display the value of an expression.",
-	     "print expression [-format d|o|x|t]",
-	     ("The print command evaluates and displays an expression. The"
-	     + " debugger interprets the expression by looking up the"
-	      + " value(s) associated with each symbol and applying the"
-	      + " operators.  The result of an expression may be a scalar"
-	      + " value or an aggregate (array, array slice, record, or"
-	      + " structure."));
+    EvalCommands(String name, String description, String syntax, String full) {
+	super(name, description, syntax, full);
 	add(new CommandOption.FormatOption() {
 		void set(Object options, Format format) {
 		    ((Options)options).format = format;
@@ -77,46 +72,33 @@ class PrintCommand extends ParameterizedCommand {
 		}
 	    });
     }
-    
-    PrintCommand (String name, String description, String syntax, 
-		  String full) {
-	super (name, description, syntax, full);
+
+    int complete(CLI cli, PTSet ptset, String incomplete, int base,
+		 List candidates) {
+	return CompletionFactory.completeExpression(cli, ptset, incomplete,
+						    base, candidates);
     }
 
-    public void interpret(CLI cli, Input input, Object o) {
-	if (input.size() == 0)
+    static private void eval(CLI cli, PTSet ptset, String expression,
+			     Options options) {
+	if (expression.equals(""))
 	    throw new InvalidCommandException("missing expression");
-	Options options = (Options)o;
-        PTSet ptset = cli.getCommandPTSet(input);
-
-	String sInput = input.stringValue();
-	if (input.getAction().compareTo("assign") == 0) {
-	    int i = sInput.indexOf(' ');
-	    if (i == -1) {
-		throw new InvalidCommandException("bad expression XXX");
-	    }
-	    sInput = sInput.substring(0, i) + "=" + sInput.substring(i);
-	}        
-
 	Value result = null;
-        Iterator taskDataIter = ptset.getTaskData();
+	Iterator taskDataIter = ptset.getTaskData();
 	do {
-            Task task = null;
-            if (taskDataIter.hasNext()) {
+	    Task task = null;
+	    if (taskDataIter.hasNext()) {
 		TaskData td = (TaskData)taskDataIter.next();
-                task = td.getTask();
-                cli.outWriter.print("[");
-		cli.outWriter.print(td.getParentID());
-		cli.outWriter.print(".");
-		cli.outWriter.print(td.getID());
-		cli.outWriter.println("]");
-            }
-            try {
-                result = cli.parseValue(task, sInput, options.dumpTree);
-            } catch (RuntimeException nnfe) {
+		task = td.getTask();
+		td.toPrint(cli.outWriter, true);
+		cli.outWriter.println();
+	    }
+	    try {
+		result = cli.parseValue(task, expression, options.dumpTree);
+	    } catch (RuntimeException nnfe) {
 		cli.addMessage(nnfe.getMessage(), Message.TYPE_ERROR);
-                continue;
-            }
+		continue;
+	    }
 
 	    Type t = result.getType();
 	    if (t instanceof PointerType) {
@@ -128,12 +110,46 @@ class PrintCommand extends ParameterizedCommand {
 			   task == null ? null : task.getMemory(),
 			   options.format);
 	    cli.outWriter.println();
-        } while (taskDataIter.hasNext());
+	} while (taskDataIter.hasNext());
     }
 
-    int complete(CLI cli, PTSet ptset, String incomplete, int base,
-		 List candidates) {
-	return CompletionFactory.completeExpression(cli, ptset, incomplete,
-						    base, candidates);
+    static class Print extends EvalCommands {
+	Print() {
+	    super("print",
+		 "Evaluate and display the value of an expression.",
+		 "print expression [-format d|o|x|t]",
+		 ("The print command evaluates and displays an expression. The"
+		  + " debugger interprets the expression by looking up the"
+		  + " value(s) associated with each symbol and applying the"
+		  + " operators.  The result of an expression may be a scalar"
+		  + " value or an aggregate (array, array slice, record, or"
+		  + " structure."));
+	}
+	void interpret(CLI cli, Input input, Object options) {
+	    eval(cli, cli.getCommandPTSet(input), input.stringValue(),
+		 (Options)options);
+	}
+    }
+
+    static class Assign extends EvalCommands {
+	Assign() {
+	    super("assign", "Change the value of a scalar program variable.",
+		  "assign scalar-target scalar-value [-force]",
+		  ("The assign command evaluates a scalar expression and"
+		   + " uses the result to replace the previous contents"
+		   + " of a program variable. The target location may be a"
+		   + " scalar variable, an element of an array or"
+		   + " structure/record, or a de-referenced pointer"
+		   + " variable."));
+	}
+	void interpret(CLI cli, Input input, Object options) {
+	    if (input.size() < 2)
+		throw new InvalidCommandException("missing expression");
+	    String lhs = input.parameter(0);
+	    input.accept();
+	    eval(cli, cli.getCommandPTSet(input),
+		 "(" + lhs + ") = (" + input.stringValue() + ")",
+		 (Options)options);
+	}
     }
 }
diff --git a/frysk-core/frysk/hpd/Input.java b/frysk-core/frysk/hpd/Input.java
index 1b025b5..e8f450f 100644
--- a/frysk-core/frysk/hpd/Input.java
+++ b/frysk-core/frysk/hpd/Input.java
@@ -43,8 +43,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 /**
- * Command class separates and contains different parts of a command:
- * set, action, parameters.  It is immutable.
+ * Command input broken down into a series of parameters.
  */
 class Input {
 
@@ -68,13 +67,11 @@ class Input {
 
     private final String fullCommand;
     private final String set;
-    private final String action;
     private final List tokens;
 
-    private Input(String fullCommand, String set, String action, List tokens) {
+    private Input(String fullCommand, String set, List tokens) {
 	this.fullCommand = fullCommand;
 	this.set = set;
-	this.action = action;
 	this.tokens = tokens;
     }
 
@@ -89,7 +86,6 @@ class Input {
     public Input(String cmd) {
 	fullCommand = cmd;
 	tokens = tokenize(fullCommand);
-	action = null;
 	if (size() <= 0) {
 	    set = null;
 	} else {
@@ -109,10 +105,6 @@ class Input {
 	return set;
     }
 
-    public String getAction() {
-	return action;
-    }
-
     /**
      * Return the N'th parameter.
      */
@@ -183,17 +175,16 @@ class Input {
     }
 
     /**
-     * Accept the current action; advance to the next one.
+     * Accept the current parameter; advance to the next one.
      */
     Input accept() {
 	List newTokens;
-	String newAction = token(0).value;
 	if (size() > 0) {
 	    newTokens = tokens.subList(1, tokens.size());
 	} else {
 	    newTokens = tokens;
 	}
-	return new Input(fullCommand, set, newAction, newTokens);
+	return new Input(fullCommand, set, newTokens);
     }
 
     /**
diff --git a/frysk-core/frysk/hpd/TestPrint.java b/frysk-core/frysk/hpd/TestEvalCommands.java
similarity index 98%
rename from frysk-core/frysk/hpd/TestPrint.java
rename to frysk-core/frysk/hpd/TestEvalCommands.java
index 7766681..faf1158 100644
--- a/frysk-core/frysk/hpd/TestPrint.java
+++ b/frysk-core/frysk/hpd/TestEvalCommands.java
@@ -55,9 +55,7 @@ import java.io.File;
  * tests.
  */
 
-public class TestPrint
-    extends TestLib
-{
+public class TestEvalCommands extends TestLib {
     public void testUnattached() {
 	e = new HpdTestbed();
 	// Add with no process; shouldn't crash.
diff --git a/frysk-core/frysk/hpd/TestInput.java b/frysk-core/frysk/hpd/TestInput.java
index c8af94a..1f0cc6f 100644
--- a/frysk-core/frysk/hpd/TestInput.java
+++ b/frysk-core/frysk/hpd/TestInput.java
@@ -85,22 +85,18 @@ public class TestInput extends TestLib {
     public void testAccept() {
 	Input input = new Input("action p0 p1");
 	assertEquals("stringValue", "action p0 p1", input.stringValue());
-	assertNull("getAction", input.getAction());
 	check(input, new String[] { "action", "p0", "p1" });
 	//
 	input = input.accept();
 	assertEquals("stringValue at action", "p0 p1", input.stringValue());
-	assertEquals("getAction at action", "action", input.getAction());
 	check(input, new String[] { "p0", "p1" });
 	//
 	input = input.accept();
 	assertEquals("stringValue at p0", "p1", input.stringValue());
-	assertEquals("getAction at p0", "p0", input.getAction());
 	check(input, new String[] { "p1" });
 	//
 	input = input.accept();
 	assertEquals("stringValue at p1", "", input.stringValue());
-	assertEquals("getAction at p1", "p1", input.getAction());
 	check(input, new String[0]);
     }
 
diff --git a/frysk-core/frysk/hpd/TopLevelCommand.java b/frysk-core/frysk/hpd/TopLevelCommand.java
index b4bddf9..e8e1e02 100644
--- a/frysk-core/frysk/hpd/TopLevelCommand.java
+++ b/frysk-core/frysk/hpd/TopLevelCommand.java
@@ -75,7 +75,8 @@ public class TopLevelCommand extends MultiLevelCommand {
 	      "a top level command");
         add(new AliasCommands.Alias());
         add(new AliasCommands.Unalias());
-        add(new AssignCommand());
+        add(new EvalCommands.Assign());
+        add(new EvalCommands.Print());
         add(new AttachCommand());
         add(new BreakpointCommand());
         add(new DebuginfoCommand());
@@ -97,7 +98,6 @@ public class TopLevelCommand extends MultiLevelCommand {
         add(new ListCommand());
         add(new StepNextCommand());
         add(new StepNextiCommand());
-        add(new PrintCommand());
         add(new PlocationCommand());
         add(new PtypeCommand());
         add(new QuitCommand("quit"));


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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-11-14  0:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-14  0:15 [SCM] master: Eliminate Input.getAction(); and the last command controlled by "argv[0]" cagney

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).