[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnet/cscc/csharp cs_attrs.c,1.25,1.26 cs_def
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnet/cscc/csharp cs_attrs.c,1.25,1.26 cs_defs.tc,1.12,1.13 cs_lvalue.tc,1.46,1.47 |
Date: |
Thu, 29 May 2003 20:43:18 -0400 |
Update of /cvsroot/dotgnu-pnet/pnet/cscc/csharp
In directory subversions:/tmp/cvs-serv23637/cscc/csharp
Modified Files:
cs_attrs.c cs_defs.tc cs_lvalue.tc
Log Message:
Handle qualified attribute names that optionally end in
"Attribute" better by pushing the X / XAttribute check further
down into semantic analysis.
Index: cs_attrs.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_attrs.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -r1.25 -r1.26
*** cs_attrs.c 4 May 2003 19:34:24 -0000 1.25
--- cs_attrs.c 30 May 2003 00:43:15 -0000 1.26
***************
*** 115,130 ****
/*
! * Modify an attribute name so that it ends in "Attribute".
*/
! static void ModifyAttrName(ILNode_Identifier *ident,int force)
{
! char *name = ident->name;
! int namelen = strlen(name);
! if(force || (namelen < 9 || strcmp(name + namelen - 9, "Attribute") !=
0))
{
! ident->name = ILInternAppendedString
! (ILInternString(name, namelen),
! ILInternString("Attribute", 9)).string;
}
}
--- 115,142 ----
/*
! * Modify an attribute name node so that it uses ILNode_AttrQualIdent
! * or ILNode_AttrIdentifier for the top-level attribute lookup.
*/
! static ILNode *ModifyAttrName(ILNode *node)
{
! ILNode *newNode;
! if(yyisa(node, ILNode_QualIdent))
{
! newNode = ILNode_AttrQualIdent_create
! (((ILNode_QualIdent *)node)->left,
! ((ILNode_QualIdent *)node)->right);
}
+ else if(yyisa(node, ILNode_Identifier))
+ {
+ newNode = ILNode_AttrIdentifier_create
+ (((ILNode_Identifier *)node)->name);
+ }
+ else
+ {
+ return node;
+ }
+ yysetfilename(newNode, yygetfilename(node));
+ yysetlinenum(newNode, yygetlinenum(node));
+ return newNode;
}
***************
*** 414,469 ****
unsigned long blobLen;
ILAttribute *attribute;
- ILNode *nameNode;
- int retry;
int skipConst;
ILType *argType;
! /* Hack: recognize "System.AttributeUsage" and add "Attribute".
! This doesn't solve all "ends in Attribute and lives in a namespace"
! problems, but gets rid of a particularly annoying one until a better
! solution can be devised */
! if(!strcmp(ILQualIdentName(attr->name, 0), "System.AttributeUsage"))
! {
! ((ILNode_QualIdent *)(attr->name))->right =
! ILNode_Identifier_create
! (ILInternString("AttributeUsageAttribute",
-1).string);
! }
! else if(!strcmp(ILQualIdentName(attr->name, 0), "System.Serializable"))
! {
! ((ILNode_QualIdent *)(attr->name))->right =
! ILNode_Identifier_create
! (ILInternString("SerializableAttribute",
-1).string);
! }
!
! /* Try the attribute name without "Attribute" first */
! nameNode = attr->name;
! retry = 1;
! type = 0;
! if(CSSemExpectType(attr->name, info, &(attr->name)))
! {
! type = CSSemType(attr->name, info, &(attr->name));
! if(ILTypeAssignCompatible(info->image, type,
!
ILFindSystemType(info, "Attribute")))
! {
! retry = 0;
! }
! }
- /* Retry with "Attribute" appended to the name if necessary */
- if(retry)
- {
- attr->name = nameNode;
- if(yyisa(attr->name, ILNode_Identifier))
- {
- ModifyAttrName((ILNode_Identifier *)(attr->name), 1);
- }
- else if(yyisa(attr->name, ILNode_QualIdent))
- {
- ModifyAttrName((ILNode_Identifier *)(((ILNode_QualIdent
*)
-
(attr->name))->right), 1);
- }
- type = CSSemType(attr->name, info, &(attr->name));
- }
-
/* The type must inherit from "System.Attribute" and not be abstract */
if(!ILTypeAssignCompatible
--- 426,437 ----
unsigned long blobLen;
ILAttribute *attribute;
int skipConst;
ILType *argType;
! /* Modify the name so as to correctly handle "Attribute" suffixes,
! and then perform semantic analysis on the type */
! attr->name = ModifyAttrName(attr->name);
! type = CSSemType(attr->name, info, &(attr->name));
/* The type must inherit from "System.Attribute" and not be abstract */
if(!ILTypeAssignCompatible
Index: cs_defs.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_defs.tc,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** cs_defs.tc 22 Feb 2003 06:14:33 -0000 1.12
--- cs_defs.tc 30 May 2003 00:43:15 -0000 1.13
***************
*** 120,123 ****
--- 120,125 ----
}
%node ILNode_ToAttrConst ILNode_ToConst
+ %node ILNode_AttrQualIdent ILNode_QualIdent
+ %node ILNode_AttrIdentifier ILNode_Identifier
/*
Index: cs_lvalue.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_lvalue.tc,v
retrieving revision 1.46
retrieving revision 1.47
diff -C2 -r1.46 -r1.47
*** cs_lvalue.tc 29 May 2003 20:59:27 -0000 1.46
--- cs_lvalue.tc 30 May 2003 00:43:15 -0000 1.47
***************
*** 997,1000 ****
--- 997,1074 ----
/*
+ * Perform semantic analysis with a bias to returning Type objects.
+ * Also handle names that optionally end in "Attribute".
+ */
+ ILNode_SemAnalysisType(ILNode_AttrIdentifier)
+ {
+ CSSemValue value;
+ ILNode_UsingAlias *alias;
+ ILScopeData *data;
+ int savedState=info->inSemType;
+ char *name;
+
+ /* Resolve the simple name */
+ info->inSemType=1;
+ value = CSResolveSimpleNameQuiet(info, (ILNode *)node, node->name, 1);
+ info->inSemType=savedState;
+
+ if (CSSemGetKind(value) == CS_SEMKIND_TYPE &&
+ ILTypeAssignCompatible(info->image, CSSemGetType(value),
+ ILFindSystemType(info,
"Attribute")))
+ {
+ /* Convert the result into an l-value or r-value and return it
*/
+ return SemToLRValue((ILNode *)node, info, parent,
+ value, node->name, 0,
0);
+ }
+
+ /* Try again, this time with "Attribute" appended */
+ name = ILInternAppendedString
+ (ILInternString(node->name, strlen(node->name)),
+ ILInternString("Attribute", 9)).string;
+ info->inSemType=1;
+ value = CSResolveSimpleNameQuiet(info, (ILNode *)node, name, 1);
+ info->inSemType=savedState;
+
+ if (CSSemGetKind(value) == CS_SEMKIND_TYPE)
+ {
+ /* Convert the result into an l-value or r-value and return it
*/
+ return SemToLRValue((ILNode *)node, info, parent,
+ value, node->name, 0,
0);
+ }
+
+ data = ILScopeLookup(info->currentScope, node->name, 1);
+
+ if(data && ILScopeDataGetKind(data) == IL_SCOPE_ALIAS &&
+ !(info->resolvingAlias))
+ {
+ alias=(ILNode_UsingAlias*)ILScopeDataGetNode(data);
+ if(alias->visited==ILVisitMode_Processing)
+ {
+ CCErrorOnLine(yygetfilename(alias), yygetlinenum(alias),
+ "circularity detected in `using' declaration");
+ CSSemSetLValue(value, ILType_Int32);
+ return value;
+ }
+ alias->visited=ILVisitMode_Processing;
+ *parent = (ILNode*)ILScopeDataGetData1(data);
+ if(info->resolvingAlias)
+ {
+ CCErrorOnLine(yygetfilename(alias), yygetlinenum(alias),
+ "using aliases may not refer
to other aliases");
+ }
+ info->resolvingAlias = 1;
+ savedState=info->inSemType;
+ info->inSemType=1;
+ value = ILNode_SemAnalysis(*parent,info,parent);
+ info->inSemType=savedState;
+ info->resolvingAlias = 0;
+ alias->visited=ILVisitMode_Done;
+ return value;
+ }
+
+ return CSSemValueDefault;
+ }
+
+ /*
* Perform semantic analysis for qualified identifiers.
*/
***************
*** 1037,1040 ****
--- 1111,1161 ----
value2 = CSResolveMemberName(info, (ILNode *)node, value, name, 1);
+ info->inSemType = savedState;
+
+ if (CSSemGetKind(value2) != CS_SEMKIND_TYPE)
+ {
+ return CSSemValueDefault;
+ }
+ else
+ {
+ /* Convert the result into an l-value or r-value and return it
*/
+ return SemToLRValue((ILNode *)node, info, parent, value2,
+ name, node->left, &value);
+ }
+ }
+
+ /*
+ * Perform semantic analysis with a bias to returning Type objects.
+ * If the first lookup fails, another is tried where the right-hand
+ * part of the identifier ends in "Attribute".
+ */
+ ILNode_SemAnalysisType(ILNode_AttrQualIdent)
+ {
+ CSSemValue value;
+ CSSemValue value2;
+ char *name;
+ int savedState = info->inSemType;
+
+ /* Restrict lookups for types only (ie namespaces , types, nested types
*/
+ info->inSemType = 1;
+
+ /* Get the semantic value for the left part of the identifier */
+ value = ILNode_SemAnalysis(node->left, info, &(node->left));
+
+ /* Resolve the member */
+ name = ILQualIdentName(node->right, 0);
+ value2 = CSResolveMemberNameQuiet(info, (ILNode *)node, value, name, 1);
+
+ /* If the resolution failed, then try again with "Attribute" appended */
+ if(CSSemGetKind(value2) != CS_SEMKIND_TYPE ||
+ !ILTypeAssignCompatible(info->image, CSSemGetType(value2),
+ ILFindSystemType(info,
"Attribute")))
+ {
+ name = ILInternAppendedString
+ (ILInternString(name, strlen(name)),
+ ILInternString("Attribute", 9)).string;
+ value2 = CSResolveMemberName(info, (ILNode *)node, value, name,
1);
+ }
+
info->inSemType = savedState;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnet/cscc/csharp cs_attrs.c,1.25,1.26 cs_defs.tc,1.12,1.13 cs_lvalue.tc,1.46,1.47,
Rhys Weatherley <address@hidden> <=