You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by di...@apache.org on 2008/11/16 23:35:38 UTC

svn commit: r718128 [3/6] - in /incubator/etch/branches/etch-python: ./ binding-csharp/compiler/src/main/java/etch/bindings/csharp/compiler/ binding-csharp/compiler/src/main/resources/etch/bindings/csharp/compiler/ binding-csharp/runtime/ binding-cshar...

Modified: incubator/etch/branches/etch-python/binding-java/runtime/src/main/java/etch/bindings/java/transport/fmt/binary/BinaryTaggedDataInput.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/binding-java/runtime/src/main/java/etch/bindings/java/transport/fmt/binary/BinaryTaggedDataInput.java?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/binding-java/runtime/src/main/java/etch/bindings/java/transport/fmt/binary/BinaryTaggedDataInput.java (original)
+++ incubator/etch/branches/etch-python/binding-java/runtime/src/main/java/etch/bindings/java/transport/fmt/binary/BinaryTaggedDataInput.java Sun Nov 16 14:35:35 2008
@@ -19,6 +19,7 @@
 
 import java.io.IOException;
 
+import etch.bindings.java.msg.ComboValidator;
 import etch.bindings.java.msg.Field;
 import etch.bindings.java.msg.Message;
 import etch.bindings.java.msg.StructValue;
@@ -27,9 +28,11 @@
 import etch.bindings.java.msg.ValueFactory;
 import etch.bindings.java.support.Validator_int;
 import etch.bindings.java.support.Validator_object;
+import etch.bindings.java.support.Validator_string;
 import etch.bindings.java.transport.ArrayValue;
 import etch.bindings.java.transport.TaggedDataInput;
 import etch.bindings.java.transport.fmt.TypeCode;
+import etch.util.Assertion;
 import etch.util.FlexBuffer;
 
 /**
@@ -110,27 +113,21 @@
 		Type t = sv.type();
 		while (true)
 		{
-			Object obj = readValue( intValidator, true );
-			if (obj == NONE)
-				break;
-			
-			Integer id = (Integer) obj;
-			Field key = t.getField( id );
-			
+			Field key = readField( t );
 			if (key == null)
-			{
-				key = new Field( id, id.toString() );
-			}
+				break;
 			
 			Validator v = t.getValidator( key );
-			if (v == null)
+			if (v != null)
 			{
-				// read the value but ignore it.
-				readValue( Validator_object.get( 0 ) );
+				sv.put( key, readValue( v ) );
 			}
 			else
 			{
-				sv.put( key, readValue( v ) );
+				// read the value but ignore it.
+				Object obj = readValue( Validator_object.get( 0 ) );
+				if (false)
+					sv.put( key, obj );
 			}
 		}
 	}
@@ -216,12 +213,59 @@
 	
 	private Type readType() throws IOException
 	{
-		Integer id = readIntegerValue();
-		Type t = vf.getType( id );
-		if (t == null)
-			t = new Type( id, id.toString() );
-		return t;
+		Object obj = readValue( intOrStrValidator, false );
+		
+		if (obj instanceof Integer)
+		{
+			Integer id = (Integer) obj;
+			Type type = vf.getType( id );
+			
+			if (type == null)
+				type = new Type( id, id.toString() );
+			
+			return type;
+		}
+		
+		Assertion.check( obj instanceof String, "obj instanceof String" );
+		String name = (String) obj;
+		Type type = vf.getType( name );
+		
+		if (type == null)
+			type = new Type( name );
+		
+		return type;
 	}
+
+	private Field readField( Type type ) throws IOException
+	{
+		Object obj = readValue( intOrStrValidator, true );
+		
+		if (obj == NONE)
+			return null;
+		
+		if (obj instanceof Integer)
+		{
+			Integer id = (Integer) obj;
+			Field field = type.getField( id );
+			
+			if (field == null)
+				field = new Field( id, id.toString() );
+			
+			return field;
+		}
+		
+		Assertion.check( obj instanceof String, "obj instanceof String" );
+		String name = (String) obj;
+		Field field = type.getField( name );
+		
+		if (field == null)
+			field = new Field( name );
+		
+		return field;
+	}
+	
+	private final Validator intOrStrValidator =
+		new ComboValidator( Validator_int.get( 0 ), Validator_string.get( 0 ) );
 	
 	private int readLength() throws IOException
 	{

Modified: incubator/etch/branches/etch-python/binding-java/runtime/src/main/java/etch/bindings/java/transport/fmt/binary/BinaryTaggedDataOutput.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/binding-java/runtime/src/main/java/etch/bindings/java/transport/fmt/binary/BinaryTaggedDataOutput.java?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/binding-java/runtime/src/main/java/etch/bindings/java/transport/fmt/binary/BinaryTaggedDataOutput.java (original)
+++ incubator/etch/branches/etch-python/binding-java/runtime/src/main/java/etch/bindings/java/transport/fmt/binary/BinaryTaggedDataOutput.java Sun Nov 16 14:35:35 2008
@@ -28,19 +28,28 @@
 import etch.bindings.java.msg.ValueFactory;
 import etch.bindings.java.msg.Validator.Level;
 import etch.bindings.java.support.Validator_int;
+import etch.bindings.java.support.Validator_string;
 import etch.bindings.java.transport.ArrayValue;
 import etch.bindings.java.transport.TaggedDataOutput;
 import etch.bindings.java.transport.fmt.TypeCode;
 import etch.util.FlexBuffer;
+import etch.util.URL;
 
 /**
- * Description of TaggedDataOutputStream.
+ * An implementation of TaggedDataOutput which uses a binary encoding.
  */
 final public class BinaryTaggedDataOutput extends BinaryTaggedData
 	implements TaggedDataOutput
 {
 	/**
-	 * Constructs the BinaryTaggedDataOutput with a null buffer.
+	 * Name of uri parameter which controls whether we write ints or strings
+	 * for types and fields.
+	 */
+	public static final String STRING_TYPE_AND_FIELD =
+		"BinaryTaggedDataOutput.stringTypeAndField";
+
+	/**
+	 * Constructs the BinaryTaggedDataOutput.
 	 * 
 	 * @param vf the value factory for the service.
 	 * @param uri the uri used to construct the transport stack.
@@ -48,11 +57,14 @@
 	public BinaryTaggedDataOutput( ValueFactory vf, String uri )
 	{
 		super( vf );
-		this.level = vf.getLevel();
-		// don't have anything to do with uri yet.
+		level = vf.getLevel();
+		URL u = new URL( uri );
+		stringTypeAndField = u.getBooleanTerm( STRING_TYPE_AND_FIELD, false );
 	}
 
 	private final Level level;
+	
+	private final boolean stringTypeAndField;
 
 	//////////////////////////////
 	// TaggedDataOutput methods //
@@ -95,11 +107,11 @@
 		for (Map.Entry<Field, Object> me: sv)
 		{
 			Field f = me.getKey();
-			writeIntValue( f.getId() );
+			writeField( f );
 			writeValue( t.getValidator( f ), me.getValue() );
 		}
 	}
-	
+
 	private void writeValues( ArrayValue av, Validator v )
 		throws IOException
 	{
@@ -160,16 +172,34 @@
 	
 	private void writeType( Type type ) throws IOException
 	{
-		writeIntValue( type.getId() );
+		if (stringTypeAndField)
+			writeStringValue( type.getName() );
+		else
+			writeIntValue( type.getId() );
 	}
 	
-	private void writeIntValue( int value ) throws IOException
+	private void writeField( Field field ) throws IOException
+	{
+		if (stringTypeAndField)
+			writeStringValue( field.getName() );
+		else
+			writeIntValue( field.getId() );
+	}
+
+	private void writeIntValue( Integer value ) throws IOException
 	{
 		writeValue( intValidator, value );
 	}
 	
 	private final Validator intValidator = Validator_int.get( 0 );
 	
+	private void writeStringValue( String value ) throws IOException
+	{
+		writeValue( stringValidator, value );
+	}
+	
+	private final Validator stringValidator = Validator_string.get( 0 );
+	
 	private void writeNoneValue() throws IOException
 	{
 		writeValue( noneValidator, NONE );

Modified: incubator/etch/branches/etch-python/binding-java/runtime/src/test/java/etch/bindings/java/transport/filters/TestKeepAlive.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/binding-java/runtime/src/test/java/etch/bindings/java/transport/filters/TestKeepAlive.java?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/binding-java/runtime/src/test/java/etch/bindings/java/transport/filters/TestKeepAlive.java (original)
+++ incubator/etch/branches/etch-python/binding-java/runtime/src/test/java/etch/bindings/java/transport/filters/TestKeepAlive.java Sun Nov 16 14:35:35 2008
@@ -113,9 +113,9 @@
 		KeepAlive filter = newKeepAlive(uri);
 		filter.setSession( session );		
 		filter.sessionNotify( Session.UP );
-		System.out.println("Sleeping for 5 seconds");
+//		System.out.println("Sleeping for 5 seconds");
 		Thread.sleep( 5000 );		 
-		System.out.println("Out of sleep");
+//		System.out.println("Out of sleep");
 		assertSame( What.TRANSPORT_MESSAGE, transport.what );
 		Message msg = transport.msg;
 		assertEquals( "_Etch_KeepAliveReq", msg.type().getName() );
@@ -132,9 +132,9 @@
 		KeepAlive filter = newKeepAlive(uri);
 		filter.setSession( session );		
 		filter.sessionNotify( Session.UP );
-		System.out.println("Sleeping for 4 seconds");
+//		System.out.println("Sleeping for 4 seconds");
 		Thread.sleep( 4000 );		 
-		System.out.println("Out of sleep");
+//		System.out.println("Out of sleep");
 		assertSame( What.TRANSPORT_MESSAGE, transport.what );
 		Message msg = transport.msg;
 		assertEquals( "_Etch_KeepAliveReq", msg.type().getName() );

Modified: incubator/etch/branches/etch-python/binding-java/runtime/src/test/java/etch/bindings/java/transport/fmt/binary/TestBinaryTaggedDataInOut.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/binding-java/runtime/src/test/java/etch/bindings/java/transport/fmt/binary/TestBinaryTaggedDataInOut.java?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/binding-java/runtime/src/test/java/etch/bindings/java/transport/fmt/binary/TestBinaryTaggedDataInOut.java (original)
+++ incubator/etch/branches/etch-python/binding-java/runtime/src/test/java/etch/bindings/java/transport/fmt/binary/TestBinaryTaggedDataInOut.java Sun Nov 16 14:35:35 2008
@@ -47,6 +47,7 @@
 import etch.util.FlexBuffer;
 import etch.util.Log;
 import etch.util.Resources;
+import etch.util.URL;
 import etch.util.core.Who;
 import etch.util.core.io.SessionPacket;
 import etch.util.core.io.Transport;
@@ -79,7 +80,7 @@
 		// the parking lot, you don't wanna go there.
 		
 //		ValueFactory vf = new DummyValueFactory();
-		BinaryTaggedDataOutput btdo = new BinaryTaggedDataOutput( vf, "tcp:" );
+		BinaryTaggedDataOutput btdo = new BinaryTaggedDataOutput( vf, "none:" );
 		
 		// byte values
 		for (byte i: getBytes( Byte.MIN_VALUE, 256 ))
@@ -300,7 +301,7 @@
 		Field _mf__messageId = DefaultValueFactory._mf__messageId;
 		add.putValidator( _mf__messageId, Validator_long.get( 0 ) );
 		
-		long msgid = 0x0123456789abcdefL;
+		long msgid = 0x0102030405060708L;
 		
 //		System.out.printf( "add.id() = %04x\n", add.getId() );
 //		System.out.printf( "x.id() = %04x\n", x.getId() );
@@ -312,21 +313,35 @@
 		msg.put( x, 1 );
 		msg.put( y, 2 );
 		msg.put( _mf__messageId, msgid );
-//		System.out.println( "msg = "+msg );
-		/* byte[] buf = */ msg2bytes( msg );
-//		dump( buf );
-//		buf = null;
+		testmsg2bytes( msg, null,  new byte[] { 3, -122, 39, -23, -73, -100, 3, -122, 21, 10, 44, -77, 1, -122, 99, 6, -76, 104, -121, 1, 2, 3, 4, 5, 6, 7, 8, -122, 21, 10, 44, -76, 2, -127 } );
+		testmsg2bytes( msg, false, new byte[] { 3, -122, 39, -23, -73, -100, 3, -122, 21, 10, 44, -77, 1, -122, 99, 6, -76, 104, -121, 1, 2, 3, 4, 5, 6, 7, 8, -122, 21, 10, 44, -76, 2, -127 } );
+		testmsg2bytes( msg, true,  new byte[] { 3, -109, 3, 97, 100, 100, 3, -109, 1, 120, 1, -109, 10, 95, 109, 101, 115, 115, 97, 103, 101, 73, 100, -121, 1, 2, 3, 4, 5, 6, 7, 8, -109, 1, 121, 2, -127 } );
 		
 		msg = new Message( add, vf );
 		msg.put( x, 1000000000 );
 		msg.put( y, 2000000000 );
 		msg.put( _mf__messageId, msgid );
-//		System.out.println( "msg = "+msg );
-		/* buf = */ msg2bytes( msg );
-//		dump( buf );
-//		buf = null;
+		testmsg2bytes( msg, null,  new byte[] { 3, -122, 39, -23, -73, -100, 3, -122, 21, 10, 44, -77, -122, 59, -102, -54, 0, -122, 99, 6, -76, 104, -121, 1, 2, 3, 4, 5, 6, 7, 8, -122, 21, 10, 44, -76, -122, 119, 53, -108, 0, -127 } );
+		testmsg2bytes( msg, false, new byte[] { 3, -122, 39, -23, -73, -100, 3, -122, 21, 10, 44, -77, -122, 59, -102, -54, 0, -122, 99, 6, -76, 104, -121, 1, 2, 3, 4, 5, 6, 7, 8, -122, 21, 10, 44, -76, -122, 119, 53, -108, 0, -127 } );
+		testmsg2bytes( msg, true,  new byte[] { 3, -109, 3, 97, 100, 100, 3, -109, 1, 120, -122, 59, -102, -54, 0, -109, 10, 95, 109, 101, 115, 115, 97, 103, 101, 73, 100, -121, 1, 2, 3, 4, 5, 6, 7, 8, -109, 1, 121, -122, 119, 53, -108, 0, -127 } );
 	}
 	
