Пример #1
0
		protected static bool Apply( ref Tflag flags, Opcode code )
		{
			if( code.Kind() == Opkind.Access )
			{
				if( code == Opcode.Internal )
				{
					flags |= Tflag.Internal;
				}
				else
				{
					flags = ((Tflag)(unchecked((byte)code) & 3)) | (flags & (~((Tflag)3)));
				}
				return true;
			}
			if( code.Kind() == Opkind.Scope )
			{
				if( ((code == Opcode.Readonly) && (flags.Scope() == Tflag.Static)) || ((code == Opcode.Static) && (flags.Scope() == Tflag.Readonly)) )
				{
					flags = Tflag.Rostatic | (flags & (~Tflag.Scope));
				}
				else
				{
					flags = ((Tflag)((unchecked((byte)code) & 7) << 4)) | (flags & (~Tflag.Scope));
				}
				return true;
			}
			if( code == Opcode.Partial )
			{
				flags |= Tflag.Partial;
				return true;
			}
			if( code == Opcode.Unsafe )
			{
				flags |= Tflag.Unsafe;
				return true;
			}
			return false;
		}//Apply
Пример #2
0
		}//Apply
		
		protected virtual bool Classes( Flag flags, Tflag lflags = Tflag.None )
		{
			if( (Word == null) || (Indent < Pindent) )
			{
				return false;
			}
			var one = (flags & Flag.Single) != 0;
			flags &= ~Flag.Single;
			var was = false;
			var ppind = Pindent;
			int saveAt;
			do
			{
				saveAt = At;
				Pindent = Indent;
				var name = Word;
				var type = Opcode.Undef;
				var tflags = lflags;
				if( (((unchecked((byte)Opcode) == unchecked((byte)Opcode.Class)) || (Opcode == Opcode.Face)) || (Opcode == Opcode.Struct)) || (Opcode == Opcode.Enum) )
				{
					type = Opcode;
					name = null;
				}
				else if( ((Opcode != Opcode.Const) && (Opcode != Opcode.Readonly)) && Apply( ref tflags, Opcode ) )
				{
					name = null;
				}
				else if( Opcode != Opcode.Ident )
				{
					break;
				}
				while( (Next( name == null ).Curr == ',') || ((Curr == ':') && (type != 0)) )
				{
				}
				if( Word == null )
				{
					if( (ppind >= 0) && (type != 0) )
					{
						throw new ParseError( this, "Expected word after '{0}'", name );
					}
					goto revert;
				}
				for( ; type == 0; Next( tflags != 0 ) )
				{
					if( Indent < Pindent )
					{
						throw new ParseError( this, "Wrong indentation" );
					}
					if( (Curr == ',') && (tflags != 0) )
					{
						continue;
					}
					if( (((Opcode == Opcode.Class) || (Opcode == Opcode.Face)) || (Opcode == Opcode.Struct)) || (Opcode == Opcode.Enum) )
					{
						type = Opcode;
						Next();
						break;
					}
					if( !Apply( ref tflags, Opcode ) )
					{
						if( tflags != 0 )
						{
							throw new ParseError( this, "Unexpected input in class declaration" );
						}
						goto revert;
					}
				}
				if( name == null )
				{
					while( (Eol || (Curr == ',')) || (Curr == ':') )
					{
						Next( true );
						if( Indent < Pindent )
						{
							throw new ParseError( this, "Wrong indentation" );
						}
					}
					if( Word == null )
					{
						throw new ParseError( this, "Unexpected input in class declaration" );
					}
					name = Word;
					Next();
				}
				var mark = Cgen.ClassStart( name );
				var bcnum = 0;
				for( var line = false; ; Next( line ) )
				{
					if( Indent < Pindent )
					{
						throw new ParseError( this, "Wrong indentation" );
					}
					if( (Curr == ',') || (Curr == ':') )
					{
						if( Eol && (Curr == ':') )
						{
							break;
						}
						line = true;
						continue;
					}
					line = false;
					if( !Apply( ref tflags, Opcode ) )
					{
						if( Word == null )
						{
							break;
						}
						if( (((Opcode == Opcode.Class) || (Opcode == Opcode.Face)) || (Opcode == Opcode.Struct)) || (Opcode == Opcode.Enum) )
						{
							if( ((type != 0) && (type != Opcode.Def)) && (type != Opcode.Define) )
							{
								throw new ParseError( this, "More than one class type" );
							}
							type = Opcode;
						}
						else
						{
							FullType( flags );
							bcnum++;
						}
					}
				}
				if( (type == Opcode.Def) || (type == Opcode.Define) )
				{
					type = Opcode.Class;
				}
				mark = Cgen.ClassBody( mark, name, type, 0, bcnum, tflags );
				Members( name, type, tflags, flags );
				Cgen.ClassEnd( mark, name );
			}
			while( (Indent > ppind) && (!one) );
			Pindent = ppind;
			return was;
		revert:
			Pindent = ppind;
			End = saveAt;
			Next();
			return was;
		}//Classes
