dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnet/cscc/csharp cs_lvalue.tc,1.44,1.45 cs_in


From: Gopal.V <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/cscc/csharp cs_lvalue.tc,1.44,1.45 cs_internal.h,1.15,1.16 cs_lookup.c,1.26,1.27
Date: Thu, 29 May 2003 12:58:38 -0400

Update of /cvsroot/dotgnu-pnet/pnet/cscc/csharp
In directory subversions:/tmp/cvs-serv22769/cscc/csharp

Modified Files:
        cs_lvalue.tc cs_internal.h cs_lookup.c 
Log Message:
Implement Base element access for C# (semanalysis) and IL (codegen)


Index: cs_lvalue.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_lvalue.tc,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -r1.44 -r1.45
*** cs_lvalue.tc        9 May 2003 15:28:21 -0000       1.44
--- cs_lvalue.tc        29 May 2003 16:58:33 -0000      1.45
***************
*** 1246,1252 ****
  ILNode_SemAnalysis(ILNode_BaseElement)
  {
-       /* TODO */
        CSSemValue value;
!       CSSemSetRValue(value, ILType_Int32);
        return value;
  }
--- 1246,1405 ----
  ILNode_SemAnalysis(ILNode_BaseElement)
  {
        CSSemValue value;
!       ILNode_MethodDeclaration *caller;
!       ILClass *classInfo;
!       ILNode *thisExpr;
!       CSSemValue indexers;
!       CSEvalArg *args;
!       int numArgs, argNum;
!       unsigned long itemNum;
!       ILProgramItem *itemInfo;
!       int candidateForm, kind;
!       ILMethod *getMethod;
!       ILMethod *setMethod;
!       ILType *objectType;
!       ILNode *tempNode;
!       
!       /* Bail out if "base" is used within a static method */
!       caller = (ILNode_MethodDeclaration *)(info->currentMethod);
!       if(!caller || (caller->modifiers & IL_META_METHODDEF_STATIC) != 0)
!       {
!               CCErrorOnLine(yygetfilename(node), yygetlinenum(node),
!                         "cannot use base reference in a static method");
!               CSSemSetType(value, ILType_Int32);
!               return value;
!       }
! 
!       /* Find the parent class to start searching from */
!       classInfo = ILClass_Parent(ILMethod_Owner(caller->methodInfo));
!       if(!classInfo)
!       {
!               CCErrorOnLine(yygetfilename(node), yygetlinenum(node),
!                         "cannot use base reference in `System.Object'");
!               CSSemSetType(value, ILType_Int32);
!               return value;
!       }
! 
!       /* Construct a dummy "this" expression to represent the object */
!       thisExpr = ILNode_This_create();
! 
!       /* Perform semantic analysis on the index argument list */
!       numArgs = CSEvalArguments(info, node->expr, &(node->expr), &args);
!       if(numArgs < 0)
!       {
!               CSSemSetLValue(value, ILType_Int32);
!               return value;
!       }
! 
!       /* Resolve the indexer for this type */
!       objectType = ILClassToType(classInfo);
! 
!       indexers = CSResolveIndexers(info, (ILNode *)node,
!                                                                
ILType_ToClass(objectType),1);
!       
!       if(CSSemIsIndexerGroup(indexers))
!       {
!               /* Scan through the indexer group looking for something
!                  that is applicable to the expression list */
!               itemNum = 0;
!               while((itemInfo = CSGetGroupMember
!                                       (CSSemGetGroup(indexers), itemNum)) != 
0)
!               {
!                       candidateForm = CSItemIsCandidate
!                                       (info, itemInfo, args, numArgs);
!                       if(candidateForm)
!                       {
!                               CSSetGroupMemberForm(CSSemGetGroup(indexers), 
itemNum,
!                                                                        
candidateForm);
!                               ++itemNum;
!                       }
!                       else
!                       {
!                               CSSemModifyGroup(indexers, (ILType 
*)CSRemoveGroupMember
!                                                                       
(CSSemGetGroup(indexers), itemNum));
!                       }
!               }
! 
!               /* If there are no candidates left, then bail out */
!               itemNum = 0;
!               itemInfo = CSGetGroupMember(CSSemGetGroup(indexers), itemNum);
!               if(!itemInfo)
!               {
!                       CSItemCandidateError((ILNode *)node, 0, 0,
!                                                            
CSSemGetGroup(indexers), args, numArgs);
!                       CSEvalFreeArguments(args);
!                       return value;
!               }
! 
!               /* If there are two or more candidates, then try to
!                  find the best one */
!               if(CSGetGroupMember(CSSemGetGroup(indexers), 1) != 0)
!               {
!                       itemInfo = CSBestCandidate(info, 
CSSemGetGroup(indexers),
!                                                                          
args, numArgs);
!                       if(!itemInfo)
!                       {
!                               CSItemCandidateError((ILNode *)node, 0, 0,
!                                                                    
CSSemGetGroup(indexers),
!                                                                        args, 
numArgs);
!                               CSEvalFreeArguments(args);
!                               return value;
!                       }
!               }
! 
!               /* Locate the "get" and "set" methods for the indexer */
!               getMethod = ILProperty_Getter((ILProperty *)itemInfo);
!               setMethod = ILProperty_Setter((ILProperty *)itemInfo);
! 
!               /* Determine the semantic kind for the value */
!               if(getMethod && setMethod)
!               {
!                       kind = CS_SEMKIND_LVALUE;
!               }
!               else if(getMethod)
!               {
!                       kind = CS_SEMKIND_RVALUE;
!               }
!               else if(setMethod)
!               {
!                       kind = CS_SEMKIND_SVALUE;
!               }
!               else
!               {
!                       CCErrorOnLine(yygetfilename(node), yygetlinenum(node),
!                                                 "indexer does not have `get' 
or `set' accessors");
!                       kind = CS_SEMKIND_LVALUE;
!               }
! 
!               /* Import the methods into this image */
!               if(getMethod)
!               {
!                       getMethod = (ILMethod *)ILMemberImport
!                                       (info->image, (ILMember *)getMethod);
!               }
!               if(setMethod)
!               {
!                       setMethod = (ILMethod *)ILMemberImport
!                                       (info->image, (ILMember *)setMethod);
!               }
! 
!               /* Coerce the arguments and build the final argument list */
!               CSSemSetValueKind(value, kind, CSItemCoerceArgs
!                                       (info, ILToProgramItem(itemInfo),
!                                        args, numArgs, &(node->expr)));
! 
!               /* Replace this node with an indexer access node */
!               *parent = ILNode_IndexerAccess_create
!                               (thisExpr, node->expr, getMethod, setMethod,
!                                objectType, CSSemGetType(value),
!                                ILTypeToMachineType(CSSemGetType(value)),1);
!       }
!       else
!       {
!               /* No indexers are defined for this type */
!               CCErrorOnLine(yygetfilename(node), yygetlinenum(node),
!                                         "array or indexed value expected");
!               CSSemSetLValue(value, ILType_Int32);
!       }
        return value;
  }
***************
*** 1448,1452 ****
                objectType = CSSemGetType(value);
                indexers = CSResolveIndexers(info, (ILNode *)node,
!                                                                        
ILType_ToClass(objectType));
                if(CSSemIsIndexerGroup(indexers))
                {
--- 1601,1605 ----
                objectType = CSSemGetType(value);
                indexers = CSResolveIndexers(info, (ILNode *)node,
!                                                                        
ILType_ToClass(objectType),0);
                if(CSSemIsIndexerGroup(indexers))
                {
***************
*** 1544,1548 ****
                                        (node->array, node->indices, getMethod, 
setMethod,
                                         objectType, CSSemGetType(value),
!                                        
ILTypeToMachineType(CSSemGetType(value)));
                }
                else
--- 1697,1701 ----
                                        (node->array, node->indices, getMethod, 
setMethod,
                                         objectType, CSSemGetType(value),
!                                        
ILTypeToMachineType(CSSemGetType(value)),0);
                }
                else

Index: cs_internal.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_internal.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -r1.15 -r1.16
*** cs_internal.h       22 Feb 2003 06:14:33 -0000      1.15
--- cs_internal.h       29 May 2003 16:58:33 -0000      1.16
***************
*** 183,187 ****
   */
  CSSemValue CSResolveIndexers(ILGenInfo *genInfo, ILNode *node,
!                                                        ILClass *classInfo);
  
  /*
--- 183,187 ----
   */
  CSSemValue CSResolveIndexers(ILGenInfo *genInfo, ILNode *node,
!                                                        ILClass *classInfo, 
int baseAccess);
  
  /*

Index: cs_lookup.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/csharp/cs_lookup.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -r1.26 -r1.27
*** cs_lookup.c 7 May 2003 05:58:21 -0000       1.26
--- cs_lookup.c 29 May 2003 16:58:33 -0000      1.27
***************
*** 677,681 ****
   */
  static void FindIndexers(ILClass *info, ILClass *accessedFrom,
!                                            CSMemberLookupInfo *results)
  {
        ILImplements *impl;
--- 677,681 ----
   */
  static void FindIndexers(ILClass *info, ILClass *accessedFrom,
!                                            CSMemberLookupInfo *results, int 
baseAccess)
  {
        ILImplements *impl;
***************
*** 708,712 ****
                                        continue;
                                }
!                               if(ILMethod_IsVirtual(method) && 
!ILMethod_IsNewSlot(method))
                                {
                                        /* This is a virtual override, so skip 
it */
--- 708,713 ----
                                        continue;
                                }
!                               if((!baseAccess) && 
!                                       ILMethod_IsVirtual(method) && 
!ILMethod_IsNewSlot(method))
                                {
                                        /* This is a virtual override, so skip 
it */
***************
*** 738,742 ****
                {
                        FindIndexers(ILImplementsGetInterface(impl),
!                                            accessedFrom, results);
                }
  
--- 739,743 ----
                {
                        FindIndexers(ILImplementsGetInterface(impl),
!                                            accessedFrom, results, baseAccess);
                }
  
***************
*** 750,754 ****
   */
  static int IndexerLookup(ILGenInfo *genInfo, ILClass *info,
!                                        ILClass *accessedFrom, 
CSMemberLookupInfo *results)
  {
        /* Initialize the results */
--- 751,756 ----
   */
  static int IndexerLookup(ILGenInfo *genInfo, ILClass *info,
!                                        ILClass *accessedFrom, 
CSMemberLookupInfo *results,
!                                                int baseAccess)
  {
        /* Initialize the results */
***************
*** 758,762 ****
        if(info)
        {
!               FindIndexers(info, accessedFrom, results);
        }
  
--- 760,764 ----
        if(info)
        {
!               FindIndexers(info, accessedFrom, results, baseAccess);
        }
  
***************
*** 1657,1661 ****
  
  CSSemValue CSResolveIndexers(ILGenInfo *genInfo, ILNode *node,
!                                                        ILClass *classInfo)
  {
        CSSemValue value;
--- 1659,1663 ----
  
  CSSemValue CSResolveIndexers(ILGenInfo *genInfo, ILNode *node,
!                                                        ILClass *classInfo, 
int baseAccess)
  {
        CSSemValue value;
***************
*** 1668,1672 ****
  
        /* Perform a member lookup based on the class */
!       result = IndexerLookup(genInfo, classInfo, accessedFrom, &results);
        if(result != CS_SEMKIND_VOID)
        {
--- 1670,1675 ----
  
        /* Perform a member lookup based on the class */
!       result = IndexerLookup(genInfo, classInfo, accessedFrom, &results, 
!                                                       baseAccess);
        if(result != CS_SEMKIND_VOID)
        {





reply via email to

[Prev in Thread] Current Thread [Next in Thread]