+	private void testmsg2bytes( Message msg, Boolean stringTypeAndField,
+		byte[] expected ) throws Exception
+	{
+		byte[] actual = msg2bytes( msg, stringTypeAndField );
+		try
+		{
+			assertArrayEquals( expected, actual );
+		}
+		catch ( AssertionError e )
+		{
+			dump( expected );
+			dump( actual );
+			throw e;
+		}
+	}
+
 	/** Tests reading a pre-canned add message.
 	 * @throws Exception */
 	@Test public void test_add_in() throws Exception
@@ -617,32 +632,36 @@
 	@Test
 	public void badtype() throws Exception
 	{
+		@SuppressWarnings("unused")
 		Message msg = bytes2msg( new byte[] { 3, 1, 0, -127 } );
-		System.out.println( "msg = "+msg );
+//		System.out.println( "msg = "+msg );
 	}
 	
 	/** @throws Exception */
 	@Test( expected = IllegalArgumentException.class )
 	public void badmsglen1() throws Exception
 	{
+		@SuppressWarnings("unused")
 		Message msg = bytes2msg( new byte[] { 3, 1, -1, -127 } );
-		System.out.println( "msg = "+msg );
+//		System.out.println( "msg = "+msg );
 	}
 	
 	/** @throws Exception */
 	@Test( expected = IllegalArgumentException.class )
 	public void badmsglen2() throws Exception
 	{
+		@SuppressWarnings("unused")
 		Message msg = bytes2msg( new byte[] { 3, 1, 99, -127 } );
-		System.out.println( "msg = "+msg );
+//		System.out.println( "msg = "+msg );
 	}
 	
 	/** @throws Exception */
 	@Test
 	public void badfield() throws Exception
 	{
+		@SuppressWarnings("unused")
 		Message msg = bytes2msg( new byte[] { 3, 1, 1, 2, 2, -127 }, Level.MISSING_OK );
-		System.out.println( "msg = "+msg );
+//		System.out.println( "msg = "+msg );
 	}
 	
 	private void assertValueToBytes( Object value, byte[] expectedBytes ) throws Exception
@@ -653,7 +672,7 @@
 		
 		Message msg = new Message( t, vf );
 		msg.put( f, value );
-		System.out.println( "msg = "+msg );
+//		System.out.println( "msg = "+msg );
 		
 		BinaryTaggedDataOutput btdo = new BinaryTaggedDataOutput( vf, "none:" );
 		FlexBuffer buf = new FlexBuffer();
@@ -662,7 +681,7 @@
 		
 		buf.setIndex( 0 );
 		byte[] b = buf.getAvailBytes();
-		dump( b );
+//		dump( b );
 		assertArrayEquals( expectedBytes, b );
 	}
 	
@@ -725,10 +744,15 @@
 		}
 	}
 	
-	private byte[] msg2bytes( Message msg ) throws IOException
+	private byte[] msg2bytes( Message msg, Boolean stringTypeAndField ) throws IOException
 	{
 		FlexBuffer buf = new FlexBuffer();
-		BinaryTaggedDataOutput btdo = new BinaryTaggedDataOutput( vf, "" );
+		
+		URL u = new URL( "none:" );
+		if (stringTypeAndField != null)
+			u.addTerm( BinaryTaggedDataOutput.STRING_TYPE_AND_FIELD, stringTypeAndField );
+		
+		BinaryTaggedDataOutput btdo = new BinaryTaggedDataOutput( vf, u.toString() );
 		btdo.writeMessage( msg, buf );
 		buf.setIndex( 0 );
 		return buf.getAvailBytes();
@@ -765,8 +789,9 @@
 				testx( Array.get( x, i ), v.elementValidator() );
 			}
 		}
-		Object y = test( x, v );
-		assertEquals( x, y );
+		test( x, v, null );
+		test( x, v, false );
+		test( x, v, true );
 	}
 	
 	/**
@@ -778,8 +803,8 @@
 	private final Type mt_foo = vf.getType( "foo" );
 	
 	private final Field mf_x = new Field( "x" );
-
-	private Object test( Object x, Validator v ) throws Exception
+	
+	private void test( Object x, Validator v, Boolean stringTypeAndField ) throws Exception
 	{
 //		System.out.println( "-----------------------------------------" );
 		
@@ -790,15 +815,17 @@
 		msg.put( mf_x, x );
 //		System.out.println( "msg = "+msg );
 		
-		byte[] bufx = msg2bytes( msg );
+		byte[] bufx = msg2bytes( msg, stringTypeAndField );
 //		dump( bufx );
 		Message msg2 = bytes2msg( bufx );
 		
 //		System.out.println( "msg2 = "+msg2 );
 		msg2.checkType( mt_foo );
 		Assert.assertEquals( 1, msg2.size() );
-		msg.containsKey( mf_x );
-		return msg2.get( mf_x );
+		Assert.assertTrue( msg.containsKey( mf_x ) );
+		Object y = msg2.get( mf_x );
+		
+		assertEquals( x, y );
 	}
 	
 	@SuppressWarnings("unused")

Propchange: incubator/etch/branches/etch-python/binding-python/runtime/src/main/python/etch/binding/msg/AsyncMode.py
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Nov 16 14:35:35 2008
@@ -0,0 +1 @@
+/incubator/etch/trunk/binding-python/runtime/src/main/python/etch/binding/msg/AsyncMode.py:712746-718069

Propchange: incubator/etch/branches/etch-python/binding-python/runtime/src/main/python/etch/binding/msg/ComboValidator.py
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Nov 16 14:35:35 2008
@@ -0,0 +1 @@
+/incubator/etch/trunk/binding-python/runtime/src/main/python/etch/binding/msg/ComboValidator.py:712746-718069

Propchange: incubator/etch/branches/etch-python/binding-python/runtime/src/main/python/etch/binding/msg/FieldMap.py
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Nov 16 14:35:35 2008
@@ -0,0 +1 @@
+/incubator/etch/trunk/binding-python/runtime/src/main/python/etch/binding/msg/FieldMap.py:712746-718069

Propchange: incubator/etch/branches/etch-python/binding-python/runtime/src/main/python/etch/binding/msg/IdNameMap.py
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Nov 16 14:35:35 2008
@@ -0,0 +1 @@
+/incubator/etch/trunk/binding-python/runtime/src/main/python/etch/binding/msg/IdNameMap.py:712746-718069

Propchange: incubator/etch/branches/etch-python/binding-python/runtime/src/main/python/etch/binding/msg/TypeMap.py
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Nov 16 14:35:35 2008
@@ -0,0 +1 @@
+/incubator/etch/trunk/binding-python/runtime/src/main/python/etch/binding/msg/TypeMap.py:712746-718069

Modified: incubator/etch/branches/etch-python/binding-xml/compiler/src/main/java/etch/bindings/xml/compiler/Compiler.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/binding-xml/compiler/src/main/java/etch/bindings/xml/compiler/Compiler.java?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/binding-xml/compiler/src/main/java/etch/bindings/xml/compiler/Compiler.java (original)
+++ incubator/etch/branches/etch-python/binding-xml/compiler/src/main/java/etch/bindings/xml/compiler/Compiler.java Sun Nov 16 14:35:35 2008
@@ -17,7 +17,6 @@
 
 package etch.bindings.xml.compiler;
 
-import java.io.File;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringReader;
@@ -37,6 +36,7 @@
 import etch.compiler.CmdLineOptions;
 import etch.compiler.EtchGrammarConstants;
 import etch.compiler.LogHandler;
+import etch.compiler.Output;
 import etch.compiler.ParseException;
 import etch.compiler.Token;
 import etch.compiler.Version;
@@ -117,7 +117,7 @@
 				return;
 			
 			if (lh != null)
-				lh.logMessage( level == 2 ? LogHandler.LEVEL_WARNING : LogHandler.LEVEL_ERROR, null, msg );
+				lh.report( level == 2 ? LogHandler.LEVEL_WARNING : LogHandler.LEVEL_ERROR, null, msg );
 			else
 				System.out.printf( "Velocity msg (%d): %s\n", level, msg );
 		}
@@ -128,7 +128,7 @@
 				return;
 			
 			if (lh != null)
-				lh.logMessage( level == 2 ? LogHandler.LEVEL_WARNING : LogHandler.LEVEL_ERROR, null, msg );
+				lh.report( level == 2 ? LogHandler.LEVEL_WARNING : LogHandler.LEVEL_ERROR, null, msg );
 			else
 				System.out.printf( "Velocity msg (%d): %s: %s\n", level, msg, e );
 		}
@@ -190,52 +190,56 @@
 	private final Template vf_vm;
 
 	@Override
-	public void generate( Module module, CmdLineOptions options,
-		LogHandler lh )
+	public void generate( Module module, CmdLineOptions options )
 		throws Exception
 	{
-
-		this.lh = lh;
+		// xml always wants to not flatten packages:
+		options.noFlattenPackages = true;
 		
-		File dir = options.outputDir;
+		this.lh = options.lh;
 		
-		// ok, we're ready to generate code. make sure the
-		// output directories exist.
-
-		if (dir != null && module.name().name.length() > 0)
-		{
-			String path = module.name().name.replace( '.', '/' );
-			dir = new File( dir, path );
-		}
-		else
+		Output dir = options.output;
+		
+		String m = module.name().name;
+		if (m.length() > 0)
 		{
-			dir = new File( "." );
+			dir = dir.newPackage( m );
 		}
 
-		// System.out.println( "generating to "+dir );
-
-		dir.mkdirs();
-
 		// generate code for each service.
 
 		for (Service intf : module)
 		{
+			// TODO flush gIntf
 			gIntf = intf;
-			generate( intf/*, what*/, dir );
+			try
+			{
+				generate( intf, dir );
+			}
+			finally
+			{
+				// TODO flush gIntf
+				gIntf = null;
+			}
 		}
