<html>
<head>
<style><!--
body {background-color:#ffffff;}
.file {border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;}
.pathname {font-family:monospace; float:right;}
.fileheader {margin-bottom:.5em;}
.diff {margin:0;}
.tasklist {padding:4px;border:1px dashed #000000;margin-top:1em;}
.tasklist ul {margin-top:0;margin-bottom:0;}
tr.alt {background-color:#eeeeee}
#added {background-color:#ddffdd;}
#addedchars {background-color:#99ff99;font-weight:bolder;}
tr.alt #added {background-color:#ccf7cc;}
#removed {background-color:#ffdddd;}
#removedchars {background-color:#ff9999;font-weight:bolder;}
tr.alt #removed {background-color:#f7cccc;}
#copied {background-color:#ccccff;}
tr.alt #copied {background-color:#bbbbf7;}
#info {color:#888888;}
#context {background-color:#eeeeee;}
td {padding-left:.3em;padding-right:.3em;}
tr.head {border-bottom-width:1px;border-bottom-style:solid;}
tr.head td {padding:0;padding-top:.2em;}
.task {background-color:#ffff00;}
.comment {white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;padding:4px;border:1px dashed #000000;background-color:#ffffdd}
.error {color:red;}
hr {border-width:0px;height:2px;background:black;}
--></style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head"><td colspan="5">Commit in <b><tt>metaas/trunk/src</tt></b></td></tr>
<tr><td><tt>main/java/uk/co/badgersinfoil/metaas/<a href="#file1">ActionScriptFactory.java</a></tt> </td><td></td><td align="right" id="added">+6</td><td align="right" id="removed">-1</td><td nowrap="nowrap" align="center">525 -> 526</td></tr>
<tr class="alt"><td><tt>main/java/uk/co/badgersinfoil/metaas/impl/<a href="#file2">ASTASBinaryExpression.java</a></tt> </td><td></td><td align="right" id="added">+4</td><td align="right" id="removed">-2</td><td nowrap="nowrap" align="center">525 -> 526</td></tr>
<tr><td><tt> /<a href="#file3">ASTBuilder.java</a></tt> </td><td></td><td align="right" id="added">+8</td><td></td><td nowrap="nowrap" align="center">525 -> 526</td></tr>
<tr class="alt"><td><tt>test/java/uk/co/badgersinfoil/metaas/<a href="#file4"><span id="added">ExpressionTransplantTests.java</span></a></tt> </td><td></td><td align="right" id="added">+28</td><td></td><td nowrap="nowrap" align="right">added 526</td></tr>
<tr><td></td><td></td><td align="right" id="added">+46</td><td align="right" id="removed">-3</td><td></td></tr>
</table>
<small id="info">1 added + 3 modified, total 4 files</small><br />
<div class="tasklist"><ul>
<li><a href="#task1">TODO: handle operator precedence issues</a></li>
</ul></div>
<pre class="comment">
assert that an AST subtree doesn't get added in two different places at once
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname">metaas/trunk/src/main/java/uk/co/badgersinfoil/metaas</span><br />
<div class="fileheader"><big><b>ActionScriptFactory.java</b></big> <small id="info">525 -> 526</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/metaas/ActionScriptFactory.java        2007-09-02 14:42:07 UTC (rev 525)
+++ trunk/src/main/java/uk/co/badgersinfoil/metaas/ActionScriptFactory.java        2007-09-02 16:40:16 UTC (rev 526)
@@ -22,7 +22,6 @@
</small></pre><pre class="diff" id="context"> import uk.co.badgersinfoil.metaas.dom.ASIntegerLiteral;
import uk.co.badgersinfoil.metaas.impl.AS3FragmentParser;
import uk.co.badgersinfoil.metaas.impl.ASTASArrayAccessExpression;
</pre><pre class="diff" id="removed">-import uk.co.badgersinfoil.metaas.impl.ASTASBinaryExpression;
</pre><pre class="diff" id="context"> import uk.co.badgersinfoil.metaas.impl.ASTASExpression;
import uk.co.badgersinfoil.metaas.impl.ASTASInvocationExpression;
import uk.co.badgersinfoil.metaas.impl.ASTASNewExpression;
</pre><pre class="diff"><small id="info">@@ -231,6 +230,7 @@
</small></pre><pre class="diff" id="context">         private ASPrefixExpression newPrefixExpression(LinkedListToken op, ASExpression sub) {
                LinkedListTree ast = ASTUtils.newAST(op);
                LinkedListTree subExpr = ((ASTASExpression)sub).getAST();
</pre><pre class="diff" id="added">+                ASTBuilder.assertNoParent("sub-expression", subExpr);
</pre><pre class="diff" id="context">                 ast.addChildWithTokens(subExpr);
                return new ASTASPrefixExpression(ast);
        }
</pre><pre class="diff"><small id="info">@@ -258,6 +258,7 @@
</small></pre><pre class="diff" id="context">         private ASPostfixExpression newPostfixExpression(LinkedListToken op, ASExpression sub) {
                LinkedListTree ast = ASTUtils.newAST(op);
                LinkedListTree subExpr = ((ASTASExpression)sub).getAST();
</pre><pre class="diff" id="added">+                ASTBuilder.assertNoParent("sub-expression", subExpr);
</pre><pre class="diff" id="context">                 ast.addChild(subExpr);
                ast.setStartToken(subExpr.getStartToken());
                subExpr.getStopToken().setNext(op);
</pre><pre class="diff"><small id="info">@@ -276,6 +277,7 @@
</small></pre><pre class="diff" id="context">                 LinkedListTree ast = ASTUtils.newAST(AS3Parser.NEW, "new");
                ast.appendToken(TokenBuilder.newSpace());
                LinkedListTree subExpr = ((ASTASExpression)subexpression).getAST();
</pre><pre class="diff" id="added">+                ASTBuilder.assertNoParent("sub-expression", subExpr);
</pre><pre class="diff" id="context">                 // TODO: recursively check the given subexpression
                ast.addChildWithTokens(subExpr);
                LinkedListTree arguments = ASTUtils.newParentheticAST(AS3Parser.ARGUMENTS, AS3Parser.LPAREN, "(", AS3Parser.RPAREN, ")");
</pre><pre class="diff"><small id="info">@@ -288,6 +290,7 @@
</small></pre><pre class="diff" id="context">         public ASInvocationExpression newInvocationExpression(ASExpression sub, List args) {
                LinkedListTree ast = ASTUtils.newImaginaryAST(AS3Parser.METHOD_CALL);
                LinkedListTree subExpr = ((ASTASExpression)sub).getAST();
</pre><pre class="diff" id="added">+                ASTBuilder.assertNoParent("sub-expression", subExpr);
</pre><pre class="diff" id="context">                 // TODO: recursively check the given subexpression
                ast.addChildWithTokens(subExpr);
                LinkedListTree arguments = ASTUtils.newParentheticAST(AS3Parser.ARGUMENTS, AS3Parser.LPAREN, "(", AS3Parser.RPAREN, ")");
</pre><pre class="diff"><small id="info">@@ -302,10 +305,12 @@
</small></pre><pre class="diff" id="context">         {
                LinkedListTree ast = ASTUtils.newImaginaryAST(AS3Parser.ARRAY_ACC);
                LinkedListTree targetExpr = ((ASTASExpression)target).getAST();
</pre><pre class="diff" id="added">+                ASTBuilder.assertNoParent("target expression", targetExpr);
</pre><pre class="diff" id="context">                 // TODO: recursively check the given subexpression
                ast.addChildWithTokens(targetExpr);
                ast.appendToken(TokenBuilder.newLBrack());
                LinkedListTree subscriptExpr = ((ASTASExpression)subscript).getAST();
</pre><pre class="diff" id="added">+                ASTBuilder.assertNoParent("subscript expression", subscriptExpr);
</pre><pre class="diff" id="context">                 ast.addChildWithTokens(subscriptExpr);
                ast.appendToken(TokenBuilder.newRBrack());
                ASTASArrayAccessExpression result = new ASTASArrayAccessExpression(ast);
</pre></div>
<hr /><a name="file2" /><div class="file">
<span class="pathname">metaas/trunk/src/main/java/uk/co/badgersinfoil/metaas/impl</span><br />
<div class="fileheader"><big><b>ASTASBinaryExpression.java</b></big> <small id="info">525 -> 526</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/metaas/impl/ASTASBinaryExpression.java        2007-09-02 14:42:07 UTC (rev 525)
+++ trunk/src/main/java/uk/co/badgersinfoil/metaas/impl/ASTASBinaryExpression.java        2007-09-02 16:40:16 UTC (rev 526)
@@ -37,7 +37,9 @@
</small></pre><pre class="diff" id="context">
        private void setSubexpression(int index, ASExpression subexpression) {
                ASTASExpression sub = (ASTASExpression)subexpression;
</pre><pre class="diff" id="removed">-                // TODO: handle operator precidence issues
-                ast.setChildWithTokens(index, sub.getAST());
</pre><pre class="diff" id="added">+                LinkedListTree ast = sub.getAST();
+                ASTBuilder.assertNoParent("expression", ast);
<a name="task1" />+                // <span class="task">TODO</span>: handle operator precedence issues
+                ast.setChildWithTokens(index, ast);
</pre><pre class="diff" id="context">         }
}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file3" /><div class="file">
<span class="pathname">metaas/trunk/src/main/java/uk/co/badgersinfoil/metaas/impl</span><br />
<div class="fileheader"><big><b>ASTBuilder.java</b></big> <small id="info">525 -> 526</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/metaas/impl/ASTBuilder.java        2007-09-02 14:42:07 UTC (rev 525)
+++ trunk/src/main/java/uk/co/badgersinfoil/metaas/impl/ASTBuilder.java        2007-09-02 16:40:16 UTC (rev 526)
@@ -323,6 +323,7 @@
</small></pre><pre class="diff" id="context">         public static ASBinaryExpression newBinaryExpression(LinkedListToken op, ASExpression left, ASExpression right) {
                LinkedListTree ast = ASTUtils.newAST(op);
                LinkedListTree leftExpr = ((ASTASExpression)left).getAST();
</pre><pre class="diff" id="added">+                assertNoParent("left-hand expression", leftExpr);
</pre><pre class="diff" id="context">                 LinkedListTree rightExpr = ((ASTASExpression)right).getAST();
                if (precidence(ast) < precidence(leftExpr)) {
                        leftExpr = parenthise(leftExpr);
</pre><pre class="diff"><small id="info">@@ -342,6 +343,13 @@
</small></pre><pre class="diff" id="context">                 return new ASTASBinaryExpression(ast);
        }
</pre><pre class="diff" id="added">+        public static void assertNoParent(String astDescription, LinkedListTree ast)
+        {
+                if (ast.getParent() != null) {
+                        throw new SyntaxException(astDescription+" cannot be added to a second parent node");
+                }
+        }
+
</pre><pre class="diff" id="context">         private static LinkedListTree parenthise(LinkedListTree expr) {
                LinkedListTree result = ASTUtils.newParentheticAST(AS3Parser.ENCPS_EXPR, AS3Parser.LPAREN, "(", AS3Parser.RPAREN, ")");
                result.addChildWithTokens(expr);
</pre></div>
<hr /><a name="file4" /><div class="file">
<span class="pathname" id="added">metaas/trunk/src/test/java/uk/co/badgersinfoil/metaas</span><br />
<div class="fileheader" id="added"><big><b>ExpressionTransplantTests.java</b></big> <small id="info">added at 526</small></div>
<pre class="diff"><small id="info">--- trunk/src/test/java/uk/co/badgersinfoil/metaas/ExpressionTransplantTests.java         (rev 0)
+++ trunk/src/test/java/uk/co/badgersinfoil/metaas/ExpressionTransplantTests.java        2007-09-02 16:40:16 UTC (rev 526)
@@ -0,0 +1,28 @@
</small></pre><pre class="diff" id="added">+package uk.co.badgersinfoil.metaas;
+
+import uk.co.badgersinfoil.metaas.dom.ASBinaryExpression;
+import junit.framework.TestCase;
+
+public class ExpressionTransplantTests extends TestCase {
+        private ActionScriptFactory fact = new ActionScriptFactory();
+        public void testBinaryNew() {
+                ASBinaryExpression source = (ASBinaryExpression)fact.newExpression("3*7");
+                try {
+                        fact.newAddExpression(source.getLeftSubexpression(),
+                         fact.newIntegerLiteral(1));
+                        fail("adding node to a second subtree should fail");
+                } catch (SyntaxException e) {
+                        // expected
+                }
+        }
+        public void testBinarySet() {
+                ASBinaryExpression target = (ASBinaryExpression)fact.newExpression("foo + bar");
+                ASBinaryExpression source = (ASBinaryExpression)fact.newExpression("3*7");
+                try {
+                        target.setLeftSubexpression(source.getLeftSubexpression());
+                        fail("adding node to a second subtree should fail");
+                } catch (SyntaxException e) {
+                        // expected
+                }
+        }
+}
</pre></div>
<center><small><a href="http://www.badgers-in-foil.co.uk/projects/cvsspam/" title="commit -> email">CVSspam</a> 0.2.12</small></center>
</body></html>