]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/AssemblerDef.java
Changed spelling to manifest
[mirror_edk2.git] / Tools / Source / Cpptasks / net / sf / antcontrib / cpptasks / AssemblerDef.java
1 /*
2 *
3 * Copyright 2001-2005 The Ant-Contrib project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package net.sf.antcontrib.cpptasks;
18
19 import java.io.BufferedReader;
20 import java.io.File;
21 import java.io.FileReader;
22 import java.util.Vector;
23
24 import net.sf.antcontrib.cpptasks.compiler.Assembler;
25 import net.sf.antcontrib.cpptasks.compiler.Processor;
26 import net.sf.antcontrib.cpptasks.gcc.GccAssembler;
27 import net.sf.antcontrib.cpptasks.types.AssemblerArgument;
28 import net.sf.antcontrib.cpptasks.types.ConditionalPath;
29 import net.sf.antcontrib.cpptasks.types.IncludePath;
30 import net.sf.antcontrib.cpptasks.types.SystemIncludePath;
31
32 import org.apache.tools.ant.BuildException;
33 import org.apache.tools.ant.Project;
34
35 /**
36 * A assembler definition. Assembler elements may be placed either as children
37 * of a cc element or the project element. A assembler element with an id
38 * attribute may be referenced from assembler elements with refid or extends
39 * attributes.
40 *
41 */
42 public final class AssemblerDef extends ProcessorDef {
43
44 private final Vector includePaths = new Vector();
45
46 private final Vector sysIncludePaths = new Vector();
47
48 private Boolean defaultflag = new Boolean(true);
49
50 public AssemblerDef () {
51 }
52
53 /**
54 * Adds a assembler command-line arg.
55 */
56 public void addConfiguredAssemblerArg(AssemblerArgument arg) {
57 if (isReference()) {
58 throw noChildrenAllowed();
59 }
60 addConfiguredProcessorArg(arg);
61 }
62
63 /**
64 * Creates an include path.
65 */
66 public IncludePath createIncludePath() {
67 Project p = getProject();
68 if (p == null) {
69 throw new java.lang.IllegalStateException("project must be set");
70 }
71 if (isReference()) {
72 throw noChildrenAllowed();
73 }
74 IncludePath path = new IncludePath(p);
75 includePaths.addElement(path);
76 return path;
77 }
78
79 /**
80 * Creates an include path.
81 */
82 public SystemIncludePath createSysIncludePath() {
83 Project p = getProject();
84 if (p == null) {
85 throw new java.lang.IllegalStateException("project must be set");
86 }
87 if (isReference()) {
88 throw noChildrenAllowed();
89 }
90 SystemIncludePath path = new SystemIncludePath(p);
91 sysIncludePaths.addElement(path);
92 return path;
93 }
94
95 /**
96 * Add a <includepath>or <sysincludepath> if specify the file attribute
97 *
98 * @throws BuildException
99 * if the specify file not exist
100 */
101 protected void loadFile(Vector activePath, File file) throws BuildException {
102 FileReader fileReader;
103 BufferedReader in;
104 String str;
105 if (!file.exists()) {
106 throw new BuildException("The file " + file + " is not existed");
107 }
108 try {
109 fileReader = new FileReader(file);
110 in = new BufferedReader(fileReader);
111 while ((str = in.readLine()) != null) {
112 if (str.trim() == "") {
113 continue;
114 }
115 str = getProject().replaceProperties(str);
116 activePath.addElement(str.trim());
117 }
118 } catch (Exception e) {
119 throw new BuildException(e.getMessage());
120 }
121 }
122
123 public void execute() throws org.apache.tools.ant.BuildException {
124 throw new org.apache.tools.ant.BuildException(
125 "Not an actual task, but looks like one for documentation purposes");
126 }
127
128 /**
129 * Returns the assembler-specific include path.
130 */
131 public String[] getActiveIncludePaths() {
132 if (isReference()) {
133 return ((AssemblerDef) getCheckedRef(AssemblerDef.class,
134 "AssemblerDef")).getActiveIncludePaths();
135 }
136 return getActivePaths(includePaths);
137 }
138
139 /**
140 * Returns the assembler-specific sysinclude path.
141 */
142 public String[] getActiveSysIncludePaths() {
143 if (isReference()) {
144 return ((AssemblerDef) getCheckedRef(AssemblerDef.class,
145 "AssemblerDef")).getActiveSysIncludePaths();
146 }
147 return getActivePaths(sysIncludePaths);
148 }
149
150 private String[] getActivePaths(Vector paths) {
151 Project p = getProject();
152 if (p == null) {
153 throw new java.lang.IllegalStateException("project not set");
154 }
155 Vector activePaths = new Vector(paths.size());
156 for (int i = 0; i < paths.size(); i++) {
157 ConditionalPath path = (ConditionalPath) paths.elementAt(i);
158 if (path.isActive(p)) {
159 if (path.getFile() == null) {
160 String[] pathEntries = path.list();
161 for (int j = 0; j < pathEntries.length; j++) {
162 activePaths.addElement(pathEntries[j]);
163 }
164 } else {
165 loadFile(activePaths, path.getFile());
166 }
167 }
168 }
169 String[] pathNames = new String[activePaths.size()];
170 activePaths.copyInto(pathNames);
171 return pathNames;
172 }
173
174 public final Boolean getDefaultflag(AssemblerDef[] defaultProviders,
175 int index) {
176 if (isReference()) {
177 return ((AssemblerDef) getCheckedRef(AssemblerDef.class,
178 "AssemblerDef")).getDefaultflag(defaultProviders,
179 index);
180 }
181 return defaultflag;
182 }
183
184 public Processor getProcessor() {
185 Processor processor = super.getProcessor();
186 if (processor == null) {
187 processor = GccAssembler.getInstance();
188 }
189 return processor;
190 }
191
192 /**
193 * Sets r type.
194 *
195 * <table width="100%" border="1"> <thead>Supported assemblers</thead>
196 * <tr>
197 * <td>gcc (default)</td>
198 * <td>GAS assembler</td>
199 * </tr>
200 * <tr>
201 * <td>masm</td>
202 * <td>MASM assembler</td>
203 * </tr>
204 * </table>
205 *
206 */
207 public void setName(AssemblerEnum name) throws BuildException {
208 if (isReference()) {
209 throw tooManyAttributes();
210 }
211 Assembler assembler = name.getAssembler();
212 setProcessor(assembler);
213 }
214
215 protected void setProcessor(Processor proc) throws BuildException {
216 try {
217 super.setProcessor((Assembler) proc);
218 } catch (ClassCastException ex) {
219 throw new BuildException(ex);
220 }
221 }
222
223 /**
224 * Enables or disables default flags.
225 *
226 * @param defaultflag
227 * if true, default flags will add to command line.
228 *
229 */
230 public void setDefaultflag(boolean defaultflag) {
231 if (isReference()) {
232 throw tooManyAttributes();
233 }
234 this.defaultflag = booleanValueOf(defaultflag);
235 }
236
237 }