-		gIntf = null;
 	}
 
+	// TODO flush gIntf
+	@Deprecated
 	private Service gIntf;
 
-	private void generate( final Service intf, /*MessageDirection what, */File dir )
+	private void generate( final Service intf, Output dir )
 		throws Exception
 	{
 		// Generate the value factory file
 
-		doFile( dir, getVfName( intf )+fnSuffix, true,
-			true, new Gen() { public void run( PrintWriter pw ) throws Exception
-				{ generateVf( pw, intf ); } }, lh );
+		doFile( dir, getVfName( intf ) + fnSuffix, lh, new Gen()
+		{
+			public void run( PrintWriter pw ) throws Exception
+			{
+				generateVf( pw, intf );
+			}
+		} );
 	}
 
 	/**

Modified: incubator/etch/branches/etch-python/build-support/NUnitToJUnit.xsl
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/build-support/NUnitToJUnit.xsl?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/build-support/NUnitToJUnit.xsl (original)
+++ incubator/etch/branches/etch-python/build-support/NUnitToJUnit.xsl Sun Nov 16 14:35:35 2008
@@ -5,23 +5,29 @@
     <xsl:template match="test-results/test-suite">
 
         <xsl:variable name="testcases" select="//test-suite[./results/test-case]"/>
+        <!--
         <xsl:variable name="asmClass">
-                <xsl:choose>
-                        <xsl:when test="$testcases"><xsl:value-of select="$testcases[1]/../../@name"/></xsl:when>
-                        <xsl:otherwise><xsl:value-of select="@name"/></xsl:otherwise>
-                </xsl:choose>
+            <xsl:choose>
+                <xsl:when test="$testcases"><xsl:value-of select="$testcases[1]/../../@name"/></xsl:when>
+                <xsl:otherwise><xsl:value-of select="@name"/></xsl:otherwise>
+            </xsl:choose>
         </xsl:variable>
+        -->
         <testsuite name="NUnitTests" time="{@time}" tests="{count($testcases//test-case)}"
             errors="" failures="{count($testcases//test-case/failure)}">
 
             <xsl:for-each select="$testcases">
+
                 <xsl:variable name="suite" select="."/>
                 <xsl:variable name="generalfailure" select="./failure"/>
                 <xsl:for-each select=".//test-case">
-                <xsl:variable name="tempBefore" select="concat(concat(substring-before(./@name, $asmClass), $asmClass),'.')" />
-                <xsl:variable name="tempAfter" select="substring-after(./@name, $tempBefore)" />
-                <testcase classname="{concat($tempBefore, substring-before($tempAfter, '.'))}"
-                	name="{substring-after($tempAfter, '.')}" time="{./@time}">
+                
+                <xsl:variable name="testClass" select="concat(substring-before(./@name, ./../../@name), ./../../@name)" />
+                <xsl:variable name="testName" select="substring-after(./@name, concat($testClass,'.'))" />
+
+                <testcase classname="{$testClass}" name="{$testName}" time="{./@time}" >
+                
+                 
                 <xsl:if test="./failure">
                 <xsl:variable name="failstack" select="count(./failure/stack-trace/*) + count(./failure/stack-trace/text())"/>
                 <failure>

Modified: incubator/etch/branches/etch-python/build-support/dependencies.xml
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/build-support/dependencies.xml?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/build-support/dependencies.xml (original)
+++ incubator/etch/branches/etch-python/build-support/dependencies.xml Sun Nov 16 14:35:35 2008
@@ -43,4 +43,4 @@
     <target name="check-all" depends="check-javacc,check-junit,check-velocity,check-dotnet" />
     
 
-</project>
\ No newline at end of file
+</project>

Modified: incubator/etch/branches/etch-python/build-support/etch.common.xml
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/build-support/etch.common.xml?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/build-support/etch.common.xml (original)
+++ incubator/etch/branches/etch-python/build-support/etch.common.xml Sun Nov 16 14:35:35 2008
@@ -90,7 +90,7 @@
     <property name="tool.vs-2k5-task" value="${Etch.runtime.workspace}/scripts/vs-2k5-task.bat" />
 
     <!-- NSIS installer support -->
-    <property name="tool.makensis"    value="${env.NSIS_HOME}\makensis.exe" />
+    <property name="tool.makensis"    value="${build.nsis.home}\makensis.exe" />
     <condition property="NSIS.enabled">
         <and>
             <os family="windows" />
@@ -110,13 +110,15 @@
     <condition property="USE.dotnet">
         <and>
             <os family="windows" />
-            <available file="${env.DOTNET_HOME}/msbuild.exe" />
+            <available file="${build.dotnet.home}/msbuild.exe" />
         </and>
     </condition>
     <condition property="USE.mono">
         <and>
             <not><os family="windows" /></not>
-            <available file="${env.MONO_HOME}/bin/mdtool" />
+            <!-- TODO mono support is not fully baked, use -DUSE.mono to test -->
+            <!-- <available file="${build.mono.home}/bin/mdtool" /> -->
+            <isset property="USE.mono" />
         </and>
     </condition>
     <condition property="BUILD.csharp">
@@ -125,18 +127,18 @@
             <isset property="USE.mono" />
         </or>
     </condition>
-    <property name="tool.mdtool" value="${env.MONO_HOME}/bin/mdtool" />
+    <property name="tool.mdtool" value="${build.mono.home}/bin/mdtool" />
 
     <!-- clover support -->
     <!-- TODO: make this toggle-able -->
     <property name="With.clover" value="true" />
     <condition property="Clover.enabled" >
         <and>
-            <available file="${env.CLOVER_HOME}/lib/clover.jar" />
+            <available file="${build.clover.home}/lib/clover.jar" />
             <isset property="With.clover" />
         </and>
     </condition>
-    <property name="Etch.dependency.clover.jar" value="${env.CLOVER_HOME}/lib/clover.jar" />
+    <property name="Etch.dependency.clover.jar" value="${build.clover.home}/lib/clover.jar" />
     <taskdef resource="cloverlib.xml" classpath="${Etch.dependency.clover.jar}" />
     <!-- If Clover is enabled, use the clover version of the Etch build, this
          allows code-coverage metrics to be collected throughout the build process -->
@@ -158,7 +160,7 @@
     <property name="Clover.coverage" location="${Clover.path}/code-coverage-results" />
     
     <!-- properties for examples -->
-    <property name="EXAMPLE.etch.home" value="${Etch.HOME}" />
+    <property name="EXAMPLE.etch.home" value="${Etch.dist}" />
     <property name="EXAMPLE.etch.version" value="${Etch.version}" />
     <property name="EXAMPLE.ant.dotnet.jar" value="${Etch.dependency.ant-dotnet-1.0.jar}" />
     
@@ -222,9 +224,10 @@
     <!-- token filter macro -->
     <macrodef name="update-tokens" >
         <attribute name="filename" />
+        <attribute name="template" default="@{filename}.tmpl" />
         <sequential>
             <!-- Generate version info -->
-            <copy tofile="@{filename}" file="@{filename}.tmpl" overwrite="true">
+            <copy tofile="@{filename}" file="@{template}" overwrite="true">
                 <filterset refid="Etch.buildTokens" />
             </copy>
         </sequential>

Modified: incubator/etch/branches/etch-python/build.dependencies
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/build.dependencies?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/build.dependencies (original)
+++ incubator/etch/branches/etch-python/build.dependencies Sun Nov 16 14:35:35 2008
@@ -1,4 +1,28 @@
+##
+## Core Dependencies .. these must be set
+##
+
 javacc.home=${env.TOOLS_DIR}/javacc/4.0
 junit.lib=${env.TOOLS_DIR}/junit/4.3.1
 velocity.lib=${env.TOOLS_DIR}/velocity/1.5
+
+##
+## Optional Dependencies
+##
+
+## NSIS
+nsis.home=${env.NSIS_HOME}
+
+## Clover
+clover.home=${env.CLOVER_HOME}
+
+## Csharp support
 ant-dotnet.lib=${env.TOOLS_DIR}/apache-ant-dotnet/1.0
+nunit.home=${env.NUNIT_HOME}
+
+# Set to the .NET 2.0 framework install
+dotnet.home=${env.windir}/Microsoft.NET/Framework/v2.0.50727
+
+# MONO support still a bit flakey
+mono.home=${env.MONO_HOME}
+

Modified: incubator/etch/branches/etch-python/compiler/build.xml
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/compiler/build.xml?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/compiler/build.xml (original)
+++ incubator/etch/branches/etch-python/compiler/build.xml Sun Nov 16 14:35:35 2008
@@ -49,7 +49,7 @@
             <!-- main-resources -->
             <copy todir="${classesDirectory}/main">
                 <fileset dir="${src}/main/resources">
-                    <include name="**/*.kwd" />
+                    <include name="**" />
                 </fileset>
             </copy>            
 
@@ -70,7 +70,7 @@
             <!-- test-resources -->
             <copy todir="${classesDirectory}/test">
                 <fileset dir="${src}/test/resources">
-                    <include name="**/*.kwd" />
+                    <include name="**" />
                 </fileset>
             </copy>            
 

Modified: incubator/etch/branches/etch-python/compiler/src/main/java/etch/compiler/Backend.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/compiler/src/main/java/etch/compiler/Backend.java?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/compiler/src/main/java/etch/compiler/Backend.java (original)
+++ incubator/etch/branches/etch-python/compiler/src/main/java/etch/compiler/Backend.java Sun Nov 16 14:35:35 2008
@@ -17,12 +17,9 @@
 
 package etch.compiler;
 
-import java.io.BufferedOutputStream;
 import java.io.BufferedReader;
-import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -44,6 +41,7 @@
 import etch.compiler.ast.Service;
 import etch.compiler.ast.TypeRef;
 import etch.compiler.opt.Extern;
