- Cleaned up the package structure in the compiler-build-tools
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/a656f9bb Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/a656f9bb Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/a656f9bb Branch: refs/heads/develop Commit: a656f9bb199f2f888392256096fb2f3d842c2163 Parents: 18cbf70 Author: Christofer Dutz <[email protected]> Authored: Sat Jul 9 13:03:55 2016 +0200 Committer: Christofer Dutz <[email protected]> Committed: Sat Jul 9 13:03:55 2016 +0200 ---------------------------------------------------------------------- .../UnknownTreeHandlerGeneratorMojo.java | 76 ----- .../codegen/UnknownTreePatternInputOutput.java | 306 ------------------- .../UnknownTreeHandlerGeneratorMojo.java | 76 +++++ .../UnknownTreePatternInputOutput.java | 306 +++++++++++++++++++ compiler/build.xml | 2 +- 5 files changed, 383 insertions(+), 383 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/a656f9bb/compiler-build-tools/src/main/java/org/apache/flex/compiler/internal/as/codegen/UnknownTreeHandlerGeneratorMojo.java ---------------------------------------------------------------------- diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/internal/as/codegen/UnknownTreeHandlerGeneratorMojo.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/internal/as/codegen/UnknownTreeHandlerGeneratorMojo.java deleted file mode 100644 index 4551cab..0000000 --- a/compiler-build-tools/src/main/java/org/apache/flex/compiler/internal/as/codegen/UnknownTreeHandlerGeneratorMojo.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2001-2005 The Apache Software Foundation. - * - * Licensed 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.flex.compiler.internal.as.codegen; - -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.project.MavenProject; - -import java.io.File; - -/** - * Goal which touches a timestamp file. - */ -@Mojo(name="generate-unknown-tree-handler",defaultPhase = LifecyclePhase.GENERATE_SOURCES) -public class UnknownTreeHandlerGeneratorMojo - extends AbstractMojo -{ - @Parameter(defaultValue="${project.basedir}/src/main/unknowntreehandler",property="inputDir",required=true) - private File inputDir; - - @Parameter(property="inputFile",required=true) - private String inputFile; - - @Parameter(defaultValue="${project.build.directory}/generated-sources/unknowntreehandler",property="outputDir",required=true) - private File outputDirectory; - - @Parameter(property="outputFile",required=true) - private String outputFile; - - @Parameter(defaultValue="${project}") - private MavenProject project; - - public void execute() - throws MojoExecutionException - { - File input = new File(inputDir, inputFile); - if(!input.exists()) { - throw new MojoExecutionException("Could not read file: " + input.getAbsolutePath()); - } - - // Make sure the output directory exists. - File output = new File(outputDirectory, outputFile); - if(!output.getParentFile().exists()) { - if(!output.getParentFile().mkdirs()) { - throw new MojoExecutionException("Could not create output directory: " + - output.getParentFile().getAbsolutePath()); - } - } - - String[] args = {input.getAbsolutePath(), output.getAbsolutePath()}; - try { - UnknownTreePatternInputOutput.main(args); - } catch(Exception e) { - throw new MojoExecutionException("Caught error while executing UnknownTreePatternInputOutput.main", e); - } - - project.addCompileSourceRoot(outputDirectory.getPath()); - } -} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/a656f9bb/compiler-build-tools/src/main/java/org/apache/flex/compiler/internal/as/codegen/UnknownTreePatternInputOutput.java ---------------------------------------------------------------------- diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/internal/as/codegen/UnknownTreePatternInputOutput.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/internal/as/codegen/UnknownTreePatternInputOutput.java deleted file mode 100644 index f551331..0000000 --- a/compiler-build-tools/src/main/java/org/apache/flex/compiler/internal/as/codegen/UnknownTreePatternInputOutput.java +++ /dev/null @@ -1,306 +0,0 @@ -/* - * - * 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.flex.compiler.internal.as.codegen; - -import java.io.PrintWriter; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.Stack; - -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.xml.sax.Attributes; -import org.xml.sax.ext.DefaultHandler2; - -/** - * UnknownTreePatternInputOutput is a support class that reads - * an XML file with template data and populates a map of finding templates, - * and may also write this map out as Java code to be copied into - * the UnknownTreeHandler as hard-coded patterns. - */ -class UnknownTreePatternInputOutput extends DefaultHandler2 -{ - /** - * The map of templates by node ID to read into. - */ - Map<String, ArrayList<Template>> destination; - - /** - * Package name to use. Hard-coded for now. - */ - String packageName = "org.apache.flex.compiler.internal.as.codegen"; - - /** - * Class name to use. Also hard-coded. - */ - String className = "UnknownTreeHandlerPatterns"; - - /** - * Emitter to use. Hard-coded. - */ - String emitterName = "org.apache.flex.compiler.internal.as.codegen.CmcEmitter"; - - /** - * Load a map of templates from an XML file. - * @param pattern_file - the path of the XML pattern file. - * @param dest - the destination map. - */ - boolean load(String pattern_file, Map<String, ArrayList<Template>> dest) - { - this.destination = dest; - - try - { - SAXParserFactory factory = SAXParserFactory.newInstance(); - factory.setNamespaceAware(true); - - SAXParser parser = factory.newSAXParser(); - parser.parse( new java.io.FileInputStream(pattern_file), this); - return true; - } - catch ( Throwable load_failed ) - { - System.err.println("Load of " + pattern_file + " failed!"); - load_failed.printStackTrace(); - return false; - } - } - - /** - * This stack tracks UnknownTreeFindingTemplate objects from - * their startElement event to their endElement event; - * it's used to create the pattern/subpattern hierarchy. - */ - Stack<Template> nodeStack = new Stack<Template>(); - - /** - * Create new UnknownTreeFindingTemplate objects in response to Pattern - * elements, and decode the Pattern's attributes. - */ - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) - { - if ( ! (localName.equals("Pattern")) ) - { - if ( ! (localName.equals("SEW")) ) - System.err.println("Unknown element " + localName); - return; - } - - Template template = new Template(); - - for ( int index = 0; index < attributes.getLength(); index++) - { - String attr_name = attributes.getLocalName(index); - String attr_value = attributes.getValue(index); - - if ( "ID".equals(attr_name) ) - { - template.id = attr_value; - } - else if ( "cantHaveState".equals(attr_name) ) - { - String state_id = "__" + attr_value + "_NT"; - template.cantHaveState = state_id; - } - else if ( "mustHaveState".equals(attr_name) ) - { - String state_id = "__" + attr_value + "_NT"; - template.mustHaveState = state_id; - } - else if ( "problem".equals(attr_name) ) - { - String class_name; - if ( attr_value.startsWith("org.apache.") ) - class_name = attr_value; - else - class_name = "org.apache.flex.compiler.problems." + attr_value; - template.problemClass = class_name; - } - else if ( "nodeClass".equals(attr_name) ) - { - String class_name; - if ( attr_value.startsWith("org.apache.") ) - class_name = attr_value; - else - class_name = "org.apache.flex.compiler.internal.tree.as." + attr_value; - template.nodeClass = class_name; - } - else if ( "provisional".equals(attr_name) ) - { - template.provisional = Boolean.valueOf(attr_value); - } - else - { - System.err.println("** Unknown attr name:" + attr_name); - } - } - - - // Top-level templates go into the map by node id; - // subpatterns get linked to their immediate parent. - if ( nodeStack.isEmpty() ) - { - assert template.problemClass != null : "Top-level template " + template + " must have a problem class."; - - if ( ! (destination.containsKey(template.id)) ) - destination.put(template.id, new ArrayList<Template>()); - - destination.get(template.id).add(template); - } - else - { - Template base = nodeStack.peek(); - if ( base.requiredSubtree == null ) - base.requiredSubtree = template; - else - System.err.println("already has subtree: " + base); - } - - this.nodeStack.push(template); - } - - /** - * Maintain the UnknownTreeFindingTemplate stack. - */ - @Override - public void endElement(String uri, String localName, String qName) - { - if ( localName.equals("Pattern") ) - this.nodeStack.pop(); - } - - /** - * Load an XML file containing patterns and dump equivalent Java code to System.out. - */ - public static void main(String[] argv) - throws Exception - { - if ( argv.length < 2 ) - { - System.err.println("Usage: java org.apache.flex.compiler.internal.as.codegen.UnknownTreePatternInputOutput <xml pattern file> <destination java file>"); - System.exit(1); - } - - new UnknownTreePatternInputOutput().dumpTemplateData(argv[0], argv[1]); - } - - PrintWriter output; - - /** - * Read an XML file of patterns and dump the equivalent Java code to the target file. - * @param src_file_name - the path of the XML file. - * @param dest_file_name - the path of the output Java file. - */ - void dumpTemplateData(String src_file_name, String dest_file_name) - throws Exception - { - if ( !load(src_file_name, new HashMap<String, ArrayList<Template>>()) ) - return; - - output = new PrintWriter(dest_file_name); - - output.println("package " + this.packageName + ";"); - output.println("import java.util.ArrayList;"); - output.println("import java.util.HashMap;"); - output.println("import java.util.Map;"); - output.println("import org.apache.flex.compiler.tree.ASTNodeID;"); - output.println("import static org.apache.flex.compiler.tree.ASTNodeID.*;"); - output.println("import " + this.emitterName + ";"); - output.println(); - output.println("public class " + this.className); - output.println("{"); - output.println(); - output.println(" // Patterns generated " + new java.util.Date().toString() + " from " + src_file_name.replaceAll("\\\\", "/")); - output.println(" public static Map<ASTNodeID, ArrayList<UnknownTreeFinding.Template> > allTemplates = new HashMap<ASTNodeID, ArrayList<UnknownTreeFinding.Template>>();"); - - output.println(" static"); - output.println(" {"); - - for ( String id: destination.keySet() ) - { - String templates_name = "templates_for_" + id; - output.printf(" ArrayList<UnknownTreeFinding.Template> %s = allTemplates.get(%s);%n", templates_name, id); - output.printf(" if ( %s == null ) {%n", templates_name); - output.printf(" %s = new ArrayList<UnknownTreeFinding.Template>();%n", templates_name); - output.printf(" allTemplates.put(%s, %s);%n", id, templates_name); - output.printf(" }%n"); - - for ( Template templ: destination.get(id) ) - { - output.printf(" {%n"); - dumpTemplate(templ, "current_template"); - output.printf(" %s.add(current_template);%n", templates_name); - output.printf(" }%n"); - } - } - output.println(" }"); - output.println("}"); - output.close(); - } - - /** - * Recursively dump a template. - * @param templ - the template to dump. - * @param var_name - the name by which this template will be known - * in the output Java code. As this routine recurses, it builds - * successively longer variable names. - */ - void dumpTemplate(Template templ, String var_name) - { - output.printf(" UnknownTreeFinding.Template %s = new UnknownTreeFinding.Template();%n", var_name); - output.printf(" %s.id = %s;%n", var_name, templ.id); - if ( templ.problemClass != null ) - output.printf(" %s.problemClass = %s.class;%n", var_name, templ.problemClass); - if ( templ.nodeClass != null ) - output.printf(" %s.nodeClass = %s.class;%n", var_name, templ.nodeClass); - if ( templ.mustHaveState != null ) - output.printf(" %s.mustHaveState = CmcEmitter.%s;%n", var_name, templ.mustHaveState); - if ( templ.cantHaveState != null ) - output.printf(" %s.cantHaveState = CmcEmitter.%s;%n", var_name, templ.cantHaveState); - output.printf(" %s.provisional = %s;%n", var_name, templ.provisional); - - if ( templ.requiredSubtree != null ) - { - String subtemp_name = var_name + "_subtempl"; - dumpTemplate(templ.requiredSubtree, subtemp_name); - output.printf(" %s.requiredSubtree = %s;%n", var_name, subtemp_name); - } - } - - /** - * Build-time representation of a UnknownTreeFinding.Template object. - */ - private static class Template - { - String id = "UnknownID"; - - String problemClass; - String nodeClass; - String mustHaveState; - String cantHaveState; - Boolean provisional = Boolean.FALSE; - - Template requiredSubtree; - } -} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/a656f9bb/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/unknowntreehandler/UnknownTreeHandlerGeneratorMojo.java ---------------------------------------------------------------------- diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/unknowntreehandler/UnknownTreeHandlerGeneratorMojo.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/unknowntreehandler/UnknownTreeHandlerGeneratorMojo.java new file mode 100644 index 0000000..b024e35 --- /dev/null +++ b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/unknowntreehandler/UnknownTreeHandlerGeneratorMojo.java @@ -0,0 +1,76 @@ +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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.flex.compiler.tools.unknowntreehandler; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; + +import java.io.File; + +/** + * Goal which touches a timestamp file. + */ +@Mojo(name="generate-unknown-tree-handler",defaultPhase = LifecyclePhase.GENERATE_SOURCES) +public class UnknownTreeHandlerGeneratorMojo + extends AbstractMojo +{ + @Parameter(defaultValue="${project.basedir}/src/main/unknowntreehandler",property="inputDir",required=true) + private File inputDir; + + @Parameter(property="inputFile",required=true) + private String inputFile; + + @Parameter(defaultValue="${project.build.directory}/generated-sources/unknowntreehandler",property="outputDir",required=true) + private File outputDirectory; + + @Parameter(property="outputFile",required=true) + private String outputFile; + + @Parameter(defaultValue="${project}") + private MavenProject project; + + public void execute() + throws MojoExecutionException + { + File input = new File(inputDir, inputFile); + if(!input.exists()) { + throw new MojoExecutionException("Could not read file: " + input.getAbsolutePath()); + } + + // Make sure the output directory exists. + File output = new File(outputDirectory, outputFile); + if(!output.getParentFile().exists()) { + if(!output.getParentFile().mkdirs()) { + throw new MojoExecutionException("Could not create output directory: " + + output.getParentFile().getAbsolutePath()); + } + } + + String[] args = {input.getAbsolutePath(), output.getAbsolutePath()}; + try { + UnknownTreePatternInputOutput.main(args); + } catch(Exception e) { + throw new MojoExecutionException("Caught error while executing UnknownTreePatternInputOutput.main", e); + } + + project.addCompileSourceRoot(outputDirectory.getPath()); + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/a656f9bb/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/unknowntreehandler/UnknownTreePatternInputOutput.java ---------------------------------------------------------------------- diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/unknowntreehandler/UnknownTreePatternInputOutput.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/unknowntreehandler/UnknownTreePatternInputOutput.java new file mode 100644 index 0000000..e3c7c35 --- /dev/null +++ b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/unknowntreehandler/UnknownTreePatternInputOutput.java @@ -0,0 +1,306 @@ +/* + * + * 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.flex.compiler.tools.unknowntreehandler; + +import java.io.PrintWriter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.Stack; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.xml.sax.Attributes; +import org.xml.sax.ext.DefaultHandler2; + +/** + * UnknownTreePatternInputOutput is a support class that reads + * an XML file with template data and populates a map of finding templates, + * and may also write this map out as Java code to be copied into + * the UnknownTreeHandler as hard-coded patterns. + */ +class UnknownTreePatternInputOutput extends DefaultHandler2 +{ + /** + * The map of templates by node ID to read into. + */ + Map<String, ArrayList<Template>> destination; + + /** + * Package name to use. Hard-coded for now. + */ + String packageName = "org.apache.flex.compiler.internal.as.codegen"; + + /** + * Class name to use. Also hard-coded. + */ + String className = "UnknownTreeHandlerPatterns"; + + /** + * Emitter to use. Hard-coded. + */ + String emitterName = "org.apache.flex.compiler.internal.as.codegen.CmcEmitter"; + + /** + * Load a map of templates from an XML file. + * @param pattern_file - the path of the XML pattern file. + * @param dest - the destination map. + */ + boolean load(String pattern_file, Map<String, ArrayList<Template>> dest) + { + this.destination = dest; + + try + { + SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setNamespaceAware(true); + + SAXParser parser = factory.newSAXParser(); + parser.parse( new java.io.FileInputStream(pattern_file), this); + return true; + } + catch ( Throwable load_failed ) + { + System.err.println("Load of " + pattern_file + " failed!"); + load_failed.printStackTrace(); + return false; + } + } + + /** + * This stack tracks UnknownTreeFindingTemplate objects from + * their startElement event to their endElement event; + * it's used to create the pattern/subpattern hierarchy. + */ + Stack<Template> nodeStack = new Stack<Template>(); + + /** + * Create new UnknownTreeFindingTemplate objects in response to Pattern + * elements, and decode the Pattern's attributes. + */ + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) + { + if ( ! (localName.equals("Pattern")) ) + { + if ( ! (localName.equals("SEW")) ) + System.err.println("Unknown element " + localName); + return; + } + + Template template = new Template(); + + for ( int index = 0; index < attributes.getLength(); index++) + { + String attr_name = attributes.getLocalName(index); + String attr_value = attributes.getValue(index); + + if ( "ID".equals(attr_name) ) + { + template.id = attr_value; + } + else if ( "cantHaveState".equals(attr_name) ) + { + String state_id = "__" + attr_value + "_NT"; + template.cantHaveState = state_id; + } + else if ( "mustHaveState".equals(attr_name) ) + { + String state_id = "__" + attr_value + "_NT"; + template.mustHaveState = state_id; + } + else if ( "problem".equals(attr_name) ) + { + String class_name; + if ( attr_value.startsWith("org.apache.") ) + class_name = attr_value; + else + class_name = "org.apache.flex.compiler.problems." + attr_value; + template.problemClass = class_name; + } + else if ( "nodeClass".equals(attr_name) ) + { + String class_name; + if ( attr_value.startsWith("org.apache.") ) + class_name = attr_value; + else + class_name = "org.apache.flex.compiler.internal.tree.as." + attr_value; + template.nodeClass = class_name; + } + else if ( "provisional".equals(attr_name) ) + { + template.provisional = Boolean.valueOf(attr_value); + } + else + { + System.err.println("** Unknown attr name:" + attr_name); + } + } + + + // Top-level templates go into the map by node id; + // subpatterns get linked to their immediate parent. + if ( nodeStack.isEmpty() ) + { + assert template.problemClass != null : "Top-level template " + template + " must have a problem class."; + + if ( ! (destination.containsKey(template.id)) ) + destination.put(template.id, new ArrayList<Template>()); + + destination.get(template.id).add(template); + } + else + { + Template base = nodeStack.peek(); + if ( base.requiredSubtree == null ) + base.requiredSubtree = template; + else + System.err.println("already has subtree: " + base); + } + + this.nodeStack.push(template); + } + + /** + * Maintain the UnknownTreeFindingTemplate stack. + */ + @Override + public void endElement(String uri, String localName, String qName) + { + if ( localName.equals("Pattern") ) + this.nodeStack.pop(); + } + + /** + * Load an XML file containing patterns and dump equivalent Java code to System.out. + */ + public static void main(String[] argv) + throws Exception + { + if ( argv.length < 2 ) + { + System.err.println("Usage: java org.apache.flex.compiler.tools.unknowntreehandler.UnknownTreePatternInputOutput <xml pattern file> <destination java file>"); + System.exit(1); + } + + new UnknownTreePatternInputOutput().dumpTemplateData(argv[0], argv[1]); + } + + PrintWriter output; + + /** + * Read an XML file of patterns and dump the equivalent Java code to the target file. + * @param src_file_name - the path of the XML file. + * @param dest_file_name - the path of the output Java file. + */ + void dumpTemplateData(String src_file_name, String dest_file_name) + throws Exception + { + if ( !load(src_file_name, new HashMap<String, ArrayList<Template>>()) ) + return; + + output = new PrintWriter(dest_file_name); + + output.println("package " + this.packageName + ";"); + output.println("import java.util.ArrayList;"); + output.println("import java.util.HashMap;"); + output.println("import java.util.Map;"); + output.println("import org.apache.flex.compiler.tree.ASTNodeID;"); + output.println("import static org.apache.flex.compiler.tree.ASTNodeID.*;"); + output.println("import " + this.emitterName + ";"); + output.println(); + output.println("public class " + this.className); + output.println("{"); + output.println(); + output.println(" // Patterns generated " + new java.util.Date().toString() + " from " + src_file_name.replaceAll("\\\\", "/")); + output.println(" public static Map<ASTNodeID, ArrayList<UnknownTreeFinding.Template> > allTemplates = new HashMap<ASTNodeID, ArrayList<UnknownTreeFinding.Template>>();"); + + output.println(" static"); + output.println(" {"); + + for ( String id: destination.keySet() ) + { + String templates_name = "templates_for_" + id; + output.printf(" ArrayList<UnknownTreeFinding.Template> %s = allTemplates.get(%s);%n", templates_name, id); + output.printf(" if ( %s == null ) {%n", templates_name); + output.printf(" %s = new ArrayList<UnknownTreeFinding.Template>();%n", templates_name); + output.printf(" allTemplates.put(%s, %s);%n", id, templates_name); + output.printf(" }%n"); + + for ( Template templ: destination.get(id) ) + { + output.printf(" {%n"); + dumpTemplate(templ, "current_template"); + output.printf(" %s.add(current_template);%n", templates_name); + output.printf(" }%n"); + } + } + output.println(" }"); + output.println("}"); + output.close(); + } + + /** + * Recursively dump a template. + * @param templ - the template to dump. + * @param var_name - the name by which this template will be known + * in the output Java code. As this routine recurses, it builds + * successively longer variable names. + */ + void dumpTemplate(Template templ, String var_name) + { + output.printf(" UnknownTreeFinding.Template %s = new UnknownTreeFinding.Template();%n", var_name); + output.printf(" %s.id = %s;%n", var_name, templ.id); + if ( templ.problemClass != null ) + output.printf(" %s.problemClass = %s.class;%n", var_name, templ.problemClass); + if ( templ.nodeClass != null ) + output.printf(" %s.nodeClass = %s.class;%n", var_name, templ.nodeClass); + if ( templ.mustHaveState != null ) + output.printf(" %s.mustHaveState = CmcEmitter.%s;%n", var_name, templ.mustHaveState); + if ( templ.cantHaveState != null ) + output.printf(" %s.cantHaveState = CmcEmitter.%s;%n", var_name, templ.cantHaveState); + output.printf(" %s.provisional = %s;%n", var_name, templ.provisional); + + if ( templ.requiredSubtree != null ) + { + String subtemp_name = var_name + "_subtempl"; + dumpTemplate(templ.requiredSubtree, subtemp_name); + output.printf(" %s.requiredSubtree = %s;%n", var_name, subtemp_name); + } + } + + /** + * Build-time representation of a UnknownTreeFinding.Template object. + */ + private static class Template + { + String id = "UnknownID"; + + String problemClass; + String nodeClass; + String mustHaveState; + String cantHaveState; + Boolean provisional = Boolean.FALSE; + + Template requiredSubtree; + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/a656f9bb/compiler/build.xml ---------------------------------------------------------------------- diff --git a/compiler/build.xml b/compiler/build.xml index 1b86190..c39f02e 100644 --- a/compiler/build.xml +++ b/compiler/build.xml @@ -361,7 +361,7 @@ <target name="unknown.tree.handler.patterns" depends="set.unknown.tree.handler.patterns.uptodate" unless="unknown.tree.handler.patterns.uptodate"> <mkdir dir="${compiler}/target/generated-sources/unknowntreehandler/org/apache/flex/compiler/internal/as/codegen"/> - <java classname="org.apache.flex.compiler.internal.as.codegen.UnknownTreePatternInputOutput" fork="true" failonerror="true"> + <java classname="org.apache.flex.compiler.tools.unknowntreehandler.UnknownTreePatternInputOutput" fork="true" failonerror="true"> <arg value="${compiler}/src/main/unknowntreehandler/org/apache/flex/compiler/internal/as/codegen/UnknownTreeHandlerPatterns.xml"/> <arg value="${compiler}/target/generated-sources/unknowntreehandler/org/apache/flex/compiler/internal/as/codegen/UnknownTreeHandlerPatterns.java"/> <classpath>
