Exemplo n.º 1
0
		public string PrintCode ()
		{
			StringWriter sw = new StringWriter ();
			CodeWriter cw = new CodeWriter (sw);
			PrintCode (cw);
			return sw.ToString ();
		}
Exemplo n.º 2
0
		public override void PrintCode (CodeWriter cp)
		{
			if (tryBlock == null) return;
			
			cp.Write ("try {");
			cp.Indent ();
			condition.PrintCode (cp);
			cp.Unindent ();
			foreach (DictionaryEntry de in catchBlocks) {
				CodeVariableDeclaration vd = (CodeVariableDeclaration) de.Key;
				cp.Write ("} catch (");
				if (vd.Variable.Name.Length > 0)
					vd.PrintCode (cp);
				else
					cp.Write (vd.Variable.Type.FullName);
				cp.Write (") {");
				cp.Indent ();
				((CodeBlock) de.Value).PrintCode (cp);
				cp.Unindent ();
			}
			if (!finallyBlock.IsEmpty) {
				cp.Write ("} finally {");
				cp.Indent ();
				finallyBlock.PrintCode (cp);
				cp.Unindent ();
			}
			cp.Write ("}");
		}
Exemplo n.º 3
0
		public override void PrintCode (CodeWriter cp)
		{
			foreach (CodeItem item in statements) {
				cp.BeginLine ();
				item.PrintCode (cp);
				cp.Write (";");
				cp.EndLine ();
			}
		}
Exemplo n.º 4
0
		public override void PrintCode (CodeWriter cp)
		{
			cp.Write ("(");
			condition.PrintCode (cp);
			cp.Write (") ? ");
			trueBlock.PrintCode (cp);
			cp.Write (" : ");
			falseBlock.PrintCode (cp);
		}
Exemplo n.º 5
0
		public override void PrintCode (CodeWriter cp)
		{
			if (object.ReferenceEquals (retValue, null))
				cp.Write ("return");
			else {
				cp.Write ("return ");
				retValue.PrintCode (cp);
			}
		}
Exemplo n.º 6
0
 public override void PrintCode(CodeWriter cp)
 {
     cp.Write ("new " + type.Name + " (");
     for (int n=0; n<parameters.Length; n++) {
         if (n > 0) cp.Write (", ");
         parameters[n].PrintCode (cp);
     }
     cp.Write (")");
 }
Exemplo n.º 7
0
		public override void PrintCode (CodeWriter cp)
		{
			if (!field.IsStatic)
				target.PrintCode (cp);
			else
				cp.Write (field.DeclaringType.Name);
			cp.Write (".");
			cp.Write (field.Name);
		}
Exemplo n.º 8
0
		public override void PrintCode (CodeWriter cp)
		{
			cp.Write ("while (");
			condition.PrintCode (cp);
			cp.Write (") {");
			cp.EndLine ();
			cp.Indent ();
			whileBlock.PrintCode (cp);
			cp.Unindent ();
			cp.BeginLine ().Write ("}");
		}
Exemplo n.º 9
0
		public override void PrintCode (CodeWriter cp)
		{
			cp.Write ("for (");
			initExp.PrintCode (cp);
			cp.Write (";");
			conditionExp.PrintCode (cp);
			cp.Write (";");
			nextExp.PrintCode (cp);
			cp.Write (") {");
			cp.EndLine ();
			cp.Indent ();
			forBlock.PrintCode (cp);
			cp.Unindent ();
			cp.BeginLine ().Write ("}");
		}
Exemplo n.º 10
0
		public override void PrintCode (CodeWriter cp)
		{
			if (trueBlock == null) return;
			
			cp.Write ("if (");
			condition.PrintCode (cp);
			cp.Write (") {");
			cp.EndLine ();
			cp.Indent ();
			trueBlock.PrintCode (cp);
			cp.Unindent ();
			cp.BeginLine ().Write ("}");
			if (falseBlock != null) {
				cp.EndLine ();
				cp.WriteLineInd ("else {");
				falseBlock.PrintCode (cp);
				cp.Unindent ();
				cp.BeginLine ().Write ("}");
			}
		}