+import etch.util.Assertion;
 
 /**
  * Generic interface to language (or language/runtime) bindings.
@@ -53,61 +51,68 @@
 	private final static String tmplPath1 = "etch/compiler/";
 	private final static String tmplPath2 = "resources/etch/compiler/";
 	
+	//////////////////////////
+	// WHAT DIRECTION GROUP //
+	//////////////////////////
+	
 	/**
-	 * Constant for Command Line option BOTH
+	 * Constant for option --what: generate both client and server files.
 	 */
 	public static final String WHAT_BOTH = "BOTH";
+	
 	/**
-	 * Constant for Command Line option ALL
-	 */
-	public static final String WHAT_ALL = "ALL";
-	/**
-	 * Constant for Command Line option CLIENT
+	 * Constant for option --what: generate client files.
 	 */
 	public static final String WHAT_CLIENT = "CLIENT";
+	
 	/**
-	 * Constant for Command Line option SERVER
+	 * Constant for option --what: generate generate server files.
 	 */
 	public static final String WHAT_SERVER = "SERVER";
+
+	//////////////////////
+	// WHAT FILES GROUP //
+	//////////////////////
+	
 	/**
-	 * Constant for Command Line option IMPL
-	 */
-	public static final String WHAT_IMPL = "IMPL";
-	/**
-	 * Constant for Command Line option MAIN
-	 */
-	public static final String WHAT_MAIN = "MAIN";
-	/**
-	 * Constant for Command Line option HELPER
-	 */
-	public static final String WHAT_HELPER = "HELPER";
-	/**
-	 * Constant for Command Line option FORCE
+	 * Constant for option --what: generate all files.
 	 */
-	public static final String WHAT_FORCE = "FORCE";
+	public static final String WHAT_ALL = "ALL";
+	
 	/**
-	 * Constant for Command Line option NONE
+	 * Constant for option --what: generate no files.
 	 */
 	public static final String WHAT_NONE = "NONE";
+	
 	/**
-	 * Constant for Java Binding
+	 * Constant for option --what: generate intf files.
 	 */
-	public static final String BINDING_JAVA = "java";
+	public static final String WHAT_INTF = "INTF";
+	
 	/**
-	 * Constant for CSharp Binding
+	 * Constant for option --what: generate main file.
 	 */
-	public static final String BINDING_CSHARP = "csharp";
+	public static final String WHAT_MAIN = "MAIN";
+	
 	/**
-	 * Constant for Ruby Binding
+	 * Constant for option --what: generate impl files.
 	 */
-	public static final String BINDING_RUBY = "ruby";
+	public static final String WHAT_IMPL = "IMPL";
+
+	/////////////////////
+	// WHAT MISC GROUP //
+	/////////////////////
+	
 	/**
-	 * Constant for XML Binding
+	 * Constant for option --what: overwrite template files.
 	 */
-	public static final String BINDING_XML = "xml";
+	public static final String WHAT_FORCE = "FORCE";
 	
+	/**
+	 * Constant for option --what: give help on what.
+	 */
+	public static final String WHAT_HELP = "HELP";
 	
-
 	/**
 	 * Constructs the Backend.
 	 * @throws Exception
@@ -134,12 +139,10 @@
 	 * Generates code for this binding of the idl.
 	 * @param module the module that we are generating code for.
 	 * @param options the options used to configure the compiler.
-	 * @param lh the log handler to use.
 	 * @throws Exception
 	 */
-	abstract public void generate( Module module, CmdLineOptions options,
-		LogHandler lh)
-	throws Exception;
+	abstract public void generate( Module module, CmdLineOptions options )
+		throws Exception;
 
 	/**
 	 * Runs the generator for a particular file with the specified
@@ -227,40 +230,20 @@
 	 * Creates (or deletes) the specified file.
 	 * @param dir
 	 * @param fn
-	 * @param makeFile
-	 * @param force
 	 * @param gen
 	 * @throws Exception
 	 */
-	protected void doFile( File dir, String fn, boolean makeFile, boolean force, Gen gen, LogHandler lh )
+	protected void doFile( Output dir, String fn, LogHandler lh, Gen gen )
 		throws Exception
 	{
-		File f = new File( dir, fn );
-
-		if (makeFile)
+		PrintWriter pw = new PrintWriter( dir.newOutputStream( fn ) );
+		try
 		{
-			if (!f.isFile())
-				f.createNewFile();
-			else if (!force)
-			{
-			//	System.err.printf( "file %s not generated because already exists; use -w force to overwrite\n", fn );
-				lh.logMessage( LogHandler.LEVEL_WARNING, null, String.format( "file %s not generated because already exists; use -w force to overwrite\n", fn) );
-				return;
-			}
-
-			PrintWriter pw = new PrintWriter( new BufferedOutputStream( new FileOutputStream( f ) ) );
-			try
-			{
-				gen.run( pw );
-			}
-			finally
-			{
-				pw.close();
-			}
+			gen.run( pw );
 		}
-		else if (f.isFile())
+		finally
 		{
-			f.delete();
+			pw.close();
 		}
 	}
 
@@ -342,77 +325,144 @@
 	 * @param what
 	 * @return the appropriate direction give --what command line options.
 	 */
