diff dmd/FuncDeclaration.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 1765f3ef917d
children 206db751bd4c
line wrap: on
line diff
--- a/dmd/FuncDeclaration.d	Sun Sep 05 15:32:22 2010 +0400
+++ b/dmd/FuncDeclaration.d	Thu Sep 09 22:51:44 2010 +0100
@@ -54,7 +54,7 @@
 import dmd.PtrExp;
 import dmd.DeclarationExp;
 import dmd.InlineDoState;
-import dmd.Argument;
+import dmd.Parameter;
 import dmd.StructDeclaration;
 import dmd.ClassDeclaration;
 import dmd.InterfaceDeclaration;
@@ -73,6 +73,7 @@
 import dmd.TypeFunction;
 import dmd.Expression;
 import dmd.STC;
+import dmd.TRUST;
 import dmd.Dsymbol;
 import dmd.Scope;
 import dmd.OutBuffer;
@@ -308,7 +309,7 @@
 			originalType = type;
 		if (!type.deco)
 		{
-			/* Apply const and invariant storage class
+			/* Apply const, immutable and shared storage class
 			 * to the function type
 			 */
 			type = type.semantic(loc, sc);
@@ -360,7 +361,7 @@
 		return;
 		}
 		f = cast(TypeFunction)type;
-		size_t nparams = Argument.dim(f.parameters);
+		size_t nparams = Parameter.dim(f.parameters);
 
 		linkage = sc.linkage;
 	//    if (!parent)