Exemplo n.º 11
0
		public override void PrintCode (CodeWriter cp)
		{
			for (int n=0; n<blocks.Count; n++) {
				if (n == 0)
					cp.Write ("if (");
				else
					cp.Write ("else if (");
				
				((CodeExpression)conditions[n]).PrintCode (cp);
				cp.Write (") {");
				cp.EndLine ();
				cp.Indent ();
				((CodeBlock) blocks[n]).PrintCode (cp);
				cp.Unindent ();
				cp.BeginLine ().Write ("}");
				if (n < blocks.Count - 1) {
					cp.EndLine ();
					cp.BeginLine ();
				}
			}
		}
Exemplo n.º 12
0
        public void PrintCode(CodeWriter cw)
        {
            for (int n = 0; n < customAttributes.Count; n++)
            {
                CodeCustomAttribute cca = customAttributes [n] as CodeCustomAttribute;
                if (n > 0)
                {
                    cw.WriteLine("");
                }
                cca.PrintCode(cw);
            }

/*			if ((typeBuilder.Attributes & TypeAttributes.Abstract) != 0) cw.Write ("abstract ");
 *                      if ((typeBuilder.Attributes & TypeAttributes.NestedAssembly) != 0) cw.Write ("internal ");
 *                      if ((typeBuilder.Attributes & TypeAttributes.NestedPrivate) != 0) cw.Write ("private ");
 */         if ((typeBuilder.Attributes & TypeAttributes.Public) != 0)
            {
                cw.Write("public ");
            }
            cw.Write("class ").Write(typeBuilder.Name);

            bool dots = false;

            if (baseType != null && baseType != typeof(object))
            {
                cw.Write(" : " + baseType);
                dots = true;
            }

            if (interfaces != null && interfaces.Length > 0)
            {
                if (!dots)
                {
                    cw.Write(" : ");
                }
                else
                {
                    cw.Write(", ");
                }
                for (int n = 0; n < interfaces.Length; n++)
                {
                    if (n > 0)
                    {
                        cw.Write(", ");
                    }
                    cw.Write(interfaces[n].ToString());
                }
            }

            cw.EndLine().WriteLineInd("{");

            foreach (FieldInfo f in fields)
            {
                cw.BeginLine();
                ArrayList atts = (ArrayList)fieldAttributes [f];
                foreach (CodeCustomAttribute a in atts)
                {
                    a.PrintCode(cw);
                }
                if ((f.Attributes & FieldAttributes.Static) != 0)
                {
                    cw.Write("static ");
                }
                cw.Write(f.FieldType.Name + " ");
                cw.Write(f.Name + ";");
                cw.EndLine();
                cw.WriteLine("");
            }

            for (int n = 0; n < properties.Count; n++)
            {
                CodeProperty prop = properties [n] as CodeProperty;
                if (n > 0)
                {
                    cw.WriteLine("");
                }
                prop.PrintCode(cw);
            }

            for (int n = 0; n < methods.Count; n++)
            {
                CodeMethod met = methods[n] as CodeMethod;
                if (n > 0)
                {
                    cw.WriteLine("");
                }
                met.PrintCode(cw);
            }
            cw.WriteLineUnind("}");
        }
Exemplo n.º 13
0
		public void PrintCode (CodeWriter cp)
		{
			cp.BeginLine ();
			foreach (CodeCustomAttribute a in customAttributes)
				a.PrintCode (cp);
			cp.BeginLine ();
			if (IsStatic)
				cp.Write ("static ");
			if (IsPublic)
				cp.Write ("public ");
			if (returnType != null) cp.Write (returnType + " ");
			cp.Write (name);
			if (parameterTypes.Length > 0) {
				cp.Write (name + " [");
				for (int n=0; n<parameterTypes.Length; n++) {
					if (n > 0) cp.Write (", ");
					cp.Write (parameterTypes[n] + " arg" + n);
				}
				cp.Write ("]");
			}
			cp.Write (" {");
			cp.EndLine ();
			cp.Indent ();
			cp.WriteLineInd ("get {");
			get_builder.PrintCode (cp);
			cp.WriteLineUnind ("}");
			cp.WriteLine ("set {");
			set_builder.PrintCode (cp);
			cp.WriteLine ("}");
			cp.WriteLineUnind ("}");
		}
