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

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

[dotgnu-pnet-commits] [SCM] DotGNU Portable.NET engine, compilers and to


From: Klaus Treichel
Subject: [dotgnu-pnet-commits] [SCM] DotGNU Portable.NET engine, compilers and tools (pnet) branch, master, updated. 2ad1d8b6dfd91a47814dfdd09ac33f4ac76fd74d
Date: Sun, 28 Jun 2009 10:03:37 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "DotGNU Portable.NET engine, compilers and tools (pnet)".

The branch, master has been updated
       via  2ad1d8b6dfd91a47814dfdd09ac33f4ac76fd74d (commit)
      from  9fb1b2fbfdba2a1c29ef3bb14daa94189f30d64f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/pnet.git/commit/?id=2ad1d8b6dfd91a47814dfdd09ac33f4ac76fd74d

commit 2ad1d8b6dfd91a47814dfdd09ac33f4ac76fd74d
Author: Klaus Treichel <address@hidden>
Date:   Sun Jun 28 12:02:25 2009 +0200

    Add support for casting functions to delegates.

diff --git a/ChangeLog b/ChangeLog
index a9a7dcb..9ede381 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2009-06-28  Klaus Treichel  <address@hidden>
+
+       * codegen/cg_nodes.tc (ILParameterModifier): Add ILParamMod_methodgroup.
+
+       * cscc/csharp/cs_cast.tc (CSCastMethod): Add function to cast a function
+       to a delegate.
+       (ILNode_SemAnalysis(ILNode_UserCast)): Add support for casting a 
function
+       to a delegate.
+
+       * cscc/csharp/cs_invoke.tc (CSEvalArguments, CSItemIsCandidate): Handle
+       function arguments.
+
+       * cscc/csharp/cs_oper.tc (AssignSem): Handle function assignments.
+
 2009-06-13  Klaus Treichel  <address@hidden>
 
        * include/il_image.h (ILImageGetSectionSize, ILImageNumMetaEntries):
diff --git a/codegen/cg_nodes.tc b/codegen/cg_nodes.tc
index 224c8fa..ce14970 100644
--- a/codegen/cg_nodes.tc
+++ b/codegen/cg_nodes.tc
@@ -98,6 +98,7 @@ typedef struct _tagILEvalValue ILEvalValue;
        ILParamMod_out,
        ILParamMod_params,
        ILParamMod_arglist,
+       ILParamMod_methodgroup
 }
 
 /*
diff --git a/cscc/csharp/cs_cast.tc b/cscc/csharp/cs_cast.tc
index 26c77e6..e9d2384 100644
--- a/cscc/csharp/cs_cast.tc
+++ b/cscc/csharp/cs_cast.tc
@@ -25,6 +25,14 @@
  */
 const char *CSTypeToName(ILType *type);
 
+#if IL_VERSION_MAJOR > 1
+/*
+ * Cast a method group to a delegate type.
+ */
+int CSCastMethod(ILGenInfo *info, ILNode *node, ILNode **parent,
+                                void *method, ILType *toType, int reportError);
+#endif /* IL_VERSION_MAJOR > 1 */
+
 %}
 
 /*
@@ -42,6 +50,18 @@ ILNode_SemAnalysis(ILNode_UserCast)
        value = ILNode_SemAnalysis(node->expr2, info, &(node->expr2));
 
        /* Validate the value */