@@ -733,7 +734,7 @@
 
 			case 1:
 			{
-			Argument arg0 = Argument.getNth(f.parameters, 0);
+			auto arg0 = Parameter.getNth(f.parameters, 0);
 			if (arg0.type.ty != TY.Tarray ||
 				arg0.type.nextOf().ty != TY.Tarray ||
 				arg0.type.nextOf().nextOf().ty != TY.Tchar ||
@@ -767,7 +768,7 @@
 		}
 		else
 		{
-			Argument arg0 = Argument.getNth(f.parameters, 0);
+			auto arg0 = Parameter.getNth(f.parameters, 0);
 			Type t0 = arg0.type.toBasetype();
 			Type tb = sd ? sd.type : cd.type;
 			if (arg0.type.implicitConvTo(tb) ||
@@ -776,7 +777,7 @@
 			{
 			if (nparams == 1)
 				goto Lassignerr;
-			Argument arg1 = Argument.getNth(f.parameters, 1);
+			auto arg1 = Parameter.getNth(f.parameters, 1);
 			if (arg1.defaultArg)
 				goto Lassignerr;
 			}
@@ -817,11 +818,11 @@
 					outId = Id.result;	// provide a default
 
 				Loc loc = fensure.loc;
-				Arguments arguments = new Arguments();
-				Argument a = null;
+				auto arguments = new Parameters();
+				Parameter a = null;
 				if (outId)
 				{	
-					a = new Argument(STCref, f.nextOf(), outId, null);
+					a = new Parameter(STCref, f.nextOf(), outId, null);
 					arguments.push(a);
 				}
 				TypeFunction tf = new TypeFunction(arguments, Type.tvoid, 0, LINKd);
@@ -923,8 +924,10 @@
 		sc2.sw = null;
 		sc2.fes = fes;
 		sc2.linkage = LINK.LINKd;
-		sc2.stc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCabstract | STC.STCdeprecated | STC.STC_TYPECTOR | STC.STCfinal | STC.STCtls | STC.STCgshared | STC.STCref);
-		sc2.protection = PROT.PROTpublic;
+        sc2.stc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCabstract | STC.STCdeprecated |
+			        STC.STC_TYPECTOR | STC.STCfinal | STC.STCtls | STC.STCgshared | STC.STCref |
+			        STCproperty | STCsafe | STCtrusted | STCsystem);
+        sc2.protection = PROT.PROTpublic;
 		sc2.explicitProtection = 0;
 		sc2.structalign = 8;
 		sc2.incontract = 0;
@@ -1060,10 +1063,11 @@
 			//printf("[%d] arg.type.ty = %d %s\n", i, arg.type.ty, arg.type.toChars());
 			if (arg.type.ty == TY.Ttuple)
 			{   auto t = cast(TypeTuple)arg.type;
-				size_t dim = Argument.dim(t.arguments);
+				size_t dim = Parameter.dim(t.arguments);
 				for (size_t j = 0; j < dim; j++)
-				{	Argument narg = Argument.getNth(t.arguments, j);
-				narg.storageClass = arg.storageClass;
+				{
+                    auto narg = Parameter.getNth(t.arguments, j);
+				    narg.storageClass = arg.storageClass;
 				}
 			}
 			}
@@ -1072,7 +1076,7 @@
 		/* Declare all the function parameters as variables
 		 * and install them in parameters[]
 		 */
-		size_t nparams = Argument.dim(f.parameters);
+		size_t nparams = Parameter.dim(f.parameters);
 		if (nparams)
 		{   /* parameters[] has all the tuples removed, as the back end
 			 * doesn't know about tuples
@@ -1081,7 +1085,7 @@
 			parameters.reserve(nparams);
 			for (size_t i = 0; i < nparams; i++)
 			{
-			Argument arg = Argument.getNth(f.parameters, i);
+			auto arg = Parameter.getNth(f.parameters, i);
 			Identifier id = arg.ident;
 			if (!id)
 			{
@@ -1119,11 +1123,11 @@
 				continue;			// never used, so ignore
 			if (arg.type.ty == TY.Ttuple)
 			{   auto t = cast(TypeTuple)arg.type;
-				size_t dim = Argument.dim(t.arguments);
+				size_t dim = Parameter.dim(t.arguments);
 				Objects exps = new Objects();
 				exps.setDim(dim);
 				for (size_t j = 0; j < dim; j++)
-				{	Argument narg = Argument.getNth(t.arguments, j);
+				{	auto narg = Parameter.getNth(t.arguments, j);
 				assert(narg.ident);
 				VarDeclaration v = sc2.search(Loc(0), narg.ident, null).isVarDeclaration();
 				assert(v);
@@ -1190,15 +1194,16 @@
 
 			if (outId)
 			{	// Declare result variable
-			VarDeclaration v;
 			Loc loc = this.loc;
 
 			if (fensure)
 				loc = fensure.loc;
 
-			v = new VarDeclaration(loc, type.nextOf(), outId, null);
+			auto v = new VarDeclaration(loc, type.nextOf(), outId, null);
 			v.noauto = true;
 version (DMDV2) {
+		    if (!isVirtual())
+		        v.storage_class |= STC.STCconst;
 			if (f.isref)
 			{
 				v.storage_class |= STC.STCref | STC.STCforeach;
@@ -1897,7 +1902,7 @@
 
 				//printf("tf = %s, args = %s\n", tf.deco, ((Expression *)arguments.data[0]).type.deco);
 				error(loc, "%s%s is not callable using argument types %s",
-				Argument.argsTypesToChars(tf.parameters, tf.varargs),
+				Parameter.argsTypesToChars(tf.parameters, tf.varargs),
 				buf2.toChars(),
 				buf.toChars());
 				return m.anyf;		// as long as it's not a FuncAliasDeclaration
@@ -1910,8 +1915,8 @@
 
 				error(loc, "called with argument types:\n\t(%s)\nmatches both:\n\t%s%s\nand:\n\t%s%s",
 					buf.toChars(),
-					m.lastf.toPrettyChars(), Argument.argsTypesToChars(t1.parameters, t1.varargs),
-					m.nextf.toPrettyChars(), Argument.argsTypesToChars(t2.parameters, t2.varargs));
+					m.lastf.toPrettyChars(), Parameter.argsTypesToChars(t1.parameters, t1.varargs),
+					m.nextf.toPrettyChars(), Parameter.argsTypesToChars(t2.parameters, t2.varargs));
 } else {
 				error(loc, "overloads %s and %s both match argument list for %s",
 					m.lastf.type.toChars(),
@@ -1943,8 +1948,8 @@
 
 		TypeFunction tf = cast(TypeFunction)type;
 		TypeFunction tg = cast(TypeFunction)g.type;
-		size_t nfparams = Argument.dim(tf.parameters);
-		size_t ngparams = Argument.dim(tg.parameters);
+		size_t nfparams = Parameter.dim(tf.parameters);
+		size_t ngparams = Parameter.dim(tg.parameters);
 		MATCH match = MATCHexact;
 
 		/* If both functions have a 'this' pointer, and the mods are not
@@ -1967,7 +1972,7 @@
 		args.setDim(nfparams);
 		for (int u = 0; u < nfparams; u++)
 		{
-			Argument p = Argument.getNth(tf.parameters, u);
+			auto p = Parameter.getNth(tf.parameters, u);
 			Expression e;
 			if (p.storageClass & (STCref | STCout))
 			{
@@ -2252,6 +2257,18 @@
 		return (cast(TypeFunction)this.type).ispure;
 	}
 	
+	int isSafe()
+	{
+		assert(type.ty == TY.Tfunction);
+		return (cast(TypeFunction)this.type).trust == TRUST.TRUSTsafe;
+	}
+
+	int isTrusted()
+	{
+		assert(type.ty == TY.Tfunction);
+		return (cast(TypeFunction)this.type).trust == TRUST.TRUSTtrusted;
+	}
+	
     bool isNested()
 	{
 		//if (!toParent())
@@ -2392,10 +2409,10 @@
 		// Ensure there are no lazy parameters
 		if (tf.parameters)
 		{	
-			size_t dim = Argument.dim(tf.parameters);
+			size_t dim = Parameter.dim(tf.parameters);
 			for (size_t i = 0; i < dim; i++)
 			{   
-				Argument arg = Argument.getNth(tf.parameters, i);
+				auto arg = Parameter.getNth(tf.parameters, i);
 				if (arg.storageClass & STClazy)
 				{   
 					cantInterpret = 1;
@@ -2433,7 +2450,7 @@
 			for (size_t i = 0; i < dim; i++)
 			{   
 				Expression earg = arguments[i];
-				Argument arg = Argument.getNth(tf.parameters, i);
+				auto arg = Parameter.getNth(tf.parameters, i);
 
 				if (arg.storageClass & (STCout | STCref))
 				{
@@ -2462,7 +2479,7 @@
 			for (size_t i = 0; i < dim; i++)
 			{   
 				auto earg = eargs[i];
-				Argument arg = Argument.getNth(tf.parameters, i);
+				auto arg = Parameter.getNth(tf.parameters, i);
 				auto v = cast(VarDeclaration)parameters[i];
 				vsave[i] = v.value;
 version (LOG) {