diff dmd/BinExp.d @ 174:af724d3510d7

lot os toCBuffer methods implemented moved shared Type.* stuff into Global
author korDen
date Sun, 10 Oct 2010 03:47:23 +0400
parents 14feb7ae01a6
children 94b6033c07f3
line wrap: on
line diff
--- a/dmd/BinExp.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/BinExp.d	Sun Oct 10 03:47:23 2010 +0400
@@ -277,7 +277,7 @@
 				goto Lt1;
 			}
 			else if (t1.ty == TY.Tclass && t2.ty == TY.Tclass)
-			{	
+			{
 				TypeClass tc1 = cast(TypeClass)t1;
 				TypeClass tc2 = cast(TypeClass)t2;
 
@@ -399,7 +399,7 @@
 		this.e1 = e1;
 		this.e2 = e2;
 	}
-	
+
     override Expression syntaxCopy()
 	{
 		BinExp e = cast(BinExp)copy();
@@ -429,16 +429,16 @@
 		}
 		return this;
 	}
-	
+
     Expression semanticp(Scope sc)
 	{
 		BinExp.semantic(sc);
-	
+
 		e1 = resolveProperties(sc, e1);
 		e2 = resolveProperties(sc, e2);
 		return this;
 	}
-	
+
 	/***************************
 	 * Common semantic routine for some xxxAssignExp's.
 	 */
@@ -461,9 +461,9 @@
 				e = e.semantic(sc);
 				return e;
 			}
-			
+
 			if (e1.op == TOKslice)