Пример #3
0
		}//Classes
		
		protected virtual bool Members( string className, Opcode classType, Tflag classFlags, Flag flags )
		{
			if( !Eol )
			{
				throw new ParseError( this, "Unexpected input in class declaration" );
			}
			if( NextLine().Indent < Pindent )
			{
				return false;
			}
			if( classFlags.Scope() == Tflag.Static )
			{
				flags |= Flag.Static;
			}
			var one = (flags & Flag.Single) != 0;
			flags &= ~Flag.Single;
			var was = false;
			var ppind = Pindent;
			var lflags = Tflag.None;
			int saveAt;
			do
			{
				saveAt = At;
				Pindent = Indent;
				var tflags = Tflag.None;
				var isvar = false;
				while( Apply( ref tflags, Opcode ) )
				{
					if( (Opcode == Opcode.Readonly) || (Opcode == Opcode.Const) )
					{
						isvar = true;
					}
					Next( isvar );
				}
				if( !isvar )
				{
					if( Curr == ':' )
					{
						if( tflags == Tflag.None )
						{
							throw new ParseError( this, "Unexpected ':' in class body" );
						}
						Next();
						lflags = tflags;
						continue;
					}
					if( (((unchecked((byte)Opcode) == unchecked((byte)Opcode.Class)) || (Opcode == Opcode.Face)) || (Opcode == Opcode.Struct)) || (Opcode == Opcode.Enum) )
					{
						Pindent = ppind;
						if( At != saveAt )
						{
							End = saveAt;
							Next();
						}
						if( !Classes( flags, lflags ) )
						{
							throw new ParseError( this, "Expected class declaration" );
						}
						was = true;
						continue;
					}
				}
				if( tflags == Tflag.None )
				{
					tflags = lflags;
				}
				else
				{
					if( tflags.Access() == Tflag.None )
					{
						tflags = (tflags & (~Tflag.Access)) | lflags.Access();
					}
					if( tflags.Scope() == Tflag.None )
					{
						tflags = (tflags & (~Tflag.Scope)) | lflags.Scope();
					}
				}
				int mark;
				var name = Word;
				if( (isvar || (Opcode == Opcode.Var)) || (Opcode == Opcode.Event) )
				{
					var evt = (!isvar) && (Opcode == Opcode.Event);
					if( !isvar )
					{
						Next( true );
						while( Apply( ref tflags, Opcode ) )
						{
							Next( true );
						}
					}
					name = Word;
					if( name == null )
					{
						throw new ParseError( this, "Expected field name" );
					}
					mark = Cgen.FieldStart( name );
					Next();
					while( Apply( ref tflags, Opcode ) )
					{
						Next();
					}
					OptType( flags );
					OptExpr( flags );
					while( Apply( ref tflags, Opcode ) )
					{
						Next();
					}
					Cgen.FieldEnd( mark, name, evt ? Opcode.Event : Opcode.Field, tflags );
					if( !Eof )
					{
						if( !Eol )
						{
							throw new ParseError( this, "Unexpected input in class body" );
						}
						NextLine();
					}
				}
				else
				{
					if( Curr == '.' )
					{
						if( Next().Word == null )
						{
							throw new ParseError( this, "Unexpected 'ctor' or 'new' after '.'" );
						}
						name = "." + Word;
					}
					if( name == null )
					{
						throw new ParseError( this, "Unexpected input in class body" );
					}
					mark = Cgen.FuncStart( name );
					Next();
					while( Apply( ref tflags, Opcode ) )
					{
						Next();
					}
					OptType( flags );
					mark = Cgen.FuncTypeEnd( mark, name );
					while( Apply( ref tflags, Opcode ) )
					{
						Next();
					}
					var argc = 0;
					var paren = Curr == '(';
					if( paren || (Curr == ',') )
					{
						Next( true );
					}
					while( (paren || (!Eol)) && (!Eof) )
					{
						if( Word == null )
						{
							throw new ParseError( this, "Expected argument name" );
						}
						if( (!paren) && Apply( ref tflags, Opcode ) )
						{
							Next();
							while( Apply( ref tflags, Opcode ) )
							{
								Next();
							}
							break;
						}
						var argn = Word;
						var argm = Cgen.FuncArg( mark, name, argc, argn );
						Next();
						OptType( flags );
						argm = Cgen.FuncArgDef( mark, argm, name, argc, argn );
						OptExpr( flags );
						Cgen.FuncArgEnd( mark, argm, name, argc++, argn );
						if( paren && (Curr == ')') )
						{
							Next();
							break;
						}
						if( Curr == ',' )
						{
							Next( true );
						}
					}
					while( Apply( ref tflags, Opcode ) )
					{
						Next();
					}
					mark = Cgen.FuncBody( mark, name, argc, tflags );
					Block( flags | Flag.Nosize );
					Cgen.FuncEnd( mark, name );
				}
			}
			while( ((!Eof) && (Indent > ppind)) && (!one) );
			Pindent = ppind;
			return was;
		}//Members
