src/share/classes/com/sun/tools/corba/se/idl/Arguments.java

Thu, 31 Aug 2017 18:10:36 +0800

author
aoqi
date
Thu, 31 Aug 2017 18:10:36 +0800
changeset 748
6845b95cba6b
parent 158
91006f157c46
parent 0
7ef37b2cdcad
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25 /*
aoqi@0 26 * COMPONENT_NAME: idl.parser
aoqi@0 27 *
aoqi@0 28 * ORIGINS: 27
aoqi@0 29 *
aoqi@0 30 * Licensed Materials - Property of IBM
aoqi@0 31 * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999
aoqi@0 32 * RMI-IIOP v1.0
aoqi@0 33 *
aoqi@0 34 */
aoqi@0 35
aoqi@0 36 package com.sun.tools.corba.se.idl;
aoqi@0 37
aoqi@0 38 // NOTES:
aoqi@0 39 // -F46082.51<daz> Remove -stateful option. "Stateful interfaces" obsolete.
aoqi@0 40 // -D58319<daz> Add -version option. Note that this may occur as the last
aoqi@0 41 // argument on the command-line.
aoqi@0 42 // -F60858.1<daz> Add -corba [level] option. Accept IDL upto this level, and
aoqi@0 43 // behave in a "proprietary manner" otherwise.
aoqi@0 44 // -D62023<daz> Add -noWarn option to supress warnings.
aoqi@0 45
aoqi@0 46 import java.io.DataInputStream;
aoqi@0 47 import java.io.IOException;
aoqi@0 48 import java.util.Hashtable;
aoqi@0 49 import java.util.Properties;
aoqi@0 50 import java.util.Vector;
aoqi@0 51 import java.util.StringTokenizer;
aoqi@0 52 import java.lang.reflect.Modifier;
aoqi@0 53 import java.lang.reflect.Field;
aoqi@0 54
aoqi@0 55 import com.sun.tools.corba.se.idl.som.cff.FileLocator;
aoqi@0 56
aoqi@0 57 /**
aoqi@0 58 * This class is responsible for parsing the command line arguments to the
aoqi@0 59 * compiler. To add new arguments to the compiler, this class must be extended
aoqi@0 60 * and the parseOtherArgs method overridden.
aoqi@0 61 **/
aoqi@0 62 public class Arguments
aoqi@0 63 {
aoqi@0 64 /**
aoqi@0 65 * Method parseOtherArgs() is called when the framework detects arguments
aoqi@0 66 * which are unknown to it. The default implementation of this method simply
aoqi@0 67 * throws an InvalidArgument exception. Any overriding implementation
aoqi@0 68 * must check the arguments passed to it for validity and process the
aoqi@0 69 * arguments appropriately. If it detects an invalid argument, it should
aoqi@0 70 * throw an InvalidArgument exception. Arguments MUST be of the form
aoqi@0 71 * `/<arg> [<qualifiers>]' or `-<arg> [<qualifiers>]' where <qualifiers>
aoqi@0 72 * is optional (for example, -iC:\includes, `C:\includes' is the qualifier
aoqi@0 73 * for the argument `i').
aoqi@0 74 * @param args The arguments which are unknown by the framework.
aoqi@0 75 * @param properties Environment-style properties collected from the
aoqi@0 76 * file idl.config.
aoqi@0 77 * @exception idl.InvalidArgument if the argument is unknown.
aoqi@0 78 **/
aoqi@0 79 protected void parseOtherArgs (String[] args, Properties properties) throws InvalidArgument
aoqi@0 80 {
aoqi@0 81 if (args.length > 0)
aoqi@0 82 throw new InvalidArgument (args[0]);
aoqi@0 83 } // parseOtherArgs
aoqi@0 84
aoqi@0 85
aoqi@0 86 protected void setDebugFlags( String args )
aoqi@0 87 {
aoqi@0 88 StringTokenizer st = new StringTokenizer( args, "," ) ;
aoqi@0 89 while (st.hasMoreTokens()) {
aoqi@0 90 String token = st.nextToken() ;
aoqi@0 91
aoqi@0 92 // If there is a public boolean data member in this class
aoqi@0 93 // named token + "DebugFlag", set it to true.
aoqi@0 94 try {
aoqi@0 95 Field fld = this.getClass().getField( token + "DebugFlag" ) ;
aoqi@0 96 int mod = fld.getModifiers() ;
aoqi@0 97 if (Modifier.isPublic( mod ) && !Modifier.isStatic( mod ))
aoqi@0 98 if (fld.getType() == boolean.class)
aoqi@0 99 fld.setBoolean( this, true ) ;
aoqi@0 100 } catch (Exception exc) {
aoqi@0 101 // ignore it
aoqi@0 102 }
aoqi@0 103 }
aoqi@0 104 }
aoqi@0 105
aoqi@0 106 /**
aoqi@0 107 * Collect the command-line parameters.
aoqi@0 108 **/
aoqi@0 109 void parseArgs (String[] args) throws InvalidArgument {
aoqi@0 110 Vector unknownArgs = new Vector ();
aoqi@0 111 int i = 0;
aoqi@0 112
aoqi@0 113 try {
aoqi@0 114 // Process command line parameters
aoqi@0 115 for (i = 0; i < args.length - 1; ++i) {
aoqi@0 116 String lcArg = args[i].toLowerCase ();
aoqi@0 117 if (lcArg.charAt (0) != '-' && lcArg.charAt (0) != '/')
aoqi@0 118 throw new InvalidArgument (args[i]);
aoqi@0 119 if (lcArg.charAt (0) == '-' ) {
aoqi@0 120 lcArg = lcArg.substring (1);
aoqi@0 121 }
aoqi@0 122
aoqi@0 123 // Include path
aoqi@0 124 if (lcArg.equals ("i")) {
aoqi@0 125 includePaths.addElement (args[++i]);
aoqi@0 126 } else if (lcArg.startsWith ("i")) {
aoqi@0 127 includePaths.addElement (args[i].substring (2));
aoqi@0 128 } else if (lcArg.equals ("v") || lcArg.equals ("verbose")) {
aoqi@0 129 // Verbose mode
aoqi@0 130 verbose = true;
aoqi@0 131 } else if (lcArg.equals ("d")) {
aoqi@0 132 // Define symbol
aoqi@0 133 definedSymbols.put (args[++i], "");
aoqi@0 134 } else if (lcArg.equals( "debug" )) {
aoqi@0 135 // Turn on debug flags
aoqi@0 136 setDebugFlags( args[++i] ) ;
aoqi@0 137 } else if (lcArg.startsWith ("d")) {
aoqi@0 138 definedSymbols.put (args[i].substring (2), "");
aoqi@0 139 } else if (lcArg.equals ("emitall")) {
aoqi@0 140 // Emit bindings for included sources
aoqi@0 141 emitAll = true;
aoqi@0 142 } else if (lcArg.equals ("keep")) {
aoqi@0 143 // Keep old files
aoqi@0 144 keepOldFiles = true;
aoqi@0 145 } else if (lcArg.equals ("nowarn")) {
aoqi@0 146 // <d62023> Suppress warnings
aoqi@0 147 noWarn = true;
aoqi@0 148 } else if (lcArg.equals ("trace")) {
aoqi@0 149 // Allow tracing.
aoqi@0 150 Runtime.getRuntime ().traceMethodCalls (true);
aoqi@0 151 }
aoqi@0 152 // <f46082.51> Remove -stateful feature.
aoqi@0 153 //else if (lcArg.equals ("stateful"))
aoqi@0 154 //{
aoqi@0 155 // Emit stateful bindings.
aoqi@0 156 // parseStateful = true;
aoqi@0 157 //}
aoqi@0 158 // CPPModule
aoqi@0 159 else if ( lcArg.equals ("cppmodule")) {
aoqi@0 160 cppModule = true;
aoqi@0 161 } else if (lcArg.equals ("version")) {
aoqi@0 162 // Version
aoqi@0 163 versionRequest = true;
aoqi@0 164 } else if (lcArg.equals ("corba")) {
aoqi@0 165 // CORBA level
aoqi@0 166 if (i + 1 >= args.length)
aoqi@0 167 throw new InvalidArgument (args[i]);
aoqi@0 168 String level = args[++i];
aoqi@0 169 if (level.charAt (0) == '-')
aoqi@0 170 throw new InvalidArgument (args[i - 1]);
aoqi@0 171 try {
aoqi@0 172 corbaLevel = new Float (level).floatValue ();
aoqi@0 173 } catch (NumberFormatException e) {
aoqi@0 174 throw new InvalidArgument (args[i]);
aoqi@0 175 }
aoqi@0 176 } else {
aoqi@0 177 unknownArgs.addElement (args[i]);
aoqi@0 178 ++i;
aoqi@0 179 while (i < (args.length - 1) &&
aoqi@0 180 args[i].charAt (0) != '-' &&
aoqi@0 181 args[i].charAt (0) != '/') {
aoqi@0 182 unknownArgs.addElement (args[i++]);
aoqi@0 183 }
aoqi@0 184 --i;
aoqi@0 185 }
aoqi@0 186 }
aoqi@0 187 } catch (ArrayIndexOutOfBoundsException e) {
aoqi@0 188 // If there is any array indexing problem, it is probably
aoqi@0 189 // because the qualifier on the last argument is missing.
aoqi@0 190 // Report that this last argument is invalid.
aoqi@0 191 throw new InvalidArgument (args[args.length - 1]);
aoqi@0 192 }
aoqi@0 193
aoqi@0 194 // <d57319>
aoqi@0 195 // The last argument is the file argument or "-version", which may
aoqi@0 196 // be specified without a file argument.
aoqi@0 197 if (i == args.length - 1) {
aoqi@0 198 if (args[i].toLowerCase ().equals ("-version"))
aoqi@0 199 versionRequest = true;
aoqi@0 200 else
aoqi@0 201 file = args[i];
aoqi@0 202 } else
aoqi@0 203 throw new InvalidArgument ();
aoqi@0 204
aoqi@0 205 // Get and process the idl.config file.
aoqi@0 206 Properties props = new Properties ();
aoqi@0 207 try {
aoqi@0 208 DataInputStream stream = FileLocator.locateFileInClassPath ("idl.config");
aoqi@0 209 props.load (stream);
aoqi@0 210 addIncludePaths (props);
aoqi@0 211 } catch (IOException e) {
aoqi@0 212 }
aoqi@0 213
aoqi@0 214 // Call parseOtherArgs. By default, if there are unknown args,
aoqi@0 215 // InvalidArgument is called. A call to parseOtherArgs is useful
aoqi@0 216 // only when this framework has been extended.
aoqi@0 217 String[] otherArgs;
aoqi@0 218 if (unknownArgs.size () > 0) {
aoqi@0 219 otherArgs = new String[unknownArgs.size ()];
aoqi@0 220 unknownArgs.copyInto (otherArgs);
aoqi@0 221 } else
aoqi@0 222 otherArgs = new String[0];
aoqi@0 223
aoqi@0 224 parseOtherArgs (otherArgs, props);
aoqi@0 225 } // parseArgs
aoqi@0 226
aoqi@0 227 /**
aoqi@0 228 *
aoqi@0 229 **/
aoqi@0 230 private void addIncludePaths (Properties props)
aoqi@0 231 {
aoqi@0 232 String paths = props.getProperty ("includes");
aoqi@0 233 if (paths != null)
aoqi@0 234 {
aoqi@0 235 String separator = System.getProperty ("path.separator");
aoqi@0 236 int end = -separator.length (); // so the first pass paths == original paths
aoqi@0 237 do
aoqi@0 238 {
aoqi@0 239 paths = paths.substring (end + separator.length ());
aoqi@0 240 end = paths.indexOf (separator);
aoqi@0 241 if (end < 0)
aoqi@0 242 end = paths.length ();
aoqi@0 243 includePaths.addElement (paths.substring (0, end));
aoqi@0 244 }
aoqi@0 245 while (end != paths.length ());
aoqi@0 246 }
aoqi@0 247 } // addIncludePaths
aoqi@0 248
aoqi@0 249 /**
aoqi@0 250 * The name of the IDL file.
aoqi@0 251 **/
aoqi@0 252 public String file = null;
aoqi@0 253
aoqi@0 254 /**
aoqi@0 255 * True if the user wishes to see processing remarks.
aoqi@0 256 **/
aoqi@0 257 public boolean verbose = false;
aoqi@0 258
aoqi@0 259 /**
aoqi@0 260 * If this is true, then existing files should not be overwritten
aoqi@0 261 * by the compiler.
aoqi@0 262 **/
aoqi@0 263 public boolean keepOldFiles = false;
aoqi@0 264
aoqi@0 265 /**
aoqi@0 266 * If this is true, then the types in all included files are also emitted.
aoqi@0 267 **/
aoqi@0 268 public boolean emitAll = false;
aoqi@0 269
aoqi@0 270 // <f46082.51> Remove -stateful feature.
aoqi@0 271 ///**
aoqi@0 272 // * If this is true, then stateful interfaces (for the Objects-by-Value
aoqi@0 273 // * proposal) are allowed. This is not yet a standard, so it must
aoqi@0 274 // * explicitly be called for by setting the -stateful argument to the
aoqi@0 275 // * compiler. If -stateful does not appear on the command line, then
aoqi@0 276 // * the IDL will be parsed according to the standards.
aoqi@0 277 // **/
aoqi@0 278 //public boolean parseStateful = false;
aoqi@0 279 /**
aoqi@0 280 * A list of strings, each of which is a path from which included files
aoqi@0 281 * are found.
aoqi@0 282 **/
aoqi@0 283 public Vector includePaths = new Vector ();
aoqi@0 284
aoqi@0 285 /**
aoqi@0 286 * A table of defined symbols. The key is the symbol name; the value
aoqi@0 287 * (if any) is the replacement value for the symbol.
aoqi@0 288 **/
aoqi@0 289 public Hashtable definedSymbols = new Hashtable ();
aoqi@0 290
aoqi@0 291 /**
aoqi@0 292 * <f46082.46.01> True if new module entries are created for each
aoqi@0 293 * re-opened module.
aoqi@0 294 **/
aoqi@0 295 public boolean cppModule = false;
aoqi@0 296
aoqi@0 297 /**
aoqi@0 298 * -version option.
aoqi@0 299 **/
aoqi@0 300 public boolean versionRequest = false; // <D58319>
aoqi@0 301
aoqi@0 302 // <f60858.1> Specify the maximal level of the CORBA spec. the parser
aoqi@0 303 // will support.
aoqi@0 304 //
aoqi@0 305 // NOTE: For BOSS 3.0, specify at 2.2. Raise to greater value in future
aoqi@0 306 // releases.
aoqi@0 307 /**
aoqi@0 308 * -corba [level] option, where [level] is a floating-point number indicating
aoqi@0 309 * the maximal level of CORBA IDL the parser framework can accept.
aoqi@0 310 **/
aoqi@0 311 public float corbaLevel = 2.2f;
aoqi@0 312 // <d62023>
aoqi@0 313 /**
aoqi@0 314 * -noWarn option. Suppress warnings when true.
aoqi@0 315 **/
aoqi@0 316 public boolean noWarn = false; // Issue warnings by default.
aoqi@0 317
aoqi@0 318 // Currently defined debug flags. Any additions must be called xxxDebugFlag.
aoqi@0 319 // All debug flags must be public boolean types.
aoqi@0 320 // These are set by passing the flag -ORBDebug x,y,z in the ORB init args.
aoqi@0 321 // Note that x,y,z must not contain spaces.
aoqi@0 322 public boolean scannerDebugFlag = false ;
aoqi@0 323 public boolean tokenDebugFlag = false ;
aoqi@0 324
aoqi@0 325 } // class Arguments

mercurial