You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vxquery.apache.org by vi...@apache.org on 2010/02/05 16:19:46 UTC
svn commit: r906965 [3/3] - in /incubator/vxquery/trunk/vxquery/src:
main/java/org/apache/vxquery/api/
main/java/org/apache/vxquery/compiler/expression/
main/java/org/apache/vxquery/compiler/rewriter/
main/java/org/apache/vxquery/compiler/rewriter/fram...
Modified: incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryCompiler.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryCompiler.java?rev=906965&r1=906964&r2=906965&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryCompiler.java (original)
+++ incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryCompiler.java Fri Feb 5 15:19:44 2010
@@ -1,13 +1,11 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
+ * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,12 +19,13 @@
import org.apache.vxquery.xmlquery.ast.ModuleNode;
public class XMLQueryCompiler {
- public static Module compile(ModuleNode moduleNode, CompilerControlBlock ccb) throws SystemException {
- return compile(NoopXQueryCompilationListener.INSTANCE, moduleNode, ccb);
+ public static Module compile(ModuleNode moduleNode, CompilerControlBlock ccb, int optimizationLevel)
+ throws SystemException {
+ return compile(NoopXQueryCompilationListener.INSTANCE, moduleNode, ccb, optimizationLevel);
}
- public static Module compile(XQueryCompilationListener listener, ModuleNode moduleNode, CompilerControlBlock ccb)
- throws SystemException {
+ public static Module compile(XQueryCompilationListener listener, ModuleNode moduleNode, CompilerControlBlock ccb,
+ int optimizationLevel) throws SystemException {
if (listener == null) {
listener = NoopXQueryCompilationListener.INSTANCE;
}
@@ -34,6 +33,8 @@
listener.notifyTranslationResult(module);
XMLQueryTypeChecker.typeCheckModule(module);
listener.notifyTypecheckResult(module);
+ XMLQueryOptimizer.optimize(module, optimizationLevel);
+ listener.notifyOptimizedResult(module);
XMLQueryCodeGenerator.codegenModule(module);
listener.notifyCodegenResult(module);
return module;
Added: incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryOptimizer.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryOptimizer.java?rev=906965&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryOptimizer.java (added)
+++ incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryOptimizer.java Fri Feb 5 15:19:44 2010
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.vxquery.xmlquery.query;
+
+import java.util.Iterator;
+
+import org.apache.vxquery.compiler.expression.ExpressionHandle;
+import org.apache.vxquery.compiler.rewriter.framework.RulesetDriver;
+import org.apache.vxquery.compiler.rewriter.rulesets.DefaultRulesetProviderImpl;
+import org.apache.vxquery.context.StaticContext;
+import org.apache.vxquery.functions.Function;
+import org.apache.vxquery.functions.UserDefinedXQueryFunction;
+
+final class XMLQueryOptimizer {
+ static void optimize(Module module, int optimizationLevel) {
+ StaticContext sCtx = module.getModuleContext();
+ for (Iterator<Function> i = sCtx.listFunctions(); i.hasNext();) {
+ Function f = i.next();
+ if (Function.FunctionTag.UDXQUERY.equals(f.getTag())) {
+ UserDefinedXQueryFunction udf = (UserDefinedXQueryFunction) f;
+ optimize(udf.getBody(), optimizationLevel);
+ }
+ }
+ if (module.getBody() != null) {
+ optimize(module.getBody(), optimizationLevel);
+ }
+ }
+
+ private static void optimize(ExpressionHandle handle, int optimizationLevel) {
+ RulesetDriver rd = new RulesetDriver();
+ rd.rewrite(handle, DefaultRulesetProviderImpl.INSTANCE.createRuleset(), optimizationLevel);
+ }
+}
\ No newline at end of file
Modified: incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryTranslator.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryTranslator.java?rev=906965&r1=906964&r2=906965&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryTranslator.java (original)
+++ incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryTranslator.java Fri Feb 5 15:19:44 2010
@@ -315,7 +315,7 @@
case MAIN_MODULE: {
MainModuleNode mmNode = (MainModuleNode) moduleNode;
QueryBodyNode qbNode = mmNode.getQueryBody();
- module.setBody(translateExpression(qbNode.getExpression()));
+ module.getBody().set(translateExpression(qbNode.getExpression()));
break;
}
@@ -515,7 +515,7 @@
Expression bodyExpr = translateExpression(node.getBody());
bodyExpr = new TreatExpression(currCtx, bodyExpr, sign.getReturnType());
popVariableScope();
- f.setBody(bodyExpr);
+ f.getBody().set(bodyExpr);
}
break;
}
@@ -1361,7 +1361,7 @@
}
if (flwor != null) {
popVariableScope();
- flwor.setReturnExpression(ctxExpr);
+ flwor.getReturnExpression().set(ctxExpr);
ctxExpr = wrapSortAndDistinctNodesOrAtomics(flwor, asc);
}
}
@@ -1497,8 +1497,9 @@
clauses
.add(new FLWORExpression.WhereClause(new IfThenElseExpression(currCtx, typeTest, posTest, boolTest)));
- innerFLWOR.setReturnExpression(new VariableReferenceExpression(currCtx, varScope
- .lookupVariable(XMLQueryCompilerConstants.DOT_VAR_NAME)));
+ innerFLWOR.getReturnExpression().set(
+ new VariableReferenceExpression(currCtx, varScope
+ .lookupVariable(XMLQueryCompilerConstants.DOT_VAR_NAME)));
ctxExpr = innerFLWOR;
popVariableScope();
Modified: incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryTypeChecker.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryTypeChecker.java?rev=906965&r1=906964&r2=906965&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryTypeChecker.java (original)
+++ incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryTypeChecker.java Fri Feb 5 15:19:44 2010
@@ -1,19 +1,17 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.vxquery.xmlquery.query;
import java.util.HashMap;
@@ -73,7 +71,7 @@
Function f = i.next();
if (Function.FunctionTag.UDXQUERY.equals(f.getTag())) {
UserDefinedXQueryFunction udf = (UserDefinedXQueryFunction) f;
- Expression body = udf.getBody();
+ Expression body = udf.getBody().get();
body.accept(new ExpressionTypeChecker());
}
}
Modified: incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XQueryCompilationListener.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XQueryCompilationListener.java?rev=906965&r1=906964&r2=906965&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XQueryCompilationListener.java (original)
+++ incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XQueryCompilationListener.java Fri Feb 5 15:19:44 2010
@@ -1,25 +1,25 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.vxquery.xmlquery.query;
public interface XQueryCompilationListener {
public void notifyTranslationResult(Module module);
-
+
public void notifyTypecheckResult(Module module);
-
+
public void notifyCodegenResult(Module module);
+
+ public void notifyOptimizedResult(Module module);
}
\ No newline at end of file
Modified: incubator/vxquery/trunk/vxquery/src/test/java/org/apache/vxquery/xmlquery/query/SimpleXQueryTest.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/src/test/java/org/apache/vxquery/xmlquery/query/SimpleXQueryTest.java?rev=906965&r1=906964&r2=906965&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/src/test/java/org/apache/vxquery/xmlquery/query/SimpleXQueryTest.java (original)
+++ incubator/vxquery/trunk/vxquery/src/test/java/org/apache/vxquery/xmlquery/query/SimpleXQueryTest.java Fri Feb 5 15:19:44 2010
@@ -1,13 +1,11 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
+ * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -160,7 +158,8 @@
private static void runTestInternal(String testName, String query) throws SystemException {
InternalAPI iapi = new InternalAPI(new DTMDatamodelStaticInterfaceImpl());
- OpenableCloseableIterator ri = iapi.execute(iapi.compile(null, iapi.parse(testName, new StringReader(query))));
+ OpenableCloseableIterator ri = iapi.execute(iapi.compile(null, iapi.parse(testName, new StringReader(query)),
+ Integer.MAX_VALUE));
ri.open();
System.err.println("--- Results begin");
XDMValue o;
Modified: incubator/vxquery/trunk/vxquery/src/test/java/org/apache/vxquery/xtest/TestRunnerFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/src/test/java/org/apache/vxquery/xtest/TestRunnerFactory.java?rev=906965&r1=906964&r2=906965&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/src/test/java/org/apache/vxquery/xtest/TestRunnerFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/src/test/java/org/apache/vxquery/xtest/TestRunnerFactory.java Fri Feb 5 15:19:44 2010
@@ -67,7 +67,7 @@
} finally {
in.close();
}
- Module module = iapi.compile(null, ast);
+ Module module = iapi.compile(null, ast, opts.optimizationLevel);
for (PrologVariable pVar : module.getPrologVariables()) {
GlobalVariable var = pVar.getVariable();
QName varName = var.getName();
Modified: incubator/vxquery/trunk/vxquery/src/test/java/org/apache/vxquery/xtest/XTestOptions.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/src/test/java/org/apache/vxquery/xtest/XTestOptions.java?rev=906965&r1=906964&r2=906965&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/src/test/java/org/apache/vxquery/xtest/XTestOptions.java (original)
+++ incubator/vxquery/trunk/vxquery/src/test/java/org/apache/vxquery/xtest/XTestOptions.java Fri Feb 5 15:19:44 2010
@@ -17,6 +17,9 @@
import org.kohsuke.args4j.Option;
public class XTestOptions {
+ @Option(name = "-O", required = false, usage = "Optimization Level")
+ int optimizationLevel = Integer.MAX_VALUE;
+
@Option(name = "-port", required = false, usage = "Port for web server to listen on")
int port;