diff dmd/TraitsExp.d @ 179:cd48cb899aee

Updated to dmd2.040
author korDen
date Sun, 17 Oct 2010 20:56:07 +0400
parents e3afd1303184
children b0d41ff5e0df
line wrap: on
line diff
--- a/dmd/TraitsExp.d	Sun Oct 17 07:42:00 2010 +0400
+++ b/dmd/TraitsExp.d	Sun Oct 17 20:56:07 2010 +0400
@@ -39,37 +39,35 @@
 
 /************************************************
  * Delegate to be passed to overloadApply() that looks
- * for virtual functions.
+ * for functions matching a trait.
  */
 
-struct Pvirtuals
+struct Ptrait
 {
 	Expression e1;
-	Expressions exps;
+	Expressions exps;		// collected results
+	Identifier ident;		// which trait we're looking for
 	
 	bool visit(FuncDeclaration f)
 	{
-		Pvirtuals* p = &this;
+		if (ident == Id.getVirtualFunctions && !f.isVirtual())
+			return false;
 
-		if (f.isVirtual())
-		{	
-			Expression e;
+		Expression e;
 
-			if (p.e1.op == TOKdotvar)
-			{   
-				DotVarExp dve = cast(DotVarExp)p.e1;
-				e = new DotVarExp(Loc(0), dve.e1, f);
-			}
-			else
-				e = new DsymbolExp(Loc(0), f);
-			p.exps.push(e);
+		if (e1.op == TOKdotvar)
+		{   
+			DotVarExp dve = cast(DotVarExp)e1;
+			e = new DotVarExp(Loc(0), dve.e1, f);
 		}
+		else
+			e = new DsymbolExp(Loc(0), f);
+		exps.push(e);
+
 		return false;
 	}
 }
 
-
-
 class TraitsExp : Expression
 {
 	Identifier ident;
@@ -97,7 +95,6 @@
 		if (ident != Id.compiles && ident != Id.isSame)
 			TemplateInstance.semanticTiargs(loc, sc, args, 1);
 		size_t dim = args ? args.dim : 0;
-		Object o;
         Declaration d;
 		FuncDeclaration f;
 
@@ -180,6 +177,10 @@
 			mixin(ISDSYMBOL(q{(f = s.isFuncDeclaration()) !is null && f.isFinal()}));
 		}
 //version(DMDV2) {
+	    else if (ident == Id.isStaticFunction)
+		{
+			mixin(ISDSYMBOL(q{(f = s.isFuncDeclaration()) !is null && !f.needThis()}));
+		}
         else if (ident == Id.isRef)
         {
 	        mixin(ISDSYMBOL(q{(d = s.isDeclaration()) !is null && d.isRef()}));
@@ -192,14 +193,30 @@
         {
 	        mixin(ISDSYMBOL(q{(d = s.isDeclaration()) !is null && d.storage_class & STClazy}));
         }
+		else if (ident == Id.identifier)
+		{	
+			// Get identifier for symbol as a string literal
+			if (dim != 1)
+				goto Ldimerror;
+			auto o = args[0];
+			Dsymbol s = getDsymbol(o);
+			if (!s || !s.ident)
+			{
+				error("argument %s has no identifier", ident.toChars());	///< CHANGED o to ident!!!
+				goto Lfalse;
+			}
+			StringExp se = new StringExp(loc, s.ident.toChars());
+			return se.semantic(sc);
+		}
 //}
 		else if (ident == Id.hasMember ||
 				ident == Id.getMember ||
+			    ident == Id.getOverloads ||
 				ident == Id.getVirtualFunctions)
 		{
 			if (dim != 2)
 				goto Ldimerror;
-			auto o_ = args[0];
+			auto o = args[0];
 			Expression e = isExpression(args[1]);
 			if (!e)
 			{   error("expression expected as second argument of __traits %s", ident.toChars());
@@ -218,9 +235,9 @@
 			}
 			Identifier id = Lexer.idPool(fromStringz(cast(char*)se.string_));
 
-			Type t = isType(o_);
-			e = isExpression(o_);
-			Dsymbol s = isDsymbol(o_);
+			Type t = isType(o);
+			e = isExpression(o);
+			Dsymbol s = isDsymbol(o);
 			if (t)
 				e = typeDotIdExp(loc, t, id);
 			else if (e)
@@ -251,7 +268,7 @@
 				e = e.semantic(sc);
 				return e;
 			}
-			else if (ident == Id.getVirtualFunctions)
+			else if (ident == Id.getVirtualFunctions || ident == Id.getOverloads)
 			{
 				uint errors = global.errors;
 				Expression ex = e;
@@ -259,7 +276,7 @@
 				if (errors < global.errors)
 					error("%s cannot be resolved", ex.toChars());
 
-				/* Create tuple of virtual function overloads of e
+			    /* Create tuple of virtual function overloads of e
 				 */
 				//e.dump(0);
 				Expressions exps = new Expressions();
@@ -277,9 +294,10 @@
 				else
 					f_ = null;
 					
-				Pvirtuals p;
+			    Ptrait p;
 				p.exps = exps;
 				p.e1 = e;
+				p.ident = ident;
 				overloadApply(f_, p);
 
 				TupleExp tup = new TupleExp(loc, exps);
@@ -292,8 +310,8 @@
 		{
 			if (dim != 1)
 				goto Ldimerror;
-			Object o_ = args[0];
-			Dsymbol s = getDsymbol(o_);
+			Object o = args[0];
+			Dsymbol s = getDsymbol(o);
 			ClassDeclaration cd;
 			if (!s || (cd = s.isClassDeclaration()) is null)
 			{
@@ -306,8 +324,8 @@
 		{
 			if (dim != 1)
 				goto Ldimerror;
-			Object o_ = args[0];
-			Dsymbol s = getDsymbol(o_);
+			Object o = args[0];
+			Dsymbol s = getDsymbol(o);
 			ScopeDsymbol sd;
 			if (!s)
 			{
@@ -364,13 +382,13 @@
 				goto Lfalse;
 
 			for (size_t i = 0; i < dim; i++)
-			{   Object o_ = args[i];
+			{   Object o = args[i];
 				Expression e;
 
 				uint errors = global.errors;
 				global.gag++;
 
-				Type t = isType(o_);
+				Type t = isType(o);
 				if (t)
 				{	Dsymbol s;
 					t.resolve(loc, sc, &e, &t, &s);
@@ -441,15 +459,17 @@
 				goto Lfalse;
 		}
 		else
-		{	error("unrecognized trait %s", ident.toChars());
+		{
+			error("unrecognized trait %s", ident.toChars());
 			goto Lfalse;
 		}
 
 		return null;
 
-Lnottype:
-		error("%s is not a type", o/*.toChars()*/); // BUG: o is Object, no member toChars()
-		goto Lfalse;
+// Not used
+//Lnottype:
+//		error("%s is not a type", o.toChars());
+//		goto Lfalse;
 
 Ldimerror:
 		error("wrong number of arguments %d", dim);