diff dmd/CallExp.d @ 130:60bb0fe4563e

dmdfe 2.037 first main iteration
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Thu, 09 Sep 2010 22:51:44 +0100
parents e28b18c23469
children af1bebfd96a4
line wrap: on
line diff
--- a/dmd/CallExp.d	Sun Sep 05 15:32:22 2010 +0400
+++ b/dmd/CallExp.d	Thu Sep 09 22:51:44 2010 +0100
@@ -49,6 +49,7 @@
 import dmd.DotVarExp;
 import dmd.DotIdExp;
 import dmd.TY;
+import dmd.TRUST;
 import dmd.Id;
 import dmd.TypeAArray;
 import dmd.RemoveExp;
@@ -214,25 +215,25 @@
 				 * If not, go with partial explicit specialization.
 				 */
 				ti.semanticTiargs(sc);
-				uint errors = global.errors;
-				global.gag++;
-				ti.semantic(sc);
-				global.gag--;
-				if (errors != global.errors)
+				if (ti.needsTypeInference(sc))
 				{
-					/* Didn't work, go with partial explicit specialization
+					/* Go with partial explicit specialization
 					 */
-					global.errors = errors;
 					targsi = ti.tiargs;
 					tierror = ti;			// for error reporting
 					e1 = new IdentifierExp(loc, ti.name);
 				}
+				else
+				{
+					ti.semantic(sc);
+				}
 			}
 		}
 
 		/* This recognizes:
 		 *	expr.foo!(tiargs)(funcargs)
 		 */
+Ldotti:
 		if (e1.op == TOK.TOKdotti && !e1.type)
 		{	
 			DotTemplateInstanceExp se = cast(DotTemplateInstanceExp)e1;
@@ -243,6 +244,7 @@
 				 * If not, go with partial explicit specialization.
 				 */
 				ti.semanticTiargs(sc);
+static if (false) {
 				Expression etmp = e1.trySemantic(sc);
 				if (etmp)
 					e1 = etmp;	// it worked
@@ -252,6 +254,24 @@
 					tierror = ti;		// for error reporting
 					e1 = new DotIdExp(loc, se.e1, ti.name);
 				}
+} else {
+				if (!ti.tempdecl)
+				{
+					se.getTempdecl(sc);
+				}
+				if (ti.tempdecl && ti.needsTypeInference(sc))
+				{
+				/* Go with partial explicit specialization
+				 */
+					targsi = ti.tiargs;
+					tierror = ti;			// for error reporting
+					e1 = new DotIdExp(loc, se.e1, ti.name);
+				}
+				else
+				{
+					e1 = e1.semantic(sc);
+				}
+}
 			}
 		}
 }
@@ -259,6 +279,7 @@
 		istemp = 0;
 	Lagain:
 		//printf("Lagain: %s\n", toChars());
+		//printf("test1 %s\n", toChars());
 		f = null;
 		if (e1.op == TOK.TOKthis || e1.op == TOK.TOKsuper)
 		{
@@ -266,7 +287,21 @@
 		}
 		else
 		{
-			UnaExp.semantic(sc);
+			if (e1.op == TOK.TOKdot)
+			{
+				auto die = cast(DotIdExp)e1;
+				e1 = die.semantic(sc, 1);
+				/* Look for e1 having been rewritten to expr.opDispatch!(string)
+				 * We handle such earlier, so go back.
+				 * Note that in the rewrite, we carefully did not run semantic() on e1
+				 */
+				if (e1.op == TOK.TOKdotti && !e1.type)
+				{
+					goto Ldotti;
+				}
+			}
+			else
+				UnaExp.semantic(sc);
 
 			/* Look for e1 being a lazy parameter
 			 */
@@ -393,7 +428,7 @@
 		}
 
 		arrayExpressionSemantic(arguments, sc);
-		preFunctionArguments(loc, sc, arguments);
+		preFunctionParameters(loc, sc, arguments);
 
 		if (e1.op == TOK.TOKdotvar && t1.ty == TY.Tfunction ||
 			e1.op == TOK.TOKdottd)
@@ -450,6 +485,7 @@
 			checkDeprecated(sc, f);
 	version (DMDV2) {
 			checkPurity(sc, f);
+			checkSafety(sc, f);
 	}
 			accessCheck(loc, sc, ue.e1, f);
 			if (!f.needThis())
@@ -563,6 +599,7 @@
 					checkDeprecated(sc, f);
 version (DMDV2) {
 					checkPurity(sc, f);
+					checkSafety(sc, f);
 }
 					e1 = new DotVarExp(e1.loc, e1, f);
 					e1 = e1.semantic(sc);
@@ -602,6 +639,7 @@
 				checkDeprecated(sc, f);
 version (DMDV2) {
 				checkPurity(sc, f);
+				checkSafety(sc, f);
 }
 				e1 = new DotVarExp(e1.loc, e1, f);
 				e1 = e1.semantic(sc);
@@ -669,6 +707,10 @@
 				{
 					error("pure function '%s' cannot call impure delegate '%s'", sc.func.toChars(), e1.toChars());
 				}
+				if (sc.func && sc.func.isSafe() && tf.trust <= TRUST.TRUSTsystem)
+				{
+					error("safe function '%s' cannot call system delegate '%s'", sc.func.toChars(), e1.toChars());
+				}
 				goto Lcheckargs;
 			}
 			else if (t1.ty == TY.Tpointer && (cast(TypePointer)t1).next.ty == TY.Tfunction)
@@ -679,6 +721,10 @@
 				{
 					error("pure function '%s' cannot call impure function pointer '%s'", sc.func.toChars(), e1.toChars());
 				}
+				if (sc.func && sc.func.isSafe() && !(cast(TypeFunction)t1).trust <= TRUST.TRUSTsystem)
+				{
+					error("safe function '%s' cannot call system function pointer '%s'", sc.func.toChars(), e1.toChars());
+				}
 				e.type = t1;
 				e1 = e;
 			}
@@ -708,8 +754,7 @@
 			else
 			{   
 				error("function expected before (), not %s of type %s", e1.toChars(), e1.type.toChars());
-				type = Type.terror;
-				return this;
+				return new ErrorExp();
 			}
 		}
 		else if (e1.op == TOK.TOKvar)
@@ -726,6 +771,7 @@
 			checkDeprecated(sc, f);
 version (DMDV2) {
 			checkPurity(sc, f);
+			checkSafety(sc, f);
 }
 
 			if (f.needThis() && hasThis(sc))
@@ -754,7 +800,7 @@
 		if (!arguments)
 			arguments = new Expressions();
 
-		functionArguments(loc, sc, tf, arguments);
+		functionParameters(loc, sc, tf, arguments);
 
 		if (!type)
 		{