-	protected MessageDirection getMessageDirection(Set<String> what) {
-
-		if ( what.contains( WHAT_BOTH )  ) {
+	protected MessageDirection getMessageDirection(Set<String> what)
+	{
+		if ( what.contains( WHAT_BOTH )  )
 			return MessageDirection.BOTH;
-		}
-		if ( what.contains( WHAT_SERVER ) ) {
+		
+		if ( what.contains( WHAT_SERVER ) )
 			return MessageDirection.SERVER;
-		}
-		if ( what.contains( WHAT_CLIENT ) ) {
+		
+		if ( what.contains( WHAT_CLIENT ) )
 			return MessageDirection.CLIENT;
-		}
 
-		return null; // default value
+		throw new IllegalArgumentException( "what not correctly specified" );
 	}
 	
 	/**
 	 * @param what
-	 * @return what modified to account for all, both, and none options.
+	 * @return what modified to account for interaction of options.
 	 */
-	protected Set<String> populateWhat(Set<String> what) {
-
-		if(!checkOption(what))
+	protected Set<String> populateWhat( Set<String> what ) throws Exception
+	{
+		checkOption( what );
+		
+		if (what.contains( WHAT_HELP ))
+			throw new Exception(
+				"specify what as one or more of "+whatHelp() );
+		
+		// direction group
+		
+		if (!what.contains( WHAT_CLIENT )
+			&& !what.contains( WHAT_SERVER )
+			&& !what.contains( WHAT_BOTH ) )
 		{
-			return null;
+			// default to BOTH if none of the direction group is present.
+			what.add( WHAT_BOTH );
+			what.add( WHAT_CLIENT );
+			what.add( WHAT_SERVER );
 		}
-		
-		if (what.contains( WHAT_ALL ))
+		else if (what.contains( WHAT_BOTH ))
 		{
-//			what.add( WHAT_BOTH );
-			what.add( WHAT_IMPL );
-			what.add( WHAT_MAIN );
-			what.add( WHAT_HELPER );
+			// BOTH implies CLIENT and SERVER
+			what.add( WHAT_CLIENT );
+			what.add( WHAT_SERVER );
 		}
-		
-		if (! what.contains( WHAT_CLIENT ) && !what.contains( WHAT_SERVER ) && !what.contains( WHAT_BOTH ) ) {
+		else if (what.contains( WHAT_CLIENT ) && what.contains( WHAT_SERVER ))
+		{
+			// CLIENT and SERVER together implies BOTH
 			what.add( WHAT_BOTH );
 		}
 		
-		if (what.contains( WHAT_BOTH ))
+		// there are three reasonable outcomes of the above logic:
+		// CLIENT
+		// SERVER
+		// BOTH, CLIENT, SERVER
+		Assertion.check(
+			   (what.contains( WHAT_CLIENT ) && !what.contains( WHAT_SERVER ) && !what.contains( WHAT_BOTH ))
+			|| (!what.contains( WHAT_CLIENT ) && what.contains( WHAT_SERVER ) && !what.contains( WHAT_BOTH ))
+			|| (what.contains( WHAT_CLIENT ) && what.contains( WHAT_SERVER ) && what.contains( WHAT_BOTH ))
+			, "what files is {CLIENT}, {SERVER}, OR {CLIENT,SERVER,BOTH}" );
+		
+		// files group
+		
+		if (!what.contains( WHAT_ALL )
+			&& !what.contains( WHAT_NONE )
+			&& !what.contains( WHAT_INTF )
+			&& !what.contains( WHAT_MAIN )
+			&& !what.contains( WHAT_IMPL ))
 		{
-			what.add( WHAT_CLIENT );
-			what.add( WHAT_SERVER );
+			// default to INTF if none of the file group is present.
+			what.add( WHAT_INTF );
 		}
-
-		if (what.contains( WHAT_NONE ))
+		
+		if (what.contains( WHAT_ALL ))
 		{
-	        what.clear();
+			what.add( WHAT_INTF );
+			what.add( WHAT_MAIN );
+			what.add( WHAT_IMPL );
+			what.remove( WHAT_ALL );
+	        what.remove( WHAT_NONE );
 		}
 		
-//		if (what.isEmpty())
-//		{
-//			return what;
-//		}
+		if (what.contains( WHAT_NONE ))
+		{
+	        what.remove( WHAT_INTF );
+	        what.remove( WHAT_MAIN );
+	        what.remove( WHAT_IMPL );
+	        what.remove( WHAT_NONE );
+		}
 		
 		return what;
 	}
 
-	private boolean checkOption( Set<String> what )
+	private void checkOption( Set<String> what ) throws Exception
 	{
 		Set<String> w = new HashSet<String>( what );
-		w.remove( WHAT_BOTH );
+		
+		// what direction group
 		w.remove( WHAT_CLIENT );
 		w.remove( WHAT_SERVER );
+		w.remove( WHAT_BOTH );
+		
+		// what files group
 		w.remove( WHAT_ALL );
 		w.remove( WHAT_NONE );
-		w.remove( WHAT_IMPL );
+		w.remove( WHAT_INTF );
 		w.remove( WHAT_MAIN );
-		w.remove( WHAT_HELPER );
+		w.remove( WHAT_IMPL );
+		
 		w.remove( WHAT_FORCE );
-
-		return w.isEmpty();
+		w.remove( WHAT_HELP );
+		
+		if (!w.isEmpty())
+			throw new Exception(
+				"bad what option value(s): "+w
+				+"; specify what as one or more of "
+				+ whatHelp() );
+	}
+	
+	private String whatHelp()
+	{
+		return WHAT_CLIENT
+			+", "
+			+WHAT_SERVER
+			+", "
+			+WHAT_BOTH
+			+", "
+			+WHAT_ALL
+			+", "
+			+WHAT_NONE
+			+", "
+			+WHAT_INTF
+			+", "
+			+WHAT_MAIN
+			+", "
+			+WHAT_IMPL
+			+", "
+			+WHAT_FORCE
+			+", "
+			+WHAT_HELP;
 	}
 
 

Modified: incubator/etch/branches/etch-python/compiler/src/main/java/etch/compiler/CmdLineOptions.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/compiler/src/main/java/etch/compiler/CmdLineOptions.java?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/compiler/src/main/java/etch/compiler/CmdLineOptions.java (original)
+++ incubator/etch/branches/etch-python/compiler/src/main/java/etch/compiler/CmdLineOptions.java Sun Nov 16 14:35:35 2008
@@ -25,30 +25,50 @@
 import java.util.Set;
 
 /**
- * This class contains options to be passed to the Etch compiler.
+ * This class defines options to be passed to the Etch compiler.
  */
 public class CmdLineOptions
 {
 	/**
+	 * Name of the environment variable which contributes to the include path.
+	 */
+	public final static String ETCH_INCLUDE_PATH = "ETCH_INCLUDE_PATH";
+	
+    /**
+     * Separators for items in the "what" list.
+     */
+    public static String WHAT_DELIMETER = ",;: ";
+	
+	/**
 	 * Constructs a new CmdLineOptions from an existing one.
 	 * @param other
 	 */
 	public CmdLineOptions( CmdLineOptions other )
 	{
-		includePath = new ArrayList<File>(other.includePath);
-		ignoreGlobal = other.ignoreGlobal;
-		ignoreLocal = other.ignoreLocal;
+		includePath = new ArrayList<File>( other.includePath );
+		ignoreGlobalWordsList = other.ignoreGlobalWordsList;
+		ignoreLocalWordsList = other.ignoreLocalWordsList;
 		userWordsList = other.userWordsList;
 		outputDir = other.outputDir;
 		binding = other.binding;
-		what = new HashSet<String>(other.what);
-		bindingClass = other.bindingClass;
+		what = new HashSet<String>( other.what );
 		mixinOutputDir = other.mixinOutputDir;
 		noMixinArtifacts = other.noMixinArtifacts;
-		isMixinPresent = other.isMixinPresent;
 		noFlattenPackages = other.noFlattenPackages;
 		quiet = other.quiet;
+		templateOutputDir = other.templateOutputDir;
+		ignoreIncludePath = other.ignoreIncludePath;
+		testing = other.testing;
+		sourceFile = other.sourceFile;
+		// EPHEMERAL STUFF //
+		cl = other.cl;
 		lh = other.lh;
+		effectiveIncludePath = new ArrayList<File>( other.effectiveIncludePath );
+		output = other.output;
+		templateOutput = other.templateOutput;
+		mixinOutput = other.mixinOutput;
+		bindingClass = other.bindingClass;
+		backend = other.backend;
 	}
 	
 	/**
@@ -56,7 +76,9 @@
 	 */
 	public CmdLineOptions()
 	{
-		// nothing to do.
+		includePath = new ArrayList<File>();
+		what = new HashSet<String>();
+		effectiveIncludePath = new ArrayList<File>();
 	}
 	
 	/**
@@ -68,21 +90,22 @@
 	 * Flag indicates whether to ignore the globally reserved word list (-g
 	 * option).
 	 */
-	public boolean ignoreGlobal;
+	public boolean ignoreGlobalWordsList;
 
 	/**
 	 * Flag indicates whether to ignore the locally reserved word list (-l
 	 * option).
 	 */
-	public boolean ignoreLocal;
+	public boolean ignoreLocalWordsList;
 
 	/**
 	 * The path of the user-defined reserved words list (-W option).
 	 */
-	public String userWordsList;
+	public File userWordsList;
 
 	/**
-	 * The location of the generated files (-d option).
+	 * The destination directory of the generated files (-d option). If not
+	 * specified, the same directory of the source file.
 	 */
 	public File outputDir;
 
@@ -94,36 +117,27 @@
 
 	/**
 	 * This specifies the file(s) we need to generate (-w option). Valid values
-	 * depend upon the binding, but examples include ALL, BOTH, SERVER, CLIENT,
-	 * IMPL, MAIN, and NONE.
+	 * depend upon the binding, but examples include BOTH, SERVER, CLIENT, ALL,
+	 * INTF, IMPL, MAIN, NONE, and FORCE. HELP might give you some. Separate
+	 * values using one or more characters from ",;: " (e.g., "BOTH, INTF",
+	 * which is also the default for many bindings).
 	 */
 	public Set<String> what;
 
 	/**
-	 * This class specifies the binding to use. If the string binding is
-	 * specified then this variable does not need to be defined. It is currently
-	 * only used internally by Etch2.
-	 * @deprecated the compiler should really specify binding name.
-	 */
-	@Deprecated
-	public Class<?> bindingClass;
-
-	/**
-	 * The location of the generated mixin files (-m option).
+	 * The destination directory of the generated mixin files (-m option). If
+	 * not specified, and if {@link #noMixinArtifacts} allows, mixin artifacts
+	 * are generated into {@link #outputDir}.
 	 */
 	public File mixinOutputDir;
 
 	/**
 	 * Flag indicates that mixin artifacts should not be generated (-n option).
+	 * If false, mixin artifacts are generated into {@link #mixinOutputDir}.
 	 */
 	public boolean noMixinArtifacts;
 
 	/**
-	 * Flag indicates that a mixin has been detected.
-	 */
-	public boolean isMixinPresent;
-
-	/**
 	 * Flag indicates whether the module name should should be flattened to
 	 * produce a single directory or a directory tree (e.g., for csharp) (-f
 	 * option).
@@ -134,9 +148,71 @@
 	 * Flag indicates that the compiler should not report progress (-q option).
 	 */
 	public boolean quiet;
+
+	/**
+	 * Destination directory of the user editable template files (-t option).
+	 * If not specified, same as {@link #outputDir}.
+	 */
+	public File templateOutputDir;
+
+	/**
+	 * Ignore the ETCH_INCLUDE_PATH environment variable (-i option).
+	 */
+	public boolean ignoreIncludePath;
+
+	/**
+	 * We're just testing the compiler, don't write any files (--testing option).
+	 */
+	public boolean testing;
+
+	/**
+	 * The source file to compile.
+	 */
+	public File sourceFile;
+
+	/////////////////////
+	// EPHEMERAL STUFF //
+	/////////////////////
+
+	/**
+	 * The binding class loader.
+	 */
+	public ClassLoader cl;
 	
 	/**
 	 * Destination of various error or status messages.
 	 */
 	public LogHandler lh;
+
+	/**
+	 * Computed effective includePath, including parent dir of source file,
+	 * include path command line elements, and path elements from system
+	 * environment variable.
+	 */
+	public List<File> effectiveIncludePath;
+
+	/**
+	 * Output for service generated files.
+	 */
+	public Output output;
+
+	/**
+	 * Output for service user-editable generated files.
+	 */
+	public Output templateOutput;
+
+	/**
+	 * Output for mixed in artifacts.
+	 */
+	public Output mixinOutput;
+    
+	/**
+	 * The class which implements the binding.
+	 */
+	public Class<?> bindingClass;
+    
+	/**
+	 * The instance of bindingClass used to generated code.
+	 */
+	public Backend backend;
 }

Modified: incubator/etch/branches/etch-python/compiler/src/main/java/etch/compiler/Etch2.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/compiler/src/main/java/etch/compiler/Etch2.java?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/compiler/src/main/java/etch/compiler/Etch2.java (original)
+++ incubator/etch/branches/etch-python/compiler/src/main/java/etch/compiler/Etch2.java Sun Nov 16 14:35:35 2008
@@ -1,645 +1,643 @@
-/* $Id$
- *
- * Copyright 2007-2008 Cisco Systems Inc.
- *
- * 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 etch.compiler;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-import java.util.StringTokenizer;
-
-import etch.compiler.ast.Module;
-import etch.util.cmd.CommandParser;
-import etch.util.cmd.Option;
-import etch.util.cmd.Parameter;
-import etch.util.cmd.Program;
-
-
-/**
- * The main command line interface for the etch compiler.
- * @deprecated
- */
-@Deprecated
-public class Etch2 extends Program
-{
-	private static String WHO_DELIMETER = ",";
-
-	private static String ETCH_INCLUDE_PATH = "ETCH_INCLUDE_PATH";
-
-	private LogHandler logHandler;
-
-	/**
-	 * @param args
-	 * @deprecated
-	 */
-	@Deprecated
-	public static void main( String[] args )
-	{
-		try
-		{
-			main( new Etch2(), args );
-		}
-		catch ( Throwable e )
-		{
-			// TODO can we be more descriptive here?
-			e.printStackTrace();
-			System.exit( 3 );
-			return;
-		}
-	}
-
-	/**
-	 * Constructs the Etch2 parser / compiler driver.
-	 * @deprecated
-	 */
-	@Deprecated
-	public Etch2()
-	{
-		// Default options
-		ignoreGlobal = false;
-		ignoreLocal = false;
-		ignoreEnvIncludePath = false;
-
-		includePath = new LinkedList<File>();
-		logHandler = new CompilerLogHandler( "Command" );
-		
-		logHandler.setQuiet( false );
-	}
-
-//	/**
-//	 * Print an informative message to standard out unless running in quiet
-//	 * mode.
-//	 * @param fmt the format of the message
-//	 * @param args the contents of the message
-//	 */
-//	private void report( String fmt, Object ... args )
-//	{
-//		if (!quiet)
-//			System.out.printf( "Etch: %s\n", String.format( fmt, args ) );
-//	}
-
-
-//	/**
-//	 * Print an informative message to standard error unless running in quiet
-//	 * mode.
-//	 * @param fmt the format of the message
-//	 * @param args the contents of the message
-//	 */
-//	private void error( String fmt, Object ... args )
-//	{
-//		System.err.printf( "Etch: %s\n", String.format( fmt, args ) );
-//	}
-	
-	@Override
-	public String toString()
-	{
-		return "etch";
-	}
-
-	@Override
-	protected void defineOptionsAndParameters( CommandParser cp )
-		throws Exception
-	{
-		cp.defineFileOption( "-d|--output-dir", "outputDir", "setOutputDir",
-			"specifies the output directory",
-			Option.SINGLETON, null, null );
-
-		cp.defineStringOption( "-b|--binding", "binding", "setBinding",
-			"specifies a target language binding to generate",
-			Option.REQUIRED|Option.SINGLETON, null, null );
-
-		cp.defineStringOption( "-w|--what|--who", "what", "setWhat",
-			"specifies what files to generate (--who is deprecated)",
-			Option.SINGLETON, "BOTH", null );
-
-		cp.defineNullOption( "-g|--ignore-global", "ignoreGlobalWordsList",
-			"ignore the global reserved words list",
-			Option.SINGLETON );
-
-		cp.defineNullOption( "-l|--ignore-local", "ignoreLocalWordsList",
-			"ignore the local reserved words list",
-			Option.SINGLETON );
-
-		cp.defineFileOption( "-W|--word-list", "wordList", "setUserWordsList",
-			"the file name of a reserved words list",
-			Option.SINGLETON, null, null );
-
-		cp.defineStringOption( "-I|--include-path", "includePath", "setIncludePath",
-			"a search directory for included etch files",
-			Option.NONE, null, null );
-
-		cp.defineNullOption( "-i|--ignore-include-path", "ignoreEnvIncludePath",
-			"ignore the include path environment variable",
-			Option.SINGLETON );
-		
-		cp.defineFileOption( "-m|--dir-mixin", "mixinOutputDir", "setMixinOutputDir",
-			"the output dir for mixin artifacts",
-			Option.SINGLETON, null, null );
-		
-		cp.defineNullOption( "-n|--no-mixin-artifacts", "setNoMixinArtifacts",
-			"mixin artifacts should not be generated",
-			Option.SINGLETON );
-
-		cp.defineNullOption( "-q|--quiet", "setQuiet",
-			"only report problems",
-			Option.SINGLETON );
-
-		cp.defineNullOption( "-v|--version", "doVersion",
-			"show the version and exit",
-			Option.SINGLETON );
-		
-		cp.defineNullOption( "-f|--no-flatten", "setNoFlattenPackages",
-			"the namespace directory tree should not be flattened",
-			Option.SINGLETON );
-
-		cp.defineFileParameter( "file", "doCompile",
-			"Etch source to compile", true, true, null );
-	}
-
-	/**
-	 * Command parser method to set the output directory.
-	 * @param cp
-	 * @param option
-	 * @param token
-	 * @param value the output directory
-	 * @return true if it worked, false otherwise.
-	 */
-	public boolean setOutputDir( CommandParser cp, Option option, String token,
-		File value )
-	{
-		if (value.exists() && (!value.isDirectory() || !value.canWrite()))
-		{
-			String msg = String.format("output directory %s is not a directory or not writable.", value);
-		//	error( "output directory %s is not found or not writable.", value );
-			logHandler.logMessage( LogHandler.LEVEL_ERROR, null, msg );
-			return false;
-		}
-		outputDir = value;
-		return true;
-	}
-
-	private File outputDir;
-
-	/**
-	 * Command parser method to set the binding.
-	 * @param cp
-	 * @param option
-	 * @param token
-	 * @param value the binding
-	 * @return true if it worked, false otherwise.
-	 */
-	public boolean setBinding( CommandParser cp, Option option, String token,
-		String value )
-	{
-		try
-		{
-			binding = Class.forName( String.format(
-				"etch.bindings.%s.compiler.Compiler", value ) );
-			return true;
-		}
-		catch ( ClassNotFoundException e )
-		{
-			String msg = String.format("binding %s is not found.", value);
-			logHandler.logMessage( LogHandler.LEVEL_ERROR, null, msg );
-			return false;
-		}
-	}
-
-	private Class<?> binding;
-
-	/**
-	 * Command parser method to set for whom/what we are generating code.
-	 * @param cp
-	 * @param option
-	 * @param token
-	 * @param value the list of what needs to be generated.
-	 * @return true if it worked, false otherwise.
-	 */
-	public boolean setWhat( CommandParser cp, Option option, String token,
-		String value )
-	{
-		try
-		{
-			StringTokenizer st = new StringTokenizer(value,WHO_DELIMETER);
-			while (st.hasMoreElements()) {
-				what.add(st.nextToken().toUpperCase());
-			}
-			return true;
-		}
-		catch ( Exception e )
-		{
-			String msg = String.format("what %s is not known.", value);
-			logHandler.logMessage( LogHandler.LEVEL_ERROR, null, msg );
-			return false;
-		}
-	}
-
-	private Set<String> what = new HashSet<String>();
-
-	/**
-	 * Command parser method to ignore the globally reserved words list.
-	 * @param cp
-	 * @param option
-	 * @param token
-	 */
-	public void ignoreGlobalWordsList(CommandParser cp, Option option, String token)
-	{
-		ignoreGlobal = true;
-	}
-
-	private boolean ignoreGlobal;
-
-	/**
-	 * Command parser method to ignore the locally reserved words list.
-	 * @param cp
-	 * @param option
-	 * @param token
-	 */
-	public void ignoreLocalWordsList(CommandParser cp, Option option, String token)
-	{
-		ignoreLocal = true;
-	}
-
-	private  boolean ignoreLocal;
-
-	/**
-	 * Command parser method to set the user-defined reserved words list.
-	 * @param cp
-	 * @param option
-	 * @param token
-	 * @param value the reserved words list
-	 * @return true if it worked, false otherwise.
-	 */
-	public boolean setUserWordsList(CommandParser cp, Option option, String token,
-		File value)
-	{
-		if (!value.isFile() || !value.canRead())
-		{
-			String msg = String.format("word list %s is not found or not readable.", value);
-			logHandler.logMessage( LogHandler.LEVEL_ERROR, null, msg );
-			return false;
-		}
-		userWordsList = value.getPath();
-		return true;
-	}
-
-	private String userWordsList;
-
-	/**
-	 * Command parser method to set the include path.
-	 * @param cp
-	 * @param option
-	 * @param token
-	 * @param value path to append to the current include path
-	 */
-	public void setIncludePath( CommandParser cp, Option option, String token,
-		String value )
-	{
-		StringTokenizer includeTokens = new StringTokenizer(value,
-			File.pathSeparator);
-
-		while(includeTokens.hasMoreTokens())
-		{
-			File temp = new File(includeTokens.nextToken());
-			if (temp.exists() && temp.isDirectory())
-				includePath.add(temp);
-		}
-	}
-
-	private List<File> includePath;
-
-	/**
-	 * Command parser method to ignore the include path from the environment.
-	 * @param cp
-	 * @param option
-	 * @param token
-	 */
-	public void ignoreEnvIncludePath(CommandParser cp, Option option,
-		String token)
-	{
-		ignoreEnvIncludePath = true;
-	}
-
-	private boolean ignoreEnvIncludePath;
-
-	/**
-	 * Command parser method to set the quiet flag.
-	 * @param cp
-	 * @param option
-	 * @param token
-	 */
-	public void setQuiet( CommandParser cp, Option option, String token )
-	{
-//		quiet = true;
-		logHandler.setQuiet( true );
-	}
-
-	// TODO quiet needs to be included in the options and log handler should respect it.
-//	@SuppressWarnings("unused")
-//	private boolean quiet;
-
-	/**
-	 * Command parser method to show the version and exit.
-	 * @param cp
-	 * @param option
-	 * @param token
-	 * @return false so that we stop.
-	 */
-	public boolean doVersion( CommandParser cp, Option option, String token )
-	{
-		logHandler.logMessage( LogHandler.LEVEL_MESSAGE, null,
-			String.format( "Version is %s.", Version.VERSION ) );
-		return false;
-	}
-	
-	/**
-	 * Command parser method to suppress mixin artifacts.
-	 * @param cp
-	 * @param option
-	 * @param token
-	 */
-	public void setNoMixinArtifacts( CommandParser cp, Option option, String token )
-	{
-		noMixinArtifacts = true;
-	}
-
-	private boolean noMixinArtifacts = false;
-	
-	/**
-	 * Command parser method to set the output directory for mixins.
-	 * @param cp
-	 * @param option
-	 * @param token
-	 * @param value the output directory for mixin
-	 * @return true if it worked, false otherwise.
-	 */
-	public boolean setMixinOutputDir( CommandParser cp, Option option, String token,
-		File value )
-	{
-		if (!value.isDirectory() || !value.canWrite())
-		{
-			String msg = String.format(" Mixin Output Directory %s is not found or not writable.", value);
-		//	error( "output directory %s is not found or not writable.", value );
-			logHandler.logMessage( LogHandler.LEVEL_ERROR, null, msg );
-			return false;
-		}
-		mixinOutputDir = value;
-		return true;
-	}
-
-	private File mixinOutputDir;
-	
-	/**
-	 * @param cp
-	 * @param option
-	 * @param token
-	 */
-	public void setNoFlattenPackages( CommandParser cp, Option option, String token)
-	{
-		flattenPackages = false;
-	}
-	
-	private boolean flattenPackages = true;
-
-	/**
-	 * Command parser method to compile a file.
-	 * @param cp
-	 * @param param
-	 * @param value
-	 * @return true if it worked, false otherwise.
-	 */
-	public boolean doCompile( CommandParser cp, Parameter param, File value )
-	{
-		logHandler.push( value.getName(),null );
-		if (!value.isFile() || !value.canRead())
-		{
-			String msg = String.format("file %s is not found or not readable.", value);
-			logHandler.logMessage( LogHandler.LEVEL_ERROR, null, msg );
-			return false;
-		}
-
-		String s = value.getName();
-		if (!s.endsWith( ".etch" ))
-		{
-			String msg = String.format("file %s is not etch source (its name doesn't end in .etch).", value);
-			logHandler.logMessage( LogHandler.LEVEL_ERROR,null, msg );
-			return false;
-		}
-
-		InputStream is;
-		try
-		{
-			is = new java.io.FileInputStream( value );
-		}
-		catch ( FileNotFoundException e1 )
-		{
-			e1.printStackTrace();
-			String msg = String.format("file %s could not be opened.", value);
-			logHandler.logMessage( LogHandler.LEVEL_ERROR, null, msg );
-			return false;
-		}
-		
-		logHandler.setPhase( "Parsing" );
-
-		if (outputDir != null) {
-			String msg = String.format(" Compiling to %s ...\n", outputDir);
-			logHandler.logMessage( LogHandler.LEVEL_INFO, null, msg );
-		}
-		else
-			logHandler.logMessage( LogHandler.LEVEL_INFO, null, " Compiling.." );
-
-		// Setup Etch include path from the environment variable, command
-		// line options, and the working directory of the etch file itself.
-		String tempIncPathStr = System.getenv(ETCH_INCLUDE_PATH);
-		if (!ignoreEnvIncludePath && tempIncPathStr != null)
-		{
-			List<File> etchIncludePath = new LinkedList<File>();
-			StringTokenizer tempPath = new StringTokenizer(tempIncPathStr,
-				File.pathSeparator);
-
-			while (tempPath.hasMoreTokens())
-			{
-				File temp = new File(tempPath.nextToken());
-				if (temp.exists() && temp.isDirectory())
-					etchIncludePath.add(temp);
-			}
-
-			etchIncludePath.addAll( includePath );
-			includePath = etchIncludePath;
-		}
-
-		// Directory of etch file comes first.
-		if (value.getParentFile() != null) {
-			includePath.add(0, value.getParentFile());
-		}
-		else {
-			includePath.add( 0, value.getAbsoluteFile().getParentFile());
-		}
-
-		// Construct the Command Line Options
-		CmdLineOptions cmdOptions = new CmdLineOptions();
-		cmdOptions.bindingClass = binding;
-		cmdOptions.what = what;
-		cmdOptions.outputDir = outputDir;
-		cmdOptions.ignoreGlobal = ignoreGlobal;
-		cmdOptions.ignoreLocal = ignoreLocal;
-		cmdOptions.userWordsList = userWordsList;
-		cmdOptions.includePath = includePath;
-		cmdOptions.mixinOutputDir = mixinOutputDir;
-		cmdOptions.noMixinArtifacts = noMixinArtifacts;
-		cmdOptions.noFlattenPackages = !flattenPackages;
-		doCompile(cmdOptions,is,logHandler);
-		logHandler.pop();
-		if (logHandler.hasError())
-			return false;
-		
-		return true;
-	}
-
-	/**
-	 * Compile etch source based on command line options.
-	 * @param cl the user-defined options
-	 * @param is
-	 * @param lh
-	 * @return the generated Module abstract syntax tree.
-	 */
-	public static Module doCompile(CmdLineOptions cl, InputStream is, LogHandler lh)
-	{
-		cl.lh = lh;
-		
-//		EtchHelper.cl = cl;
-
-		if (!initBindingClass( cl, lh ))
-			return null;
-
-		final Backend b = getBinding( cl, lh );
-		if (b == null)
-			return null;
-		
-		final EtchGrammar parser = new EtchGrammar( b, is );
-
-		final Module m;
-
-		try
-		{
-			m = parser.module( cl );
-
-			lh.logMessage( LogHandler.LEVEL_INFO,null,"Parsed OK. \n" );
-
-			m.check();
-
-			lh.logMessage( LogHandler.LEVEL_INFO,null," Checked OK. \n" );
-		}
-		catch ( ParseException e )
-		{
-
-			String fmt =  e.getMessage();
-			lh.logMessage( LogHandler.LEVEL_ERROR, e.currentToken,fmt );
-	//		System.exit( 2 );
-			return null;
-		}
-		catch ( Exception e )
-		{
-			String fmt =  e.getMessage();
-			lh.logMessage( LogHandler.LEVEL_ERROR, null,fmt );
-			e.printStackTrace();
-	//		System.exit( 3 );
-			return null;
-		}
-		
-		// handling of Mixin output Directory
-		
-		if (cl.isMixinPresent) {
-			if (cl.mixinOutputDir != null) {
-				cl.outputDir = cl.mixinOutputDir;
-			}
-		}
-	
-		try
-		{
-			// TODO report word lists too?
-			lh.logMessage( LogHandler.LEVEL_INFO,null,  " Generating Resources... \n" );
-
-			// TODO integrate includePath with code generation.
-			b.generate( m, cl, lh );
-		}
-		catch ( Exception e )
-		{
-			String fmt =  e.getMessage();
-			lh.logMessage( LogHandler.LEVEL_ERROR, null, fmt );
-//			e.printStackTrace( System.err );
+///* $Id$
+// *
+// * Copyright 2007-2008 Cisco Systems Inc.
+// *
+// * 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 etch.compiler;
+//
+//import java.io.File;
+//import java.io.FileNotFoundException;
+//import java.io.InputStream;
+//import java.util.HashSet;
+//import java.util.LinkedList;
+//import java.util.List;
+//import java.util.Set;
+//import java.util.StringTokenizer;
+//
+//import etch.compiler.ast.Module;
+//import etch.util.cmd.CommandParser;
+//import etch.util.cmd.Option;
+//import etch.util.cmd.Parameter;
+//import etch.util.cmd.Program;
+//
+//
+///**
+// * The main command line interface for the etch compiler.
+// * @deprecated
+// */
+//@Deprecated
+//public class Etch2 extends Program
+//{
+//	private static String WHO_DELIMETER = ",";
+//
+//	private LogHandler logHandler;
+//
+//	/**
+//	 * @param args
+//	 * @deprecated
+//	 */
+//	@Deprecated
+//	public static void main( String[] args )
+//	{
+//		try
+//		{
+//			main( new Etch2(), args );
+//		}
+//		catch ( Throwable e )
+//		{
+//			// TODO can we be more descriptive here?
+//			e.printStackTrace();
 //			System.exit( 3 );
-			return null;
-		}
-
-		lh.logMessage( LogHandler.LEVEL_INFO,null, " Generation Done... \n" );
-		return m;
-	}
-
-	private static Backend getBinding( CmdLineOptions cl, LogHandler lh )
-	{
-		try
-		{
-			return (Backend) cl.bindingClass.newInstance();
-		}
-		catch ( Exception e )
-		{
-			String fmt =  e.getMessage();
-			lh.logMessage( LogHandler.LEVEL_ERROR, null, fmt );
-			e.printStackTrace( System.err );
-	//		System.exit( 3 );
-			return null;
-		}
-	}
-
-	private static boolean initBindingClass( CmdLineOptions cl, LogHandler lh )
-	{
-		if (cl.bindingClass != null)
-			return true;
-
-		try
-		{
-			cl.bindingClass = Class.forName( String.format(
-				"etch.bindings.%s.compiler.Compiler", cl.binding ) );
-			return true;
-		}
-		catch ( ClassNotFoundException e )
-		{
-			String fmt = "Binding  " + cl.binding + " is not supported \n";
-			lh.logMessage( LogHandler.LEVEL_ERROR, null, fmt );
-			// e.printStackTrace();
-			return false;
-		}
-		catch ( Exception ex )
-		{
-			String fmt = ex.getMessage();
-			lh.logMessage( LogHandler.LEVEL_ERROR, null, fmt );
-			ex.printStackTrace( System.err );
-			return false;
-		}
-	}
-
-	@Override
-	protected void run() throws Exception
-	{
-		// nothing to do...
-	}
-}
+//			return;
+//		}
+//	}
+//
+//	/**
+//	 * Constructs the Etch2 parser / compiler driver.
+//	 * @deprecated
+//	 */
+//	@Deprecated
+//	public Etch2()
+//	{
+//		// Default options
+//		ignoreGlobal = false;
+//		ignoreLocal = false;
+//		ignoreEnvIncludePath = false;
+//
+//		includePath = new LinkedList<File>();
+//		logHandler = new CompilerLogHandler( "Command" );
+//		
+//		logHandler.setQuiet( false );
+//	}
+//
+////	/**
+////	 * Print an informative message to standard out unless running in quiet
+////	 * mode.
+////	 * @param fmt the format of the message
+////	 * @param args the contents of the message
+////	 */
+////	private void report( String fmt, Object ... args )
+////	{
+////		if (!quiet)
+////			System.out.printf( "Etch: %s\n", String.format( fmt, args ) );
+////	}
+//
+//
+////	/**
+////	 * Print an informative message to standard error unless running in quiet
+////	 * mode.
+////	 * @param fmt the format of the message
+////	 * @param args the contents of the message
+////	 */
+////	private void error( String fmt, Object ... args )
+////	{
+////		System.err.printf( "Etch: %s\n", String.format( fmt, args ) );
+////	}
+//	
+//	@Override
+//	public String toString()
+//	{
+//		return "etch";
+//	}
+//
+//	@Override
+//	protected void defineOptionsAndParameters( CommandParser cp )
+//		throws Exception
+//	{
+//		cp.defineFileOption( "-d|--output-dir", "outputDir", "setOutputDir",
+//			"specifies the output directory",
+//			Option.SINGLETON, null, null );
+//
+//		cp.defineStringOption( "-b|--binding", "binding", "setBinding",
+//			"specifies a target language binding to generate",
+//			Option.REQUIRED|Option.SINGLETON, null, null );
+//
+//		cp.defineStringOption( "-w|--what|--who", "what", "setWhat",
+//			"specifies what files to generate (--who is deprecated)",
+//			Option.SINGLETON, "BOTH", null );
+//
+//		cp.defineNullOption( "-g|--ignore-global", "ignoreGlobalWordsList",
+//			"ignore the global reserved words list",
+//			Option.SINGLETON );
+//
+//		cp.defineNullOption( "-l|--ignore-local", "ignoreLocalWordsList",
+//			"ignore the local reserved words list",
+//			Option.SINGLETON );
+//
+//		cp.defineFileOption( "-W|--word-list", "wordList", "setUserWordsList",
+//			"the file name of a reserved words list",
+//			Option.SINGLETON, null, null );
+//
+//		cp.defineStringOption( "-I|--include-path", "includePath", "setIncludePath",
+//			"a search directory for included etch files",
+//			Option.NONE, null, null );
+//
+//		cp.defineNullOption( "-i|--ignore-include-path", "ignoreEnvIncludePath",
+//			"ignore the include path environment variable",
+//			Option.SINGLETON );
+//		
+//		cp.defineFileOption( "-m|--dir-mixin", "mixinOutputDir", "setMixinOutputDir",
+//			"the output dir for mixin artifacts",
+//			Option.SINGLETON, null, null );
+//		
+//		cp.defineNullOption( "-n|--no-mixin-artifacts", "setNoMixinArtifacts",
+//			"mixin artifacts should not be generated",
+//			Option.SINGLETON );
+//
+//		cp.defineNullOption( "-q|--quiet", "setQuiet",
+//			"only report problems",
+//			Option.SINGLETON );
+//
+//		cp.defineNullOption( "-v|--version", "doVersion",
+//			"show the version and exit",
+//			Option.SINGLETON );
+//		
+//		cp.defineNullOption( "-f|--no-flatten", "setNoFlattenPackages",
+//			"the namespace directory tree should not be flattened",
+//			Option.SINGLETON );
+//
+//		cp.defineFileParameter( "file", "doCompile",
+//			"Etch source to compile", true, true, null );
+//	}
+//
+//	/**
+//	 * Command parser method to set the output directory.
+//	 * @param cp
+//	 * @param option
+//	 * @param token
+//	 * @param value the output directory
+//	 * @return true if it worked, false otherwise.
+//	 */
+//	public boolean setOutputDir( CommandParser cp, Option option, String token,
+//		File value )
+//	{
+//		if (value.exists() && (!value.isDirectory() || !value.canWrite()))
+//		{
+//			String msg = String.format("output directory %s is not a directory or not writable.", value);
+//		//	error( "output directory %s is not found or not writable.", value );
+//			logHandler.logMessage( LogHandler.LEVEL_ERROR, null, msg );
+//			return false;
+//		}
+//		outputDir = value;
+//		return true;
+//	}
+//
+//	private File outputDir;
+//
+//	/**
+//	 * Command parser method to set the binding.
+//	 * @param cp
+//	 * @param option
+//	 * @param token
+//	 * @param value the binding
+//	 * @return true if it worked, false otherwise.
+//	 */
+//	public boolean setBinding( CommandParser cp, Option option, String token,
+//		String value )
+//	{
+//		try
+//		{
+//			binding = Class.forName( String.format(
+//				"etch.bindings.%s.compiler.Compiler", value ) );
+//			return true;
+//		}
+//		catch ( ClassNotFoundException e )
+//		{
+//			String msg = String.format("binding %s is not found.", value);
+//			logHandler.logMessage( LogHandler.LEVEL_ERROR, null, msg );
+//			return false;
+//		}
+//	}
+//
+//	private Class<?> binding;
+//
+//	/**
+//	 * Command parser method to set for whom/what we are generating code.
+//	 * @param cp
+//	 * @param option
+//	 * @param token
+//	 * @param value the list of what needs to be generated.
+//	 * @return true if it worked, false otherwise.
+//	 */
+//	public boolean setWhat( CommandParser cp, Option option, String token,
+//		String value )
+//	{
+//		try
+//		{
+//			StringTokenizer st = new StringTokenizer(value,WHO_DELIMETER);
+//			while (st.hasMoreElements()) {
+//				what.add(st.nextToken().toUpperCase());
+//			}
+//			return true;
+//		}
+//		catch ( Exception e )
+//		{
+//			String msg = String.format("what %s is not known.", value);
+//			logHandler.logMessage( LogHandler.LEVEL_ERROR, null, msg );
+//			return false;
+//		}
+//	}
+//
+//	private Set<String> what = new HashSet<String>();
+//
+//	/**
+//	 * Command parser method to ignore the globally reserved words list.
+//	 * @param cp
+//	 * @param option
+//	 * @param token
+//	 */
+//	public void ignoreGlobalWordsList(CommandParser cp, Option option, String token)
+//	{
+//		ignoreGlobal = true;
+//	}
+//
+//	private boolean ignoreGlobal;
+//
+//	/**
+//	 * Command parser method to ignore the locally reserved words list.
+//	 * @param cp
+//	 * @param option
+//	 * @param token
+//	 */
+//	public void ignoreLocalWordsList(CommandParser cp, Option option, String token)
+//	{
+//		ignoreLocal = true;
+//	}
+//
+//	private  boolean ignoreLocal;
+//
+//	/**
+//	 * Command parser method to set the user-defined reserved words list.
+//	 * @param cp
+//	 * @param option
+//	 * @param token
+//	 * @param value the reserved words list
+//	 * @return true if it worked, false otherwise.
+//	 */
+//	public boolean setUserWordsList(CommandParser cp, Option option, String token,
+//		File value)
+//	{
+//		if (!value.isFile() || !value.canRead())
+//		{
+//			String msg = String.format("word list %s is not found or not readable.", value);
+//			logHandler.logMessage( LogHandler.LEVEL_ERROR, null, msg );
+//			return false;
+//		}
+//		userWordsList = value.getPath();
+//		return true;
+//	}
+//
+//	private String userWordsList;
+//
+//	/**
+//	 * Command parser method to set the include path.
+//	 * @param cp
+//	 * @param option
+//	 * @param token
+//	 * @param value path to append to the current include path
+//	 */
+//	public void setIncludePath( CommandParser cp, Option option, String token,
+//		String value )
+//	{
+//		StringTokenizer includeTokens = new StringTokenizer(value,
+//			File.pathSeparator);
+//
+//		while(includeTokens.hasMoreTokens())
+//		{
+//			File temp = new File(includeTokens.nextToken());
+//			if (temp.exists() && temp.isDirectory())
+//				includePath.add(temp);
+//		}
+//	}
+//
+//	private List<File> includePath;
+//
+//	/**
+//	 * Command parser method to ignore the include path from the environment.
+//	 * @param cp
+//	 * @param option
+//	 * @param token
+//	 */
+//	public void ignoreEnvIncludePath(CommandParser cp, Option option,
+//		String token)
+//	{
+//		ignoreEnvIncludePath = true;
+//	}
+//
+//	private boolean ignoreEnvIncludePath;
+//
+//	/**
+//	 * Command parser method to set the quiet flag.
+//	 * @param cp
+//	 * @param option
+//	 * @param token
+//	 */
+//	public void setQuiet( CommandParser cp, Option option, String token )
+//	{
+////		quiet = true;
+//		logHandler.setQuiet( true );
+//	}
+//
+//	// TODO quiet needs to be included in the options and log handler should respect it.
+////	@SuppressWarnings("unused")
+////	private boolean quiet;
+//
+//	/**
+//	 * Command parser method to show the version and exit.
+//	 * @param cp
+//	 * @param option
+//	 * @param token
+//	 * @return false so that we stop.
+//	 */
+//	public boolean doVersion( CommandParser cp, Option option, String token )
+//	{
+//		logHandler.logMessage( LogHandler.LEVEL_MESSAGE, null,
+//			String.format( "Version is %s.", Version.VERSION ) );
+//		return false;
+//	}
+//	
+//	/**
+//	 * Command parser method to suppress mixin artifacts.
+//	 * @param cp
+//	 * @param option
+//	 * @param token
+//	 */
+//	public void setNoMixinArtifacts( CommandParser cp, Option option, String token )
+//	{
+//		noMixinArtifacts = true;
+//	}
+//
+//	private boolean noMixinArtifacts = false;
+//	
+//	/**
+//	 * Command parser method to set the output directory for mixins.
+//	 * @param cp
+//	 * @param option
+//	 * @param token
+//	 * @param value the output directory for mixin
+//	 * @return true if it worked, false otherwise.
+//	 */
+//	public boolean setMixinOutputDir( CommandParser cp, Option option, String token,
+//		File value )
+//	{
+//		if (!value.isDirectory() || !value.canWrite())
+//		{
+//			String msg = String.format(" Mixin Output Directory %s is not found or not writable.", value);
+//		//	error( "output directory %s is not found or not writable.", value );
+//			logHandler.logMessage( LogHandler.LEVEL_ERROR, null, msg );
+//			return false;
+//		}
+//		mixinOutputDir = value;
+//		return true;
+//	}
+//
+//	private File mixinOutputDir;
+//	
+//	/**
+//	 * @param cp
+//	 * @param option
+//	 * @param token
+//	 */
+//	public void setNoFlattenPackages( CommandParser cp, Option option, String token)
+//	{
+//		flattenPackages = false;
+//	}
+//	
+//	private boolean flattenPackages = true;
+//
+//	/**
+//	 * Command parser method to compile a file.
+//	 * @param cp
+//	 * @param param
+//	 * @param value
+//	 * @return true if it worked, false otherwise.
+//	 */
+//	public boolean doCompile( CommandParser cp, Parameter param, File value )
+//	{
+//		logHandler.push( value.getName(),null );
+//		if (!value.isFile() || !value.canRead())
+//		{
+//			String msg = String.format("file %s is not found or not readable.", value);
+//			logHandler.logMessage( LogHandler.LEVEL_ERROR, null, msg );
+//			return false;
+//		}
+//
+//		String s = value.getName();
+//		if (!s.endsWith( ".etch" ))
+//		{
+//			String msg = String.format("file %s is not etch source (its name doesn't end in .etch).", value);
+//			logHandler.logMessage( LogHandler.LEVEL_ERROR,null, msg );
+//			return false;
+//		}
+//
+//		InputStream is;
+//		try
+//		{
+//			is = new java.io.FileInputStream( value );
+//		}
+//		catch ( FileNotFoundException e1 )
+//		{
+//			e1.printStackTrace();
+//			String msg = String.format("file %s could not be opened.", value);
+//			logHandler.logMessage( LogHandler.LEVEL_ERROR, null, msg );
+//			return false;
+//		}
+//		
+//		logHandler.setPhase( "Parsing" );
+//
+//		if (outputDir != null) {
+//			String msg = String.format(" Compiling to %s ...\n", outputDir);
+//			logHandler.logMessage( LogHandler.LEVEL_INFO, null, msg );
+//		}
+//		else
+//			logHandler.logMessage( LogHandler.LEVEL_INFO, null, " Compiling.." );
+//
+//		// Setup Etch include path from the environment variable, command
+//		// line options, and the working directory of the etch file itself.
+//		String tempIncPathStr = System.getenv(ETCH_INCLUDE_PATH);
+//		if (!ignoreEnvIncludePath && tempIncPathStr != null)
+//		{
+//			List<File> etchIncludePath = new LinkedList<File>();
+//			StringTokenizer tempPath = new StringTokenizer(tempIncPathStr,
+//				File.pathSeparator);
+//
+//			while (tempPath.hasMoreTokens())
+//			{
+//				File temp = new File(tempPath.nextToken());
+//				if (temp.exists() && temp.isDirectory())
+//					etchIncludePath.add(temp);
+//			}
+//
+//			etchIncludePath.addAll( includePath );
+//			includePath = etchIncludePath;
+//		}
+//
+//		// Directory of etch file comes first.
+//		if (value.getParentFile() != null) {
+//			includePath.add(0, value.getParentFile());
+//		}
+//		else {
+//			includePath.add( 0, value.getAbsoluteFile().getParentFile());
+//		}
+//
+//		// Construct the Command Line Options
+//		CmdLineOptions cmdOptions = new CmdLineOptions();
+//		cmdOptions.bindingClass = binding;
+//		cmdOptions.what = what;
+//		cmdOptions.outputDir = outputDir;
+//		cmdOptions.ignoreGlobal = ignoreGlobal;
+//		cmdOptions.ignoreLocal = ignoreLocal;
+//		cmdOptions.userWordsList = userWordsList;
+//		cmdOptions.includePath = includePath;
+//		cmdOptions.mixinOutputDir = mixinOutputDir;
+//		cmdOptions.noMixinArtifacts = noMixinArtifacts;
+//		cmdOptions.noFlattenPackages = !flattenPackages;
+//		doCompile(cmdOptions,is,logHandler);
+//		logHandler.pop();
+//		if (logHandler.hasError())
+//			return false;
+//		
+//		return true;
+//	}
+//
+//	/**
+//	 * Compile etch source based on command line options.
+//	 * @param cl the user-defined options
+//	 * @param is
+//	 * @param lh
+//	 * @return the generated Module abstract syntax tree.
+//	 */
+//	public static Module doCompile(CmdLineOptions cl, InputStream is, LogHandler lh)
+//	{
+//		cl.lh = lh;
+//		
+////		EtchHelper.cl = cl;
+//
+//		if (!initBindingClass( cl, lh ))
+//			return null;
+//
+//		final Backend b = getBinding( cl, lh );
+//		if (b == null)
+//			return null;
+//		
+//		final EtchGrammar parser = new EtchGrammar( b, is );
+//
+//		final Module m;
+//
+//		try
+//		{
+//			m = parser.module( cl );
+//
+//			lh.logMessage( LogHandler.LEVEL_INFO,null,"Parsed OK. \n" );
+//
+//			m.check();
+//
+//			lh.logMessage( LogHandler.LEVEL_INFO,null," Checked OK. \n" );
+//		}
+//		catch ( ParseException e )
+//		{
+//
+//			String fmt =  e.getMessage();
+//			lh.logMessage( LogHandler.LEVEL_ERROR, e.currentToken,fmt );
+//	//		System.exit( 2 );
+//			return null;
+//		}
+//		catch ( Exception e )
+//		{
+//			String fmt =  e.getMessage();
+//			lh.logMessage( LogHandler.LEVEL_ERROR, null,fmt );
+//			e.printStackTrace();
+//	//		System.exit( 3 );
+//			return null;
+//		}
+//		
+//		// handling of Mixin output Directory
+//		
+//		if (cl.isMixinPresent) {
+//			if (cl.mixinOutputDir != null) {
+//				cl.outputDir = cl.mixinOutputDir;
+//			}
+//		}
+//	
+//		try
+//		{
+//			// TODO report word lists too?
+//			lh.logMessage( LogHandler.LEVEL_INFO,null,  " Generating Resources... \n" );
+//
+//			// TODO integrate includePath with code generation.
+//			b.generate( m, cl, lh );
+//		}
+//		catch ( Exception e )
+//		{
+//			String fmt =  e.getMessage();
+//			lh.logMessage( LogHandler.LEVEL_ERROR, null, fmt );
+////			e.printStackTrace( System.err );
+////			System.exit( 3 );
+//			return null;
+//		}
+//
+//		lh.logMessage( LogHandler.LEVEL_INFO,null, " Generation Done... \n" );
+//		return m;
+//	}
+//
+//	private static Backend getBinding( CmdLineOptions cl, LogHandler lh )
+//	{
+//		try
+//		{
+//			return (Backend) cl.bindingClass.newInstance();
+//		}
+//		catch ( Exception e )
+//		{
+//			String fmt =  e.getMessage();
+//			lh.logMessage( LogHandler.LEVEL_ERROR, null, fmt );
+//			e.printStackTrace( System.err );
+//	//		System.exit( 3 );
+//			return null;
+//		}
+//	}
+//
+//	private static boolean initBindingClass( CmdLineOptions cl, LogHandler lh )
+//	{
+//		if (cl.bindingClass != null)
+//			return true;
+//
+//		try
+//		{
+//			cl.bindingClass = Class.forName( String.format(
+//				"etch.bindings.%s.compiler.Compiler", cl.binding ) );
+//			return true;
+//		}
+//		catch ( ClassNotFoundException e )
+//		{
+//			String fmt = "Binding  " + cl.binding + " is not supported \n";
+//			lh.logMessage( LogHandler.LEVEL_ERROR, null, fmt );
+//			// e.printStackTrace();
+//			return false;
+//		}
+//		catch ( Exception ex )
+//		{
+//			String fmt = ex.getMessage();
+//			lh.logMessage( LogHandler.LEVEL_ERROR, null, fmt );
+//			ex.printStackTrace( System.err );
+//			return false;
+//		}
+//	}
+//
+//	@Override
+//	protected void run() throws Exception
+//	{
+//		// nothing to do...
+//	}
+//}