+#if IL_VERSION_MAJOR > 1
+       if(CSSemIsMethodGroup(value))
+       {
+               if(CSSemIsType(type))
+               {
+                       CSCastMethod(info, node->expr2, parent, 
CSSemGetGroup(value), CSSemGetType(type), 1);
+                       CSSemSetRValue(value, CSSemGetType(type));
+                       return value;
+               }
+       }
+       else
+#endif /* IL_VERSION_MAJOR > 1 */
        if(!CSSemIsValue(value))
        {
                CCErrorOnLine(yygetfilename(node->expr2), 
yygetlinenum(node->expr2),
@@ -389,5 +409,99 @@ const char *CSTypeToName(ILType *type)
        return "invalid type";
 }
 
+#if IL_VERSION_MAJOR > 1
+int CSCastMethod(ILGenInfo *info, ILNode *node, ILNode **parent,
+                                void *method, ILType *toType, int reportError)
+{
+       unsigned long itemNum;
+       ILProgramItem *itemInfo;
+       ILMethod *firstMatch;
+
+       if(!ILTypeIsDelegate(toType))
+       {
+               if(reportError)
+               {
+                       CCErrorOnLine(yygetfilename(node), yygetlinenum(node),
+                       "the type casted to `%s' is no delegate", 
CSTypeToName(toType));
+               }
+               return 0;
+       }
+
+       /* Find the set of candidate methods */
+       itemNum = 0;
+       firstMatch = 0;
+       while((itemInfo = CSGetGroupMember(method, itemNum)) != 0)
+       {
+               if(ILTypeDelegateSignatureMatch(toType, itemInfo))
+               {
+                       if(firstMatch)
+                       {
+                               /* We have two (or possibly more) matches for 
the delegate */
+                               if(reportError)
+                               {
+                                               
CCErrorOnLine(yygetfilename(node), yygetlinenum(node),
+                                                 "delegate expression supplies 
multiple candidates for `%s'",
+                                                 CSTypeToName(toType));
+                               }
+                               return 0;
+                       }
+                       firstMatch = (ILMethod *)itemInfo;
+               }
+               ++itemNum;
+       }
+
+       /* If there was no candidates found then bail out */
+       if(!firstMatch)
+       {
+               /* We weren't able to find a match for the delegate */
+               if(reportError)
+               {
+                       CCErrorOnLine(yygetfilename(node), yygetlinenum(node),
+                                 "delegate expression is not compatible with 
`%s'",
+                                 CSTypeToName(toType));
+               }
+               return 0;
+       }
+
+       /* Build the DelegateCreationExpression node */
+       if(ILMethod_IsStatic(firstMatch))
+       {
+               *parent = ILNode_DelegateCreationExpression_create
+                       (ILType_ToClass(toType), 0, firstMatch);
+       }
+       else
+       {
+               if(yyisa(node, ILNode_Argument))
+               {
+                       ILNode *thisExpr;
+
+                       thisExpr = ((ILNode_Argument*)(node))->expression;
+                       if(yyisa(thisExpr, ILNode_This) ||
+                         (yyisa(thisExpr, ILNode_MarkType) &&
+                          yyisa(((ILNode_MarkType *)(thisExpr))->expr, 
ILNode_This)))
+                       {
+                               ILNode_MethodDeclaration *caller;
+
+                               caller = (ILNode_MethodDeclaration 
*)(info->currentMethod);
+                               if(!caller || 
+                                       (caller->modifiers & 
IL_META_METHODDEF_STATIC) != 0)
+                               {
+                                       /* Attempt to call an instance method 
using "this"
+                                          from within a static method */
+                                       CCErrorOnLine(yygetfilename(node), 
yygetlinenum(node),
+                                                 "cannot access instance 
members in static methods");
+                               }
+                       }
+               }
+               *parent = ILNode_DelegateCreationExpression_create
+                       (ILType_ToClass(toType), node, firstMatch);
+       }
+       yysetfilename(*parent, yygetfilename(node));
+       yysetlinenum(*parent, yygetlinenum(node));
+
+       return 1;
+}
+#endif /* IL_VERSION_MAJOR > 1 */
+
 %}
 
diff --git a/cscc/csharp/cs_invoke.tc b/cscc/csharp/cs_invoke.tc
index 5f17eff..fd28110 100644
--- a/cscc/csharp/cs_invoke.tc
+++ b/cscc/csharp/cs_invoke.tc
@@ -1231,17 +1231,28 @@ int CSEvalArguments(ILGenInfo *info, ILNode *argList,
                /* Populate the argument array element */
                if(!yyisa(tempList, ILNode_Argument) ||
                   !yyisa(((ILNode_Argument *)tempList)->expression,
-                                 ILNode_VarArgExpand))
+                                 ILNode_VarArgExpand))
                {
                        /* Ordinary argument */
                        value = ILNode_SemAnalysis(tempList, info, tempParent);
                        argArray[argNum].node = *tempParent;
                        argArray[argNum].parent = tempParent;
-                       argArray[argNum].modifier = GetParamModForArg(tempList);
                        if(CSSemIsValue(value))
                        {
+                               argArray[argNum].modifier = 
GetParamModForArg(tempList);
                                argArray[argNum].type = CSSemGetType(value);
                        }
+#if IL_VERSION_MAJOR > 1
+                       else if(CSSemIsMethodGroup(value))
+                       {
+                               /*
+                                * This is an ugly hack to get a method group 
to the
+                                * eval value. This should be fixed later.
+                                */
+                               argArray[argNum].modifier = 
ILParamMod_methodgroup;
+                               argArray[argNum].type = (ILType 
*)CSSemGetGroup(value);
+                       }
+#endif /* IL_VERSION_MAJOR > 1 */
                        else
                        {
                                argArray[argNum].type = ILType_Void;
@@ -1549,8 +1560,24 @@ int CSItemIsCandidate(ILGenInfo *info, ILProgramItem 
*item,
                }
                else if(paramMod != args[argNum].modifier)
                {
-                       /* Incorrect modifiers */
-                       return 0;
+#if IL_VERSION_MAJOR > 1
+                       if((args[argNum].modifier == ILParamMod_methodgroup) &&
+                          (paramMod == ILParamMod_empty))
+                       {
+                               /* Check if the method should be casted to a 
delegate */
+                               if(!CSCastMethod(info, args[argNum].node, 
args[argNum].parent,
+                                                                (void 
*)(args[argNum].type), paramType, 0))
+                               {
+                                       return 0;
+                               }
+                               ++paramNum;
+                       }
+                       else
+#endif /* IL_VERSION_MAJOR > 1 */
+                       {
+                               /* Incorrect modifiers */
+                               return 0;
+                       }
                }
                else if(paramMod == ILParamMod_empty)
                {
diff --git a/cscc/csharp/cs_oper.tc b/cscc/csharp/cs_oper.tc
index 5d1eda2..487763c 100644
--- a/cscc/csharp/cs_oper.tc
+++ b/cscc/csharp/cs_oper.tc
@@ -1049,7 +1049,7 @@ ILNode_SemAnalysis(ILNode_Assign)
        /* Perform semantic analysis and coercion on the rvalue */
        if(!CSSemExpectValue(node->expr2, info, &(node->expr2), &value2) ||
           !ILCanCoerceNode(info, node->expr2, CSSemGetType(value2),
-                                               CSSemGetType(value1),1))
+                                               CSSemGetType(value1),1))
        {
                CCErrorOnLine(yygetfilename(node), yygetlinenum(node),
                  "incompatible types in assignment: no conversion from `%s' to 
`%s'",
@@ -1219,7 +1219,18 @@ static CSSemValue AssignSem(ILGenInfo *info,
                return value1;
        }
 
-       /* The second argument must be a value */
+#if IL_VERSION_MAJOR > 1
+       if(CSSemIsMethodGroup(value2))
+       {
+               if(!CSCastMethod(info, node->expr2, &(node->expr2),
+                                                CSSemGetGroup(value2), 
CSSemGetType(value1), 1))
+               {
+                       goto error;
+               }
+               CSSemSetRValue(value2, CSSemGetType(value1));
+       }
+       else
+#endif /* IL_VERSION_MAJOR > 1 */
        if(!CSSemIsValue(value2))
        {
                goto error;

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                |   14 ++++++
 codegen/cg_nodes.tc      |    1 +
 cscc/csharp/cs_cast.tc   |  114 ++++++++++++++++++++++++++++++++++++++++++++++
 cscc/csharp/cs_invoke.tc |   35 ++++++++++++--
 cscc/csharp/cs_oper.tc   |   15 +++++-
 5 files changed, 173 insertions(+), 6 deletions(-)


hooks/post-receive
-- 
DotGNU Portable.NET engine, compilers and tools (pnet)




reply via email to

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