Пример #4
0
		}//Parser.IGenerator.FieldStart
		
		void Parser.IGenerator.FieldEnd( int @int, string name, Opcode type, Tflag tflag )
		{
			if( type != Opcode.Field )
			{
				Debug.Assert( type == Opcode.Event );
				Write( unchecked((byte)type), @int - 5 );
			}
			Write( CodeAt - @int, @int - 4 );
			Write( ((ushort)tflag), @int );
		}//Parser.IGenerator.FieldEnd
Пример #5
0
		}//Parser.IGenerator.ClassStart
		
		int Parser.IGenerator.ClassBody( int @int, string name, Opcode opcode, int gtnum, int bcnum, Tflag tflag )
		{
			Debug.Assert( bcnum <= 127 );
			Write( unchecked((byte)opcode), @int - 5 );
			Write( CodeAt - @int, @int - 4 );
			Write( ((ushort)tflag), @int );
			Write( unchecked((byte)gtnum), @int + 2 );
			Write( unchecked((byte)bcnum), @int + 3 );
			Write( 0 );
			return CodeAt;
		}//Parser.IGenerator.ClassBody
Пример #6
0
		}//Parser.IGenerator.FuncArgEnd
		
		int Parser.IGenerator.FuncBody( int @int, string fname, int argc, Tflag tflag )
		{
			Debug.Assert( argc <= 127 );
			Write( CodeAt - @int, @int - 4 );
			Write( ((ushort)tflag), @int );
			Write( unchecked((byte)argc), @int + 2 );
			Write( 0 );
			return CodeAt;
		}//Parser.IGenerator.FuncBody