-			{   
+			{
 				// T[] op= ...
 				typeCombine(sc);
 				type = e1.type;
@@ -508,7 +508,7 @@
 				e = e.semantic(sc);
 				return e;
 			}
-			
+
 			if (e1.op == TOK.TOKslice)
 			{   // T[] op= ...
 				typeCombine(sc);
@@ -531,7 +531,7 @@
 
 		return this;
 	}
-	
+
     override bool checkSideEffect(int flag)
 	{
 		switch (op) {
@@ -561,7 +561,7 @@
 				return Expression.checkSideEffect(flag);
 		}
 	}
-	
+
     override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
 		expToCBuffer(buf, hgs, e1, precedence[op]);
@@ -581,7 +581,7 @@
 		Type t2b = e2.type.toBasetype();
 
 		if (t1b.ty == Tpointer && t2b.isintegral())
-		{   
+		{
 			// Need to adjust operator by the stride
 			// Replace (ptr + int) with (ptr + (int * stride))
 			Type t = Type.tptrdiff_t;
@@ -594,7 +594,7 @@
 			type = e1.type;
 		}
 		else if (t2b.ty == Tpointer && t1b.isintegral())
-		{   
+		{
 			// Need to adjust operator by the stride
 			// Replace (int + ptr) with (ptr + (int * stride))
 			Type t = Type.tptrdiff_t;
@@ -613,7 +613,7 @@
 		}
 		return this;
 	}
-	
+
 	/************************************
 	 * Bring leaves to common type.
 	 */
@@ -663,7 +663,7 @@
 				ulong sz = e1.type.size() * 8;
 
 				if (i2 < 0 || i2 > sz)
-				{   
+				{
 					error("shift assign by %jd is outside the range 0..%zu", i2, sz);
 					e2 = new IntegerExp(0);
 				}
@@ -677,7 +677,7 @@
 	{
 		return e1.type.isunsigned() || e2.type.isunsigned();
 	}
-	
+
     void incompatibleTypes()
 	{
 		error("incompatible types for ((%s) %s (%s)): '%s' and '%s'",
@@ -761,7 +761,7 @@
 	Lcant:
 		return EXP_CANT_INTERPRET;
 	}
-	
+
     Expression interpretAssignCommon(InterState istate, Expression function(Type, Expression, Expression) fp, int post = 0)
 	{
 version (LOG)
@@ -774,7 +774,7 @@
 		if (fp)
 		{
 			if (e1.op == TOKcast)
-			{   
+			{
 				CastExp ce = cast(CastExp)e1;
 				e1 = ce.e1;
 			}
@@ -784,7 +784,7 @@
 		Expression e2 = this.e2.interpret(istate);
 		if (e2 is EXP_CANT_INTERPRET)
 			return e2;
-		
+
 		// Chase down rebinding of out and ref.
 		if (e1.op == TOKvar)
 		{
@@ -794,7 +794,7 @@
 			{
 				VarExp ve2 = cast(VarExp)v.value;
 				if (ve2.var.isSymbolDeclaration())
-				{	
+				{
 					// This can happen if v is a struct initialized to
 					// 0 using an __initZ SymbolDeclaration from
 					// TypeStruct.defaultInit()
@@ -805,7 +805,7 @@
 			else if (v && v.value && (v.value.op==TOKindex || v.value.op == TOKdotvar))
 			{
 				// It is no longer a TOKvar, eg when a[4] is passed by ref.
-				e1 = v.value;	    
+				e1 = v.value;
 			}
 		}
 
@@ -816,9 +816,9 @@
 			aggregate = (cast(DotVarExp)e1).e1;
 		// Get rid of 'this'.
 			if (aggregate.op == TOKthis && istate.localThis)
-				aggregate = istate.localThis;	
+				aggregate = istate.localThis;
 		}
-		
+
 		/* Assignment to variable of the form:
 		 *	v = e2
 		 */
@@ -828,7 +828,7 @@
 			VarDeclaration v = ve.var.isVarDeclaration();
 			assert(v);
 			if (v && !v.isCTFE())
-			{   
+			{
 				// Can't modify global or static data
 				error("%s cannot be modified at compile time", v.toChars());
 				return EXP_CANT_INTERPRET;
@@ -837,14 +837,14 @@
 			{
 				Expression ev = v.value;
 				if (fp && !ev)
-				{	
+				{
 					error("variable %s is used before initialization", v.toChars());
 					return e;
 				}
 				if (fp)
 					e2 = (*fp)(v.type, ev, e2);
 				else
-				{	
+				{
 					/* Look for special case of struct being initialized with 0.
 					 */
 					if (v.type.toBasetype().ty == Tstruct && e2.op == TOKint64)
@@ -862,7 +862,7 @@
 			}
 		}
 		else if (e1.op == TOKdotvar && aggregate.op == TOKdotvar)
-		{	
+		{
 			// eg  v.u.var = e2,  v[3].u.var = e2, etc.
 			error("Nested struct assignment %s is not yet supported in CTFE", toChars());
 		}
@@ -870,11 +870,11 @@
 		 *   v.var = e2
 		 */
 		else if (e1.op == TOKdotvar && aggregate.op == TOKvar)
-		{	
+		{
 			VarDeclaration v = (cast(VarExp)aggregate).var.isVarDeclaration();
 
 			if (!v.isCTFE())
-			{   
+			{
 				// Can't modify global or static data
 				error("%s cannot be modified at compile time", v.toChars());
 				return EXP_CANT_INTERPRET;
@@ -884,7 +884,7 @@
 				{
 					VarExp ve2 = cast(VarExp)v.value;
 					if (ve2.var.isSymbolDeclaration())
-					{	
+					{
 						// This can happen if v is a struct initialized to
 						// 0 using an __initZ SymbolDeclaration from
 						// TypeStruct.defaultInit()
@@ -895,12 +895,12 @@
 				}
 			}
 			if (fp && !v.value)
-			{   
+			{
 				error("variable %s is used before initialization", v.toChars());
 				return e;
 			}
 			if (v.value is null && v.init.isVoidInitializer())
-			{   
+			{
 				/* Since a void initializer initializes to undefined
 				 * values, it is valid here to use the default initializer.
 				 * No attempt is made to determine if someone actually relies
@@ -946,7 +946,7 @@
 		 *   *(symoffexp) = e2
 		 */
 		else if (e1.op == TOKstar && (cast(PtrExp)e1).e1.op == TOKsymoff)
-		{	
+		{
 			SymOffExp soe = cast(SymOffExp)(cast(PtrExp)e1).e1;
 			VarDeclaration v = soe.var.isVarDeclaration();
 
@@ -956,7 +956,7 @@
 				return EXP_CANT_INTERPRET;
 			}
 			if (fp && !v.value)
-			{   
+			{
 				error("variable %s is used before initialization", v.toChars());
 				return e;
 			}
@@ -994,7 +994,7 @@
 		 *   a[i] = e2
 		 */
 		else if (e1.op == TOKindex && (cast(IndexExp)e1).e1.op == TOKvar)
-		{	
+		{
 			IndexExp ie = cast(IndexExp)e1;
 			VarExp ve = cast(VarExp)ie.e1;
 			VarDeclaration v = ve.var.isVarDeclaration();
@@ -1007,7 +1007,7 @@
 			{
 				VarExp ve2 = cast(VarExp)v.value;
 				if (ve2.var.isSymbolDeclaration())
-				{	
+				{
 					// This can happen if v is a struct initialized to
 					// 0 using an __initZ SymbolDeclaration from
 					// TypeStruct.defaultInit()
@@ -1019,7 +1019,7 @@
 			if (!v.value)
 			{
 				if (fp)
-				{   
+				{
 					error("variable %s is used before initialization", v.toChars());
 					return e;
 				}
@@ -1083,7 +1083,7 @@
 				e2 = Cast(type, type, e2);
 			if (e2 is EXP_CANT_INTERPRET)
 				return e2;
-			
+
 			addVarToInterstate(istate, v);
 			if (ae)
 			{
@@ -1103,14 +1103,14 @@
 				valuesx.setDim(aae.values.dim);
 				int updated = 0;
 				for (size_t j = valuesx.dim; j; )
-				{	
+				{
 					j--;
 					Expression ekey = aae.keys[j];
 					Expression ex = Equal(TOKequal, Type.tbool, ekey, index);
 					if (ex is EXP_CANT_INTERPRET)
 						return EXP_CANT_INTERPRET;
 					if (ex.isBool(true))
-					{   
+					{
 						valuesx[j] = e2;
 						updated = 1;
 					}
@@ -1118,7 +1118,7 @@
 						valuesx[j] = aae.values[j];
 				}
 				if (!updated)
-				{	
+				{
 					// Append index/e2 to keysx[]/valuesx[]
 					valuesx.push(e2);
 					keysx = keysx.copy();
@@ -1156,7 +1156,7 @@
 
 			e = Cast(type, type, post ? ev : e2);
 		}
-		
+
 		/* Assignment to struct element in array, of the form:
 		 *  a[i].var = e2
 		 */
@@ -1214,7 +1214,7 @@
 			int elemi = cast(int)index.toInteger();
 			if (elemi >= ae.elements.dim)
 			{
-				error("array index %d is out of bounds %s[0..%d]", elemi, 
+				error("array index %d is out of bounds %s[0..%d]", elemi,
 					v.toChars(), ae.elements.dim);
 				return EXP_CANT_INTERPRET;
 			}
@@ -1232,7 +1232,7 @@
 			int fieldi = se.getFieldIndex(type, vf.offset);
 			if (fieldi == -1)
 				return EXP_CANT_INTERPRET;
-				
+
 			Expression ev = se.getField(type, vf.offset);
 			if (fp)
 				e2 = (*fp)(type, ev, e2);
@@ -1267,7 +1267,7 @@
 			{
 				VarExp ve2 = cast(VarExp)v.value;
 				if (ve2.var.isSymbolDeclaration())
-				{	
+				{
 					// This can happen if v is a struct initialized to
 					// 0 using an __initZ SymbolDeclaration from
 					// TypeStruct.defaultInit()
@@ -1298,7 +1298,7 @@
 			}
 			Type t = v.type.toBasetype();
 			size_t dim;
-			if (t.ty == Tsarray)			
+			if (t.ty == Tsarray)
 				dim = cast(size_t)(cast(TypeSArray)t).dim.toInteger();
 			else if (t.ty == Tarray)
 			{
@@ -1346,7 +1346,7 @@
 			if (e2.op == TOKarrayliteral)
 			{
 				// Static array assignment from literal
-				ArrayLiteralExp ae = cast(ArrayLiteralExp)e2;				
+				ArrayLiteralExp ae = cast(ArrayLiteralExp)e2;
 				if (ae.elements.dim != (upperbound - lowerbound))
 				{
 					error("Array length mismatch assigning [0..%d] to [%d..%d]", ae.elements.dim, lowerbound, upperbound);
@@ -1372,7 +1372,7 @@
 					// value[] = value[0..lower] ~ ae ~ value[upper..$]
 					existing.elements = spliceElements(existing.elements, createBlockDuplicatedArrayLiteral(v.type, e2, upperbound-lowerbound).elements, lowerbound);
 					v.value = existing;
-				}				
+				}
 				return e2;
 			}
 			else if (e2.op == TOKstring)
@@ -1407,7 +1407,7 @@
 	{
 		return e1.canThrow() || e2.canThrow();
 	}
-	
+
 	// generate an error if this is a nonsensical *=,/=, or %=, eg real *= imaginary
 	void checkComplexMulAssign()
 	{
@@ -1417,7 +1417,7 @@
 		if ( e1.type.isreal() && e2.type.iscomplex())
 		{
 			error("%s %s %s is undefined. Did you mean %s %s %s.re ?",
-				e1.type.toChars(), opstr, e2.type.toChars(), 
+				e1.type.toChars(), opstr, e2.type.toChars(),
 				e1.type.toChars(), opstr, e2.type.toChars());
 		}
 		else if (e1.type.isimaginary() && e2.type.iscomplex())
@@ -1439,7 +1439,7 @@
 		// Addition or subtraction of a real and an imaginary is a complex result.
 		// Thus, r+=i, r+=c, i+=r, i+=c are all forbidden operations.
 		if ( (e1.type.isreal() && (e2.type.isimaginary() || e2.type.iscomplex())) ||
-			 (e1.type.isimaginary() && (e2.type.isreal() || e2.type.iscomplex()))        
+			 (e1.type.isimaginary() && (e2.type.isreal() || e2.type.iscomplex()))
 			)
 		{
 			error("%s %s %s is undefined (result is complex)",
@@ -1454,13 +1454,13 @@
     Expression arrayOp(Scope sc)
 	{
 		//printf("BinExp.arrayOp() %s\n", toChars());
-		
+
 		if (type.toBasetype().nextOf().toBasetype().ty == Tvoid)
 		{
 			error("Cannot perform array operations on void[] arrays");
 			return new ErrorExp();
 		}
-		
+
 		auto arguments = new Expressions();
 
 		/* The expression to generate an array operation for is mangled
@@ -1740,7 +1740,7 @@
 	{
 		return 1 + e1.inlineCost(ics) + e2.inlineCost(ics);
 	}
-	
+
     override Expression doInline(InlineDoState ids)
 	{
 		BinExp be = cast(BinExp)copy();
@@ -1749,7 +1749,7 @@
 		be.e2 = e2.doInline(ids);
 		return be;
 	}
-	
+
     override Expression inlineScan(InlineScanState* iss)
 	{
 		e1 = e1.inlineScan(iss);
@@ -1828,12 +1828,12 @@
 					overloadResolveX(&m, fd, null, args2);
 				}
 				else
-				{   
+				{
 					td = s.isTemplateDeclaration();
 					templateResolve(&m, td, sc, loc, null, null, args2);
 				}
 			}
-			
+
 			lastf = m.lastf;
 
 			if (s_r)
@@ -1844,7 +1844,7 @@
 					overloadResolveX(&m, fd, null, args1);
 				}
 				else
-				{  
+				{
 					td = s_r.isTemplateDeclaration();
 					templateResolve(&m, td, sc, loc, null, null, args1);
 				}
@@ -1900,7 +1900,7 @@
 				 */
 
 				if (!argsset)
-				{	
+				{
 					args1.setDim(1);
 					args1[0] = e1;
 					args2.setDim(1);
@@ -2031,24 +2031,24 @@
 		return e;
 	}
 	final void AssignExp_buildArrayIdent(OutBuffer buf, Expressions arguments, string Str)
-	{							
-		/* Evaluate assign expressions right to left	
-		 */							
-		e2.buildArrayIdent(buf, arguments);		
-		e1.buildArrayIdent(buf, arguments);		
-		buf.writestring(Str);				
-		buf.writestring("ass");				
+	{
+		/* Evaluate assign expressions right to left
+		 */
+		e2.buildArrayIdent(buf, arguments);
+		e1.buildArrayIdent(buf, arguments);
+		buf.writestring(Str);
+		buf.writestring("ass");
 	}
-	
+
 	final void Exp_buildArrayIdent(OutBuffer buf, Expressions arguments, string Str)
-	{									
-		/* Evaluate assign expressions left to right			
-		 */									
-		e1.buildArrayIdent(buf, arguments);				
-		e2.buildArrayIdent(buf, arguments);				
-		buf.writestring(Str);						
+	{
+		/* Evaluate assign expressions left to right
+		 */
+		e1.buildArrayIdent(buf, arguments);
+		e2.buildArrayIdent(buf, arguments);
+		buf.writestring(Str);
 	}
-	
+
 	final Expression AssignExp_buildArrayLoop(AssignExpType)(Parameters fparams)// if (is (AssignExpType : AssignExp))
 	{
 		/* Evaluate assign expressions right to left
@@ -2060,7 +2060,7 @@
 		Expression e = new AssignExpType(Loc(0), ex1, ex2);
 		return e;
 	}
-	
+
 	final Expression Exp_buildArrayLoop(ExpType)(Parameters fparams) if (is (ExpType : BinExp))
 	{
 		/* Evaluate assign expressions left to right
@@ -2070,4 +2070,4 @@
 		Expression e = new ExpType(Loc(0), ex1, ex2);
 		return e;
 	}
-}
\ No newline at end of file
+}