[Swift-commit] r3461 - branches/tests-01/src/org/griphyn/vdl/karajan/lib/swiftscript
noreply at svn.ci.uchicago.edu
noreply at svn.ci.uchicago.edu
Thu Jul 22 12:14:29 CDT 2010
Author: wozniak
Date: 2010-07-22 12:14:28 -0500 (Thu, 22 Jul 2010)
New Revision: 3461
Modified:
branches/tests-01/src/org/griphyn/vdl/karajan/lib/swiftscript/Tracef.java
Log:
Reorganize tracef
Modified: branches/tests-01/src/org/griphyn/vdl/karajan/lib/swiftscript/Tracef.java
===================================================================
--- branches/tests-01/src/org/griphyn/vdl/karajan/lib/swiftscript/Tracef.java 2010-07-22 16:55:44 UTC (rev 3460)
+++ branches/tests-01/src/org/griphyn/vdl/karajan/lib/swiftscript/Tracef.java 2010-07-22 17:14:28 UTC (rev 3461)
@@ -22,9 +22,11 @@
Format specifiers: <br>
%%: % sign. <br>
%p: Not typechecked, output as in trace(). <br>
+ %f: Typechecked float output. <br>
%i: Typechecked int output. <br>
%s: Typechecked string output. <br>
- %k: Variable sKipped, no output.
+ %k: Variable sKipped, no output. <br>
+ %q: Array output
*/
public class Tracef extends VDLFunction {
@@ -90,89 +92,113 @@
throw new ExecutionException
("tracef(): too many specifiers!");
}
- if (c == 'p') {
+ if (c == 'M') {
+ append_M(args[arg], output);
+ }
+ else if (c == 'f') {
+ append_f(args[arg], output);
+ }
+ else if (c == 'i') {
+ append_i(args[arg], output);
+ }
+ else if (c == 'p') {
output.append(args[arg].toString());
}
- else if (c == 'M') {
- try {
- synchronized (args[arg].getRoot()) {
- String[] names = VDLFunction.filename(args[arg]);
- if (names.length > 1)
- output.append(names);
- else
- output.append(names[0]);
- }
- }
- catch (Exception e) {
- throw new ExecutionException
- ("tracef(%M): Could not lookup: " + args[arg]);
- }
- }
else if (c == 's') {
- if (args[arg].getType() == Types.STRING) {
- output.append(args[arg]).toString();
- }
- else {
- throw new ExecutionException
- ("tracef(): %s requires a string!");
- }
+ append_s(args[arg], output);
}
- else if (c == 'i') {
- if (args[arg].getType() == Types.INT) {
- output.append(args[arg]).toString();
- }
- else {
- throw new ExecutionException
- ("tracef(): %i requires an int!");
- }
+ else if (c == 'q') {
+ append_q(args[arg], output);
}
- else if (c == 'f') {
- if (args[arg].getType() == Types.FLOAT) {
- output.append(args[arg]).toString();
+ else if (c == 'k') {
+ ;
+ }
+ else {
+ throw new ExecutionException
+ ("tracef(): Unknown format: %" + c);
+ }
+ return arg+1;
+ }
+
+ private void append_M(DSHandle arg, StringBuffer output)
+ throws ExecutionException {
+ try {
+ synchronized (arg.getRoot()) {
+ String[] names = VDLFunction.filename(arg);
+ if (names.length > 1)
+ output.append(names);
+ else
+ output.append(names[0]);
}
- else {
- throw new ExecutionException
- ("tracef(): %f requires a float!");
- }
}
- else if (c == 'q') {
- if (args[arg] instanceof ArrayDataNode) {
- ArrayDataNode node = (ArrayDataNode) args[arg];
- output.append("[");
- try {
- int size = node.size();
- for (int i = 0; i < size; i++) {
- String entry = ""+i;
- DSHandle handle =
- node.getField(Path.parse(entry));
- output.append(handle);
- if (i < size-1)
- output.append(",");
- }
+ catch (Exception e) {
+ throw new ExecutionException
+ ("tracef(%M): Could not lookup: " + arg);
+ }
+ }
+
+ private void append_f(DSHandle arg, StringBuffer output)
+ throws ExecutionException {
+ if (arg.getType() == Types.FLOAT) {
+ output.append(arg).toString();
+ }
+ else {
+ throw new ExecutionException
+ ("tracef(): %f requires a float!");
+ }
+ }
+
+ private void append_i(DSHandle arg, StringBuffer output)
+ throws ExecutionException {
+ if (arg.getType() == Types.INT) {
+ output.append(arg).toString();
+ }
+ else {
+ throw new ExecutionException
+ ("tracef(): %i requires an int!");
+ }
+ }
+
+ private void append_q(DSHandle arg, StringBuffer output)
+ throws ExecutionException {
+ if (arg instanceof ArrayDataNode) {
+ ArrayDataNode node = (ArrayDataNode) arg;
+ output.append("[");
+ try {
+ int size = node.size();
+ for (int i = 0; i < size; i++) {
+ String entry = ""+i;
+ DSHandle handle =
+ node.getField(Path.parse(entry));
+ output.append(handle);
+ if (i < size-1)
+ output.append(",");
}
- catch (Exception e) {
- e.printStackTrace();
- throw new ExecutionException
- ("trace(%q): Could not get children of: " +
- args[arg]);
- }
- output.append("]");
}
- else {
+ catch (Exception e) {
+ e.printStackTrace();
throw new ExecutionException
- ("tracef(): %q requires an array!");
+ ("trace(%q): Could not get children of: " + arg);
}
+ output.append("]");
}
- else if (c == 'k') {
- ;
+ else {
+ throw new ExecutionException
+ ("tracef(): %q requires an array!");
+ }
+ }
+
+ private void append_s(DSHandle arg, StringBuffer output)
+ throws ExecutionException {
+ if (arg.getType() == Types.STRING) {
+ output.append(arg).toString();
}
else {
throw new ExecutionException
- ("tracef(): Unknown format: %" + c);
+ ("tracef(): %s requires a string!");
}
- return arg+1;
}
-
+
private void escape(char c, StringBuffer output)
throws ExecutionException {
if (c == '\\') {
More information about the Swift-commit
mailing list