+++ /dev/null
-/*\r
- * \r
- * Copyright 2001-2005 The Ant-Contrib project\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package net.sf.antcontrib.cpptasks;\r
-\r
-import java.io.BufferedReader;\r
-import java.io.File;\r
-import java.io.FileReader;\r
-import java.util.Vector;\r
-\r
-import net.sf.antcontrib.cpptasks.compiler.Assembler;\r
-import net.sf.antcontrib.cpptasks.compiler.Processor;\r
-import net.sf.antcontrib.cpptasks.gcc.GccAssembler;\r
-import net.sf.antcontrib.cpptasks.types.AssemblerArgument;\r
-import net.sf.antcontrib.cpptasks.types.ConditionalPath;\r
-import net.sf.antcontrib.cpptasks.types.IncludePath;\r
-import net.sf.antcontrib.cpptasks.types.SystemIncludePath;\r
-\r
-import org.apache.tools.ant.BuildException;\r
-import org.apache.tools.ant.Project;\r
-\r
-/**\r
- * A assembler definition. Assembler elements may be placed either as children\r
- * of a cc element or the project element. A assembler element with an id\r
- * attribute may be referenced from assembler elements with refid or extends\r
- * attributes.\r
- * \r
- */\r
-public final class AssemblerDef extends ProcessorDef {\r
-\r
- private final Vector includePaths = new Vector();\r
-\r
- private final Vector sysIncludePaths = new Vector();\r
-\r
- private Boolean defaultflag = new Boolean(true);\r
-\r
- public AssemblerDef () {\r
- }\r
-\r
- /**\r
- * Adds a assembler command-line arg.\r
- */\r
- public void addConfiguredAssemblerArg(AssemblerArgument arg) {\r
- if (isReference()) {\r
- throw noChildrenAllowed();\r
- }\r
- addConfiguredProcessorArg(arg);\r
- }\r
-\r
- /**\r
- * Creates an include path.\r
- */\r
- public IncludePath createIncludePath() {\r
- Project p = getProject();\r
- if (p == null) {\r
- throw new java.lang.IllegalStateException("project must be set");\r
- }\r
- if (isReference()) {\r
- throw noChildrenAllowed();\r
- }\r
- IncludePath path = new IncludePath(p);\r
- includePaths.addElement(path);\r
- return path;\r
- }\r
-\r
- /**\r
- * Creates an include path.\r
- */\r
- public SystemIncludePath createSysIncludePath() {\r
- Project p = getProject();\r
- if (p == null) {\r
- throw new java.lang.IllegalStateException("project must be set");\r
- }\r
- if (isReference()) {\r
- throw noChildrenAllowed();\r
- }\r
- SystemIncludePath path = new SystemIncludePath(p);\r
- sysIncludePaths.addElement(path);\r
- return path;\r
- }\r
-\r
- /**\r
- * Add a <includepath>or <sysincludepath> if specify the file attribute\r
- * \r
- * @throws BuildException\r
- * if the specify file not exist\r
- */\r
- protected void loadFile(Vector activePath, File file) throws BuildException {\r
- FileReader fileReader;\r
- BufferedReader in;\r
- String str;\r
- if (!file.exists()) {\r
- throw new BuildException("The file " + file + " is not existed");\r
- }\r
- try {\r
- fileReader = new FileReader(file);\r
- in = new BufferedReader(fileReader);\r
- while ((str = in.readLine()) != null) {\r
- if (str.trim() == "") {\r
- continue;\r
- }\r
- str = getProject().replaceProperties(str);\r
- activePath.addElement(str.trim());\r
- }\r
- } catch (Exception e) {\r
- throw new BuildException(e.getMessage());\r
- }\r
- }\r
-\r
- public void execute() throws org.apache.tools.ant.BuildException {\r
- throw new org.apache.tools.ant.BuildException(\r
- "Not an actual task, but looks like one for documentation purposes");\r
- }\r
-\r
- /**\r
- * Returns the assembler-specific include path.\r
- */\r
- public String[] getActiveIncludePaths() {\r
- if (isReference()) {\r
- return ((AssemblerDef) getCheckedRef(AssemblerDef.class,\r
- "AssemblerDef")).getActiveIncludePaths();\r
- }\r
- return getActivePaths(includePaths);\r
- }\r
-\r
- /**\r
- * Returns the assembler-specific sysinclude path.\r
- */\r
- public String[] getActiveSysIncludePaths() {\r
- if (isReference()) {\r
- return ((AssemblerDef) getCheckedRef(AssemblerDef.class,\r
- "AssemblerDef")).getActiveSysIncludePaths();\r
- }\r
- return getActivePaths(sysIncludePaths);\r
- }\r
-\r
- private String[] getActivePaths(Vector paths) {\r
- Project p = getProject();\r
- if (p == null) {\r
- throw new java.lang.IllegalStateException("project not set");\r
- }\r
- Vector activePaths = new Vector(paths.size());\r
- for (int i = 0; i < paths.size(); i++) {\r
- ConditionalPath path = (ConditionalPath) paths.elementAt(i);\r
- if (path.isActive(p)) {\r
- if (path.getFile() == null) {\r
- String[] pathEntries = path.list();\r
- for (int j = 0; j < pathEntries.length; j++) {\r
- activePaths.addElement(pathEntries[j]);\r
- }\r
- } else {\r
- loadFile(activePaths, path.getFile());\r
- }\r
- }\r
- }\r
- String[] pathNames = new String[activePaths.size()];\r
- activePaths.copyInto(pathNames);\r
- return pathNames;\r
- }\r
-\r
- public final Boolean getDefaultflag(AssemblerDef[] defaultProviders,\r
- int index) {\r
- if (isReference()) {\r
- return ((AssemblerDef) getCheckedRef(AssemblerDef.class,\r
- "AssemblerDef")).getDefaultflag(defaultProviders,\r
- index);\r
- }\r
- return defaultflag;\r
- }\r
-\r
- public Processor getProcessor() {\r
- Processor processor = super.getProcessor();\r
- if (processor == null) {\r
- processor = GccAssembler.getInstance();\r
- }\r
- return processor;\r
- }\r
-\r
- /**\r
- * Sets r type.\r
- * \r
- * <table width="100%" border="1"> <thead>Supported assemblers</thead>\r
- * <tr>\r
- * <td>gcc (default)</td>\r
- * <td>GAS assembler</td>\r
- * </tr>\r
- * <tr>\r
- * <td>masm</td>\r
- * <td>MASM assembler</td>\r
- * </tr>\r
- * </table>\r
- * \r
- */\r
- public void setName(AssemblerEnum name) throws BuildException {\r
- if (isReference()) {\r
- throw tooManyAttributes();\r
- }\r
- Assembler assembler = name.getAssembler();\r
- setProcessor(assembler);\r
- }\r
-\r
- protected void setProcessor(Processor proc) throws BuildException {\r
- try {\r
- super.setProcessor((Assembler) proc);\r
- } catch (ClassCastException ex) {\r
- throw new BuildException(ex);\r
- }\r
- }\r
-\r
- /**\r
- * Enables or disables default flags.\r
- * \r
- * @param defaultflag\r
- * if true, default flags will add to command line.\r
- * \r
- */\r
- public void setDefaultflag(boolean defaultflag) {\r
- if (isReference()) {\r
- throw tooManyAttributes();\r
- }\r
- this.defaultflag = booleanValueOf(defaultflag);\r
- }\r
-\r
-}\r