Exemplo n.º 14
0
		public override void PrintCode (CodeWriter cp)
		{
			if (t1.IsPrimitive) {
				exp1.PrintCode (cp);
				cp.Write (" != ");
				exp2.PrintCode (cp);
			}
			else {
				cp.Write ("!(");
				exp1.PrintCode (cp);
				cp.Write (".Equals (");
				exp2.PrintCode (cp);
				cp.Write ("))");
			}
		}
Exemplo n.º 15
0
		public override void PrintCode (CodeWriter cp)
		{
			array.PrintCode (cp);
			cp.Write ("[");
			index.PrintCode (cp);
			cp.Write ("]");
		}
Exemplo n.º 16
0
		public override void PrintCode (CodeWriter cp)
		{
			exp1.PrintCode (cp);
			cp.Write (" && ");
			exp2.PrintCode (cp);
		}
Exemplo n.º 17
0
 public override void PrintCode(CodeWriter cp)
 {
     exp.PrintCode (cp);
     cp.Write (" is ");
     cp.Write (type.FullName);
 }
Exemplo n.º 18
0
		public override void PrintCode (CodeWriter cp)
		{
			if (value is string)
				cp.Write ("\"").Write (value.ToString ()).Write ("\"");
			else if (value == null)
				cp.Write ("null");
			else if (value is Type)
				cp.Write ("typeof(" + ((Type)value).Name + ")");
			else if (value is Enum)
				cp.Write (value.GetType().Name + "." + value);
			else
				cp.Write (value.ToString ());
		}
Exemplo n.º 19
0
 public override void PrintCode(CodeWriter cp)
 {
     exp.PrintCode(cp);
     cp.Write("--");
 }
Exemplo n.º 20
0
 public override void PrintCode(CodeWriter cp)
 {
     array.PrintCode(cp);
     cp.Write(".Length");
 }
Exemplo n.º 21
0
 public override void PrintCode(CodeWriter cp)
 {
     var.PrintCode (cp);
     cp.Write (" = ");
     exp.PrintCode (cp);
 }
Exemplo n.º 22
0
		public void PrintCode (CodeWriter cw)
		{
			for (int n=0; n<customAttributes.Count; n++) {
				CodeCustomAttribute cca = customAttributes [n] as CodeCustomAttribute;
				if (n > 0) cw.WriteLine ("");
				cca.PrintCode (cw);
			}

/*			if ((typeBuilder.Attributes & TypeAttributes.Abstract) != 0) cw.Write ("abstract ");
			if ((typeBuilder.Attributes & TypeAttributes.NestedAssembly) != 0) cw.Write ("internal ");
			if ((typeBuilder.Attributes & TypeAttributes.NestedPrivate) != 0) cw.Write ("private ");
*/			if ((typeBuilder.Attributes & TypeAttributes.Public) != 0) cw.Write ("public ");
			cw.Write ("class ").Write (typeBuilder.Name);
			
			bool dots = false;
			if (baseType != null && baseType != typeof(object)) {
				cw.Write (" : " + baseType);
				dots = true;
			}
			
			if (interfaces != null && interfaces.Length > 0) {
				if (!dots) cw.Write (" : ");
				else cw.Write (", ");
				for (int n=0; n<interfaces.Length; n++) {
					if (n > 0) cw.Write (", ");
					cw.Write (interfaces[n].ToString ());
				}
			}
			
			cw.EndLine ().WriteLineInd ("{");
			
			foreach (FieldInfo f in fields) {
				cw.BeginLine ();
				ArrayList atts = (ArrayList) fieldAttributes [f];
				foreach (CodeCustomAttribute a in atts)
					a.PrintCode (cw);
				if ((f.Attributes & FieldAttributes.Static) != 0)
					cw.Write ("static ");
				cw.Write (f.FieldType.Name + " ");
				cw.Write (f.Name + ";");
				cw.EndLine ();
				cw.WriteLine (""); 
			}
			
			for (int n=0; n<properties.Count; n++) {
				CodeProperty prop = properties [n] as CodeProperty;
				if (n > 0) cw.WriteLine ("");
				prop.PrintCode (cw);
			}

			for (int n=0; n<methods.Count; n++) {
				CodeMethod met = methods[n] as CodeMethod;
				if (n > 0) cw.WriteLine ("");
				met.PrintCode (cw);
			}
			cw.WriteLineUnind ("}");
		}
