Permalink
Browse files

Refactor coverage into an unparser, put everything in its own package…

… etc
  • Loading branch information...
1 parent 24aaed7 commit daedecc162e6b21bf9ba8a7150b0cba33162503b @olabini committed May 10, 2011
View
@@ -84,7 +84,7 @@
</javac>
<copy todir="${classes.dir}" filtering="true" overwrite="true">
- <fileset dir="${src.dir}" includes="**/*.properties"/>
+ <fileset dir="${src.dir}" includes="**/*.properties,**/*.html,**/*.css"/>
</copy>
<copy todir="${classes.dir}">
@@ -163,6 +163,8 @@
<include name="**/*.class"/>
<include name="**/*.ik"/>
<include name="**/*.properties"/>
+ <include name="**/*.html"/>
+ <include name="**/*.css"/>
</fileset>
<zipfileset src="${lib.release.dir}/jline-0.9.93.jar" includes="**/*"/>
<zipfileset src="${lib.release.dir}/joda-time-1.6.jar" includes="**/*"/>
View
@@ -1,28 +0,0 @@
-
-IKover = Origin mimic do(
- addCoverageData = method(data,
- @coverageData = data
- )
-
- processCoverage = method(
- allData = []
- coverageData each(e,
- filename = e key
- if(filename != "<init>",
- e value each(e2,
- line = e2 key
- if(line != -1,
- e2 value each(e3,
- pos = e3 key
- if(pos != -1,
- allData << [filename, line, pos, e3 value]
- )
- )
- )
- )
- )
- )
- allData sort!
- allData each(inspect println)
- )
-)
@@ -1,155 +0,0 @@
-/*
- * See LICENSE file in distribution for copyright and licensing information.
- */
-package ioke.lang;
-
-import java.io.Reader;
-import java.io.StringReader;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Map;
-import java.util.HashMap;
-
-import ioke.lang.parser.IokeParser;
-
-import ioke.lang.exceptions.ControlFlow;
-
-/**
- * @author <a href="mailto:ola.bini@gmail.com">Ola Bini</a>
- */
-public class CoverageInterpreter extends Interpreter {
- private static class CoveragePoint {
- String filename;
- String name;
- int line;
- int pos;
- int posEnd;
- IokeObject message;
-
- int count = 0;
-
- public String toString() {
- return "CoveragePoint<" + filename + ":" + line + ":" + pos + " - " + name + "(" + count + ")>";
- }
- }
-
- public final Map<String, Map<Integer, Map<Integer, CoveragePoint>>> covered = new HashMap<String, Map<Integer, Map<Integer, CoveragePoint>>>();
-
- private boolean covering = true;
-
- public void stopCovering() {
- covering = false;
- }
-
- public IokeObject iokefiedCoverageData(Runtime runtime) {
- try {
- IokeObject coveragePoint = runtime.newFromOrigin();
- coveragePoint.setKind("CoveragePoint");
- Map<Object, Object> d = new HashMap<Object, Object>();
- IokeObject result = runtime.newDict(d);
- for(Map.Entry<String, Map<Integer, Map<Integer, CoveragePoint>>> me : covered.entrySet()) {
- IokeObject k = runtime.newText(me.getKey());
- Object val = d.get(k);
- if(val == null) {
- val = runtime.newDict(new HashMap<Object, Object>());
- d.put(k, val);
- }
-
- Map<Object, Object> lineToPos = Dict.getMap(val);
-
- for(Map.Entry<Integer, Map<Integer, CoveragePoint>> me2 : me.getValue().entrySet()) {
- IokeObject k2 = runtime.newNumber(me2.getKey());
- Object val2 = lineToPos.get(k2);
- if(val2 == null) {
- val2 = runtime.newDict(new HashMap<Object, Object>());
- lineToPos.put(k2, val2);
- }
-
- Map<Object, Object> posToCoveragePoint = Dict.getMap(val2);
- for(Map.Entry<Integer, CoveragePoint> me3 : me2.getValue().entrySet()) {
- IokeObject k3 = runtime.newNumber(me3.getKey());
- IokeObject v3 = coveragePoint.mimic(null, null);
- v3.setCell("filename", runtime.newText(me3.getValue().filename));
- v3.setCell("name", runtime.newText(me3.getValue().name));
- v3.setCell("line", runtime.newNumber(me3.getValue().line));
- v3.setCell("pos", runtime.newNumber(me3.getValue().pos));
- v3.setCell("posEnd", runtime.newNumber(me3.getValue().posEnd));
- v3.setCell("message", me3.getValue().message);
- v3.setCell("count", runtime.newNumber(me3.getValue().count));
- posToCoveragePoint.put(k3, v3);
- }
- }
- }
- return result;
- } catch(ControlFlow e) {
- return null;
- }
- }
-
- private void cover(IokeObject message) throws ControlFlow {
- if(covering) {
- CoveragePoint cp = new CoveragePoint();
- cp.filename = Message.file(message);
- cp.name = Message.name(message);
- cp.line = Message.line(message);
- cp.pos = Message.position(message);
- cp.posEnd = Message.positionEnd(message);
- cp.message = message;
-
- Map<Integer, Map<Integer, CoveragePoint>> perLine = covered.get(cp.filename);
- if(perLine == null) {
- perLine = new HashMap<Integer, Map<Integer, CoveragePoint>>();
- covered.put(cp.filename, perLine);
- }
-
- Map<Integer, CoveragePoint> perPos = perLine.get(cp.line);
- if(perPos == null) {
- perPos = new HashMap<Integer, CoveragePoint>();
- perLine.put(cp.line, perPos);
- }
-
- CoveragePoint cp2 = perPos.get(cp.pos);
- if(cp2 == null) {
- cp2 = cp;
- perPos.put(cp.pos, cp2);
- }
- cp2.count++;
- }
- }
-
- @Override
- public Object evaluate(IokeObject self, IokeObject ctx, Object ground, Object receiver) throws ControlFlow {
- Runtime runtime = self.runtime;
- Object current = receiver;
- Object tmp = null;
- String name = null;
- Object lastReal = runtime.getNil();
- IokeObject m = self;
- Message msg;
- while(m != null) {
- msg = (Message)m.data;
- tmp = msg.cached;
- cover(m);
- if(tmp != null) {
- lastReal = current = tmp;
- } else if((name = msg.name.intern()) == ".") {
- current = ctx;
- } else if(name.length() > 0 && msg.arguments.size() == 0 && name.charAt(0) == ':') {
- lastReal = msg.cached = current = runtime.getSymbol(name.substring(1));
- } else {
- if((current instanceof IokeObject) || IokeRegistry.isWrapped(current, ctx)) {
- IokeObject recv = IokeObject.as(current, ctx);
- tmp = perform(recv, recv, ctx, m, name);
- } else {
- tmp = perform(current, IokeRegistry.wrap(current.getClass(), ctx), ctx, m, name);
- }
-
- lastReal = current = tmp;
- }
- m = Message.next(m);
- }
- return lastReal;
- }
-}// CoverageInterpreter
@@ -45,7 +45,6 @@ public Object activate(IokeObject method, IokeObject context, IokeObject message
mx.setFile(Message.file(message));
mx.setLine(Message.line(message));
mx.setPosition(Message.position(message));
- mx.setPositionEnd(Message.positionEnd(message));
final IokeObject mmx = context.runtime.createMessage(mx);
return runtime.newMethod(null, runtime.defaultMethod, new DefaultMethod(context, DefaultArgumentsDefinition.empty(), mmx));
}
@@ -89,7 +88,6 @@ public Object activate(IokeObject method, IokeObject context, IokeObject message
mx.setFile(Message.file(message));
mx.setLine(Message.line(message));
mx.setPosition(Message.position(message));
- mx.setPositionEnd(Message.positionEnd(message));
final IokeObject mmx = context.runtime.createMessage(mx);
return runtime.newMacro(null, runtime.defaultMacro, new DefaultMacro(context, mmx));
@@ -131,7 +129,6 @@ public Object activate(IokeObject method, IokeObject context, IokeObject message
mx.setFile(Message.file(message));
mx.setLine(Message.line(message));
mx.setPosition(Message.position(message));
- mx.setPositionEnd(Message.positionEnd(message));
final IokeObject mmx = context.runtime.createMessage(mx);
return runtime.newMacro(null, runtime.defaultSyntax, new DefaultSyntax(context, mmx));
@@ -173,7 +170,6 @@ public Object activate(IokeObject method, IokeObject context, IokeObject message
mx.setFile(Message.file(message));
mx.setLine(Message.line(message));
mx.setPosition(Message.position(message));
- mx.setPositionEnd(Message.positionEnd(message));
final IokeObject mmx = context.runtime.createMessage(mx);
return runtime.newMacro(null, runtime.lexicalMacro, new LexicalMacro(context, mmx));
@@ -505,11 +505,6 @@ public int getPosition(IokeObject self) throws ControlFlow {
return -1;
}
- public int getPositionEnd(IokeObject self) throws ControlFlow {
- report(self, self, self, "getPositionEnd");
- return -1;
- }
-
public String toString(IokeObject self) {
try {
int h = hashCode(self);
@@ -18,7 +18,7 @@
*/
public final class IokeObject implements TypeChecker {
public Runtime runtime;
- IokeData data;
+ public IokeData data;
Body body = new Body();
public static final int FALSY_F = 1 << 0;
@@ -1150,10 +1150,6 @@ public int getPosition() throws ControlFlow {
return data.getPosition(this);
}
- public int getPositionEnd() throws ControlFlow {
- return data.getPositionEnd(this);
- }
-
// TypeChecker
public Object convertToMimic(Object on, IokeObject message, IokeObject context, boolean signal) throws ControlFlow {
return convertToThis(on, signal, message, context);
@@ -12,6 +12,9 @@
import ioke.lang.exceptions.ControlFlow;
+import ioke.lang.coverage.Coverage;
+import ioke.lang.coverage.CoverageInterpreter;
+
/**
* @author <a href="mailto:ola.bini@gmail.com">Ola Bini</a>
*/
@@ -105,7 +108,6 @@ public static void main(String[] args) throws Throwable {
final Message mx = new Message(r, ".", null, true);
mx.setLine(0);
mx.setPosition(0);
- mx.setPositionEnd(0);
final IokeObject message = r.createMessage(mx);
if(debug) {
@@ -173,11 +175,7 @@ public static void main(String[] args) throws Throwable {
if(coverage) {
citer.stopCovering();
- r.evaluateString("use(\"ikover\")", r.message, r.ground);
- IokeObject ikover = (IokeObject)Interpreter.send(r.newMessage("IKover"), r.ground, r.ground);
- IokeObject iokeCoverageData = citer.iokefiedCoverageData(r);
- Interpreter.send(r.newMessage("addCoverageData"), r.ground, ikover, iokeCoverageData);
- Interpreter.send(r.newMessage("processCoverage"), r.ground, ikover);
+ Coverage.processCoverage(r, citer);
}
r.tearDown();
@@ -186,11 +184,7 @@ public static void main(String[] args) throws Throwable {
try {
if(coverage) {
citer.stopCovering();
- r.evaluateString("use(\"ikover\")", r.message, r.ground);
- IokeObject ikover = (IokeObject)Interpreter.send(r.newMessage("IKover"), r.ground, r.ground);
- IokeObject iokeCoverageData = citer.iokefiedCoverageData(r);
- Interpreter.send(r.newMessage("addCoverageData"), r.ground, ikover, iokeCoverageData);
- Interpreter.send(r.newMessage("processCoverage"), r.ground, ikover);
+ Coverage.processCoverage(r, citer);
}
r.tearDown();
Oops, something went wrong.

0 comments on commit daedecc

Please sign in to comment.