re:fxcop
Gopal V <gopalv82-/[email protected]>
| Newsgroups | gmane.comp.gnu.dotgnu.developer |
|---|---|
| Message-ID | <[email protected]> |
Hi,
As an experimental patch ... I've made a patch to
convert
if(a == "")
to
if(a != null && a.Length == 0)
inside the compiler ... Purely experimental. Just
to show that it can be done ...
It does not do if("" == a) ... which is left as an
exercise for the reader ;-)
Gopal
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
cs_oper.tc.patch
(application/octet-stream, 3.1 KB)
--- cs_oper.tc.orig 2004-03-12 17:02:42.000000000 +0530
+++ cs_oper.tc 2004-05-01 14:53:51.000000000 +0530
@@ -398,6 +398,36 @@
return value;
}
+static ILProperty* FindStringLengthProperty(ILGenInfo *info)
+{
+ ILType * stringType = ILFindSystemType(info, "String");
+ ILClass * stringClass = NULL;
+ ILMember * lengthMember = NULL;
+
+ if(!stringType)
+ {
+ return NULL;
+ }
+
+ stringClass = ILClassResolve(ILType_ToClass(stringType));
+
+ if(!stringClass)
+ {
+ return NULL;
+ }
+
+ lengthMember = ILClassNextMemberMatch(stringClass, lengthMember,
+ 0,
+ "Length",
+ NULL);
+ if(!lengthMember)
+ {
+ return NULL;
+ }
+
+ return (ILField*)lengthMember;
+}
+
%}
/*
@@ -1896,6 +1926,7 @@
CSSemValue value2;
ILType *resultType;
+ fprintf(stderr, "Do we even call this fucking function ?\n");
/* Perform semantic analysis on the arguments */
value1 = ILNode_SemAnalysis(node->expr1, info, &(node->expr1));
value2 = ILNode_SemAnalysis(node->expr2, info, &(node->expr2));
@@ -1920,23 +1951,21 @@
/* If one of the arguments is a string and the other is null,
then the code generator knows how to handle the operation */
- if(ILTypeIsStringClass(CSSemGetType(value1)))
+ if(ILTypeIsStringClass(CSSemGetType(value1)) &&
+ (CSSemGetType(value2) == ILType_Null))
{
- if(CSSemGetType(value2) == ILType_Null)
+ if(table == ILOp_Eq)
{
- if(table == ILOp_Eq)
- {
- *parent = ILNode_IsNull_create(node->expr1);
- }
- else
- {
- *parent = ILNode_IsNonNull_create(node->expr1);
- }
- yysetfilename(*parent, yygetfilename(node));
- yysetlinenum(*parent, yygetlinenum(node));
- CSSemSetRValue(value1, ILType_Boolean);
- return value1;
+ *parent = ILNode_IsNull_create(node->expr1);
}
+ else
+ {
+ *parent = ILNode_IsNonNull_create(node->expr1);
+ }
+ yysetfilename(*parent, yygetfilename(node));
+ yysetlinenum(*parent, yygetlinenum(node));
+ CSSemSetRValue(value1, ILType_Boolean);
+ return value1;
}
else if(CSSemGetType(value1) == ILType_Null &&
ILTypeIsStringClass(CSSemGetType(value2)))
@@ -1954,6 +1983,30 @@
CSSemSetRValue(value1, ILType_Boolean);
return value1;
}
+ else if(ILTypeIsStringClass(CSSemGetType(value1)) &&
+ ILTypeIsStringClass(CSSemGetType(value2)))
+ {
+ fprintf(stderr, "%s:%d ... Both are strings \n",__FILE__,__LINE__);
+ if(yyisa(node->expr2, ILNode_String) &&
+ ((ILNode_String*)(node->expr2))->len == 0)
+ {
+
+ fprintf(stderr, "%s:%d ... expr2 is constant \n",__FILE__,__LINE__);
+ ILProperty *lengthField = FindStringLengthProperty(info);
+ if(lengthField)
+ {
+ fprintf(stderr, "%s:%d ... found length field \n",__FILE__,__LINE__);
+ *parent = ILNode_LogicalAnd_create(
+ ILNode_IsNonNull_create(node->expr1),
+ ILNode_Eq_create(
+ ILNode_MemberProperty_create(node->expr1, lengthField), ILNode_Int32_create(0,0,1)));
+ yysetfilename(*parent, yygetfilename(node));
+ yysetlinenum(*parent, yygetlinenum(node));
+ CSSemSetRValue(value1, ILType_Boolean);
+ return value1;
+ }
+ }
+ }
/* If one of the arguments is a pointer and the other is null,
then the code generator knows how to handle the operation */