Exemplo n.º 23
0
 public override void PrintCode(CodeWriter cp)
 {
     cp.Write ("-");
     exp.PrintCode (cp);
 }
 public override void PrintCode(CodeWriter cp)
 {
     cp.Write (name);
 }
		public void PrintCode (CodeWriter cw)
		{
			cw.Write ("[").Write (type.Name).Write ("(");
			if (ctorArgs.Length > 0) {
				for (int i = 0; i < ctorArgs.Length - 1; i++) {
					ctorArgs [i].PrintCode (cw);
					cw.Write (", ");
				}
				ctorArgs [ctorArgs.Length - 1].PrintCode (cw);
			}
			if (members.Length > 0) {
				if (ctorArgs.Length > 0)
					cw.Write (", ");
				for (int i = 0; i < members.Length; i++) {
					cw.Write (members [i].Name).Write (" = ");
					namedArgValues [i].PrintCode (cw);
					if (i < members.Length - 1)
						cw.Write (", ");
				}
			}
			cw.Write (" )]");
			cw.EndLine ();
		}
Exemplo n.º 26
0
		public override void PrintCode (CodeWriter cp)
		{
			cp.Write ("(");
			exp1.PrintCode (cp);
			cp.Write (" || ");
			exp2.PrintCode (cp);
			cp.Write (")");
		}
Exemplo n.º 27
0
		public override void PrintCode (CodeWriter cp)
		{
			exp.PrintCode (cp);
			cp.Write ("++");
		}
Exemplo n.º 28
0
        public override void PrintCode(CodeWriter cp)
        {
            Type typeObj = exp.GetResultType ();
            if (type.IsAssignableFrom (typeObj)) {
                exp.PrintCode (cp);
                return;
            }

            cp.Write ("((" + type.FullName + ") ");
            exp.PrintCode (cp);
            cp.Write (")");
        }
 public override void PrintCode(CodeWriter cp)
 {
     exp1.PrintCode (cp);
     cp.Write (" " + symbol + " ");
     exp2.PrintCode (cp);
 }
		public override void PrintCode (CodeWriter cp)
		{
			target.PrintCode (cp);
			cp.Write (".");
			cp.Write (property.Name);
		}
Exemplo n.º 31
0
 public override void PrintCode(CodeWriter cp)
 {
     cp.Write(name);
 }
Exemplo n.º 32
0
 public override void PrintCode(CodeWriter cp)
 {
     cp.Write("new " + elemType.Name + " [");
     size.PrintCode(cp);
     cp.Write("]");
 }
Exemplo n.º 33
0
		public virtual void PrintCode (CodeWriter cp)
		{
			cp.BeginLine ();
			foreach (CodeCustomAttribute a in customAttributes)
				a.PrintCode (cp);
			if ((methodBase.Attributes & MethodAttributes.Static) != 0)
				cp.Write ("static ");
			if ((methodBase.Attributes & MethodAttributes.Public) != 0)
				cp.Write ("public ");
			if (returnType != null) cp.Write (returnType + " ");
			cp.Write (name + " (");
			for (int n=0; n<parameterTypes.Length; n++) {
				if (n > 0) cp.Write (", ");
				cp.Write (parameterTypes[n] + " arg" + n);
			}
			cp.Write (")");
			cp.EndLine ();
			cp.WriteLineInd ("{");
			
			builder.PrintCode (cp);
			
			cp.WriteLineUnind ("}");
		}
Exemplo n.º 34
0
		public override void PrintCode (CodeWriter cp)
		{
			cp.Write ("new " + elemType.Name + " [");
			size.PrintCode (cp);
			cp.Write ("]");
		}
Exemplo n.º 35
0
		public override void PrintCode (CodeWriter cp)
		{
		}
Exemplo n.º 36
0
 public abstract void PrintCode(CodeWriter cp);