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. 05fc39b5cc7d675a627efbcce21f04b73d781a58
Date: Tue, 26 Apr 2011 15:10:01 +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  05fc39b5cc7d675a627efbcce21f04b73d781a58 (commit)
      from  9d1be11f641d84e58453e33e5fbf1d85518ad24a (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=05fc39b5cc7d675a627efbcce21f04b73d781a58

commit 05fc39b5cc7d675a627efbcce21f04b73d781a58
Author: Klaus Treichel <address@hidden>
Date:   Tue Apr 26 17:09:43 2011 +0200

    Move some coder helper functions from verifier to coder.

diff --git a/ChangeLog b/ChangeLog
index 1c5adb8..e76d112 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2011-04-26  Klaus Treichel  <address@hidden>
+
+       * engine/coder.c (NestExceptionBlocks): Move from verify.c to here.
+       (InsertExceptionBlock): likewise
+       (FindOrAddTryBlock): likewise
+       (AddHandlerBlock): likewise
+       (_ILCoderAddExceptionBlock): Move AddExceptionBlock from verify.c to
+       here.
+       (_ILCoderFindExceptionBlock): Move FindExceptionBlock from 
verify_except.c
+       to here.
+       (_ILCoderThrowSystem): Move _ThrowSystem from verify_except.c to here.
+
+       * engine/coder.h: Move definitiona of IL_VERIFY_* returncodes from
+       verify.c and change the prefix to IL_CODER_.
+       Add prototypes for the moved _ILCoder functions.
+
+       * engine/verify.c: Move exception related functions to coder.c and 
adjust
+       their usages to call the moved functions.
+
+       * engine/verify_except.c (FindExceptionBlock): Move  to coder.c.
+       (_ThrowSystem): Move to coder.c
+       Adjust usages of the moved functions.
+
 2011-04-14  Klaus Treichel  <address@hidden>
 
        * engine/cvm_call.c (_ILPackCVMStackArgs): Remove unused variable x.
diff --git a/engine/coder.c b/engine/coder.c
index 9a4be1f..2cf9e9c 100644
--- a/engine/coder.c
+++ b/engine/coder.c
@@ -259,6 +259,422 @@ int _ILCoderBoxPtr(ILExecProcess *process, ILType 
*typeInfo,
        return 0;
 }
 
+static int NestExceptionBlocks(ILCoderExceptionBlock *block,
+                                                          
ILCoderExceptionBlock *prevEB,
+                                                          
ILCoderExceptionBlock *firstNestedEB,
+                                                          
ILCoderExceptionBlock **firstEB)
+{
+       ILCoderExceptionBlock *lastNestedEB;
+       ILCoderExceptionBlock *nextEB;
+
+       block->nested = firstNestedEB;
+       block->parent = firstNestedEB->parent;
+       firstNestedEB->parent = block;
+       lastNestedEB = firstNestedEB;
+       nextEB = firstNestedEB->nextNested;
+       while(nextEB)
+       {
+               if(block->endOffset <= nextEB->startOffset)
+               {
+                       /*
+                        * The next block is not nested in the current block.
+                        */
+                       break;
+               }
+               if(block->endOffset >= nextEB->endOffset)
+               {
+                       /*
+                        * The next block is nested in the current block too.
+                        */
+                       nextEB->parent = block;
+                       lastNestedEB = nextEB;
+               }
+               else
+               {
+                       /* Partially overlapping blocks are not allowed */
+                       return 0;
+               }
+               nextEB = nextEB->nextNested;
+       }
+       block->nextNested = lastNestedEB->nextNested;
+       lastNestedEB->nextNested = 0;
+       if(prevEB)
+       {
+               prevEB->nextNested = block;
+       }
+       else
+       {
+               if(block->parent)
+               {
+                       nextEB = block->parent;
+                       nextEB->nested = block;
+               }
+               else
+               {
+                       nextEB = *firstEB;
+                       *firstEB = block;
+               }
+       }
+       return 1;
+}
+
+static int InsertExceptionBlock(ILCoderExceptions *coderExceptions,
+                                                               
ILCoderExceptionBlock *block)
+{
+       ILCoderExceptionBlock *prevEB;
+       ILCoderExceptionBlock *checkEB;
+
+       prevEB = 0;
+       checkEB = coderExceptions->firstBlock;
+       while(checkEB)
+       {
+               if(block->endOffset <= checkEB->startOffset)
+               {
+                       /* The current block is before the check block */
+                       if(prevEB)
+                       {
+                               block->nextNested = prevEB->nextNested;
+                               prevEB->nextNested = block;
+                               block->parent = prevEB->parent;
+                       }
+                       else
+                       {
+                               if(checkEB->parent)
+                               {
+                                       checkEB = checkEB->parent;
+                                       block->nextNested = checkEB->nested;
+                                       checkEB->nested = block;
+                                       block->parent = checkEB;
+                               }
+                               else
+                               {
+                                       block->nextNested = 
coderExceptions->firstBlock;
+                                       coderExceptions->firstBlock = block;
+                               }
+                       }
+                       break;
+               }
+               else if(block->startOffset >= checkEB->endOffset)
+               {
+                       /*
+                        * The current block starts after the check block.
+                        */
+                       if(checkEB->nextNested)
+                       {
+                               prevEB = checkEB;
+                               checkEB = checkEB->nextNested;
+                       }
+                       else
+                       {
+                               checkEB->nextNested = block;
+                               block->parent = checkEB->parent;
+                               break;
+                       }
+               }
+               else if(block->startOffset <= checkEB->startOffset &&
+                               block->endOffset >= checkEB->endOffset)
+               {
+                       /*
+                        * The current block encloses the check block.
+                        */
+                       if(!NestExceptionBlocks(block, prevEB, checkEB,
+                                                                       
&(coderExceptions->firstBlock)))
+                       {
+                               return 0;
+                       }
+                       break;
+               }
+               else if(block->startOffset >= checkEB->startOffset &&
+                               block->endOffset <= checkEB->endOffset)
+               {
+                       /*
+                        * The current try block is nested in the check try 
block.
+                        */
+                       if(checkEB->nested)
+                       {
+                               prevEB = 0;
+                               checkEB = checkEB->nested;
+                       }
+                       else
+                       {
+                               checkEB->nested = block;
+                               block->parent = checkEB;
+                               break;
+                       }
+               }
+               else
+               {
+                       /*
+                        * Partially overlapping blocks are not allowed.
+                        */
+                       return 0;
+               }
+       }
+       return 1;
+}
+
+static ILCoderExceptionBlock *FindOrAddTryBlock(ILCoderExceptions 
*coderExceptions,
+                                                                               
                ILUInt32 tryStart, ILUInt32 tryEnd)
+{
+       ILCoderExceptionBlock *block;
+       ILUInt32 current;
+       
+       current = 0;
+       while(current < coderExceptions->numBlocks)
+       {
+               block = &(coderExceptions->blocks[current]);
+               if((block->startOffset == tryStart) && (block->endOffset == 
tryEnd) &&
+                       (block->flags == IL_CODER_HANDLER_TYPE_TRY))
+               {
+                       return block;
+               }
+               ++current;
+       }
+       /* If we get here no matching try block was found */
+       block = &(coderExceptions->blocks[coderExceptions->numBlocks++]);
+       block->flags = IL_CODER_HANDLER_TYPE_TRY;
+       block->startOffset = tryStart;
+       block->endOffset = tryEnd;
+       block->un.tryBlock.handlerBlock = 0;
+       block->parent = 0;
+       block->nested = 0;
+       block->nextNested = 0;
+
+       /*
+        * Now insert the new try block at it's place in the exception block
+        * structure
+        */
+       if(!coderExceptions->firstBlock)
+       {
+               coderExceptions->firstBlock = block;
+       }
+       else
+       {
+               if(!InsertExceptionBlock(coderExceptions, block))
+               {
+                       --coderExceptions->numBlocks;
+                       return 0;
+               }
+       }
+       return block;
+}
+
+static void AddHandlerBlock(ILCoderExceptionBlock *tryBlock,
+                                                       ILCoderExceptionBlock 
*handler)
+{
+       if(!tryBlock->un.tryBlock.handlerBlock)
+       {
+               tryBlock->un.tryBlock.handlerBlock = handler;
+       }
+       else
+       {
+               ILCoderExceptionBlock *nextHandler;
+
+               nextHandler = tryBlock->un.tryBlock.handlerBlock;
+               while(nextHandler)
+               {
+                       if(!nextHandler->un.handlerBlock.nextHandler)
+                       {
+                               nextHandler->un.handlerBlock.nextHandler = 
handler;
+                               break;
+                       }
+                       nextHandler = nextHandler->un.handlerBlock.nextHandler;
+               }
+       }
+}
+
+int _ILCoderAddExceptionBlock(ILCoderExceptions *coderExceptions,
+                                                         ILMethod *method, 
ILException *exception)
+{
+       ILCoderExceptionBlock *tryBlock;
+       ILCoderExceptionBlock *handler;
+       ILUInt32 startOffset;
+       ILUInt32 endOffset;
+
+       startOffset = exception->tryOffset;
+       endOffset = exception->tryOffset + exception->tryLength;
+       if(endOffset < startOffset)
+       {
+               return IL_CODER_BRANCH_ERR;
+       }
+       /*
+        * Find the try block for this exception handler.
+        */
+       tryBlock = FindOrAddTryBlock(coderExceptions, startOffset, endOffset);
+       if(!tryBlock)
+       {
+               return IL_CODER_BRANCH_ERR;
+       }
+
+       startOffset = exception->handlerOffset;
+       endOffset = exception->handlerOffset + exception->handlerLength;
+       if(endOffset < startOffset)
+       {
+               return IL_CODER_BRANCH_ERR;
+       }
+
+       /*
+        * Allocate a new handler block.
+        */
+       handler = &(coderExceptions->blocks[coderExceptions->numBlocks++]);
+       handler->startOffset = startOffset;
+       handler->endOffset = endOffset;
+       handler->parent = 0;
+       handler->nested = 0;
+       handler->nextNested = 0;
+       handler->startLabel = 0;
+       handler->handlerLabel = 0;
+       if(exception->flags & (IL_META_EXCEPTION_FINALLY | 
IL_META_EXCEPTION_FAULT))
+       {
+               /*
+                * A finally or fault handler.
+                */
+               if(exception->flags & IL_META_EXCEPTION_FINALLY)
+               {
+                       handler->flags = IL_CODER_HANDLER_TYPE_FINALLY;
+               }
+               else
+               {
+                       handler->flags = IL_CODER_HANDLER_TYPE_FAULT;
+               }
+               handler->un.handlerBlock.nextHandler = 0;
+               handler->un.handlerBlock.filterBlock = 0;
+               handler->un.handlerBlock.exceptionClass = 0;
+               handler->un.handlerBlock.tryBlock = tryBlock;;
+       }
+       else
+       {
+               handler->un.handlerBlock.nextHandler = 0;
+               handler->un.handlerBlock.tryBlock = tryBlock;;
+               if(exception->flags & IL_META_EXCEPTION_FILTER)
+               {
+                       /*
+                        * A catch block with filter.
+                        */
+                       ILCoderExceptionBlock *filterBlock;
+
+                       filterBlock = 
&(coderExceptions->blocks[coderExceptions->numBlocks++]);
+                       filterBlock->flags = IL_CODER_HANDLER_TYPE_FILTER;
+                       filterBlock->startOffset = exception->extraArg;
+                       filterBlock->endOffset = exception->handlerOffset;
+                       filterBlock->parent = 0;
+                       filterBlock->nested = 0;
+                       filterBlock->nextNested = 0;
+                       filterBlock->startLabel = 0;
+                       filterBlock->handlerLabel = 0;
+                       if(!InsertExceptionBlock(coderExceptions, filterBlock))
+                       {
+                               return IL_CODER_BRANCH_ERR;
+                       }
+                       handler->flags = IL_CODER_HANDLER_TYPE_FILTEREDCATCH;
+                       handler->un.handlerBlock.filterBlock = filterBlock;
+                       handler->un.handlerBlock.exceptionClass = 0;
+               }
+               else
+               {
+                       /*
+                        * A catch block.
+                        */
+                       ILClass *classInfo;
+                       ILProgramItem *item;
+
+                       handler->flags = IL_CODER_HANDLER_TYPE_CATCH;
+                       handler->un.handlerBlock.filterBlock = 0;
+
+                       /* Validate the class token */
+                       item = ((ILProgramItem 
*)ILImageTokenInfo(ILProgramItem_Image(method),
+                                                                               
                          exception->extraArg));
+                       classInfo = ILProgramItemToClass(item);
+                       if(!classInfo ||
+                          !ILClassAccessible(classInfo, 
ILMethod_Owner(method)))
+                       {
+                               return IL_CODER_TYPE_ERR;
+                       }
+                       handler->un.handlerBlock.exceptionClass = classInfo;
+               }
+       }
+       if(!InsertExceptionBlock(coderExceptions, handler))
+       {
+               return IL_CODER_BRANCH_ERR;
+       }
+       AddHandlerBlock(tryBlock, handler);
+       return IL_CODER_OK;
+}
+
+ILCoderExceptionBlock *_ILCoderFindExceptionBlock(ILCoderExceptions 
*coderExceptions,
+                                                                               
                  ILUInt32 offset)
+{
+       ILCoderExceptionBlock *block;
+       ILCoderExceptionBlock *prevEB;
+
+       prevEB = 0;
+       block = coderExceptions->firstBlock;
+       while(block)
+       {
+               if(offset < block->startOffset)
+               {
+                       break;
+               }
+               else if(offset >= block->endOffset)
+               {
+                       block = block->nextNested;
+               }
+               else
+               {
+                       prevEB = block;
+                       block = block->nested;
+               }
+       }
+       return prevEB;
+}
+
+/*
+ * Emit code to throw a system-level exception.
+ * Returns IL_CODER_OK on success or IL_CODER_TYPE_ERR if the exception
+ * or it's constructor could not be resolved.
+ */
+int _ILCoderThrowSystem(ILCoder *coder, ILMethod *method,
+                                               const char *name, const char 
*namespace)
+{
+       ILClass *classInfo;
+       ILMethod *ctor;
+       ILCoderMethodInfo callInfo;
+
+       /* Find the no-argument constructor for the class */
+       classInfo = ILClassResolveSystem(ILProgramItem_Image(method), 0,
+                                                                    name, 
namespace);
+       if(!classInfo)
+       {
+               return IL_CODER_TYPE_ERR;
+       }
+       ctor = 0;
+       while((ctor = (ILMethod *)ILClassNextMemberByKind
+                       (classInfo, (ILMember *)ctor, 
IL_META_MEMBERKIND_METHOD)) != 0)
+       {
+               if(ILMethod_IsConstructor(ctor) &&
+                  ILTypeNumParams(ILMethod_Signature(ctor)) == 0)
+               {
+                       break;
+               }
+       }
+       if(!ctor)
+       {
+               return IL_CODER_TYPE_ERR;
+       }
+
+       /* Invoke the constructor */
+       callInfo.args = 0;
+       callInfo.numBaseArgs = 0;
+       callInfo.numVarArgs = 0;
+       callInfo.hasParamArray = 0;
+       ILCoderCallCtor(coder, &callInfo, ctor);
+
+       /* Set the stack trace & throw the object */
+       ILCoderSetStackTrace(coder);
+       ILCoderThrow(coder, 0);
+       return IL_CODER_OK;
+}
+
 #ifdef __cplusplus
 };
 #endif
diff --git a/engine/coder.h b/engine/coder.h
index 2bb0ba1..db8ff78 100644
--- a/engine/coder.h
+++ b/engine/coder.h
@@ -26,6 +26,13 @@ extern       "C" {
 #endif
 
 /*
+ * Some error codes used during verification
+ */
+#define IL_CODER_OK                            0
+#define IL_CODER_BRANCH_ERR            1
+#define IL_CODER_TYPE_ERR              2
+
+/*
  * Get the type of a parameter to the current method.
  * Returns 0 if the parameter number is invalid.
  */
@@ -61,6 +68,31 @@ int _ILCoderBoxValue(ILExecProcess *process, ILEngineType 
valueType,
 int _ILCoderBoxPtr(ILExecProcess *process, ILType *typeInfo, 
                                   ILClass *boxClass, ILUInt32 pos);
 
+/*
+ * Add an IL exception block to the coder exception blocks.
+ * Returns IL_VERIFY_OK on success or IL_VERIFY_BRANCH_ERR if something is
+ * wrong with the offsets for example start > end or the block oberlaps
+ * with an existing block so that the block is neither completely nested
+ * in the block or surrounds the exicting block or vice versa.
+ */
+int _ILCoderAddExceptionBlock(ILCoderExceptions *coderExceptions,
+                                                         ILMethod *method, 
ILException *exception);
+
+/*
+ * Find the most nested exception block where an offset is located.
+ * Returns NULL if no such exception block could be found.
+ */
+ILCoderExceptionBlock *_ILCoderFindExceptionBlock(ILCoderExceptions 
*coderExceptions,
+                                                                               
                  ILUInt32 offset);
+
+/*
+ * Emit code to throw a system-level exception.
+ * Returns IL_CODER_OK on success or IL_CODER_TYPE_ERR if the exception
+ * or it's constructor could not be resolved.
+ */
+int _ILCoderThrowSystem(ILCoder *coder, ILMethod *method,
+                                               const char *name, const char 
*namespace);
+
 #ifdef __cplusplus
 };
 #endif
diff --git a/engine/verify.c b/engine/verify.c
index 5a978c3..25908c7 100644
--- a/engine/verify.c
+++ b/engine/verify.c
@@ -35,13 +35,6 @@ extern       "C" {
 #endif
 
 /*
- * Some error codes used during verification
- */
-#define IL_VERIFY_OK                   0
-#define IL_VERIFY_BRANCH_ERR   1
-#define IL_VERIFY_TYPE_ERR             2
-
-/*
  * Temporary memory allocator.
  */
 typedef struct
@@ -642,352 +635,6 @@ static int IsSubClass(ILType *type, ILClass *classInfo)
        }
 }
 
-static int
-NestExceptionBlocks(ILCoderExceptionBlock *block,
-                                       ILCoderExceptionBlock *prevEB,
-                                       ILCoderExceptionBlock *firstNestedEB,
-                                       ILCoderExceptionBlock **firstEB)
-{
-       ILCoderExceptionBlock *lastNestedEB;
-       ILCoderExceptionBlock *nextEB;
-
-       block->nested = firstNestedEB;
-       block->parent = firstNestedEB->parent;
-       firstNestedEB->parent = block;
-       lastNestedEB = firstNestedEB;
-       nextEB = firstNestedEB->nextNested;
-       while(nextEB)
-       {
-               if(block->endOffset <= nextEB->startOffset)
-               {
-                       /*
-                        * The next block is not nested in the current block.
-                        */
-                       break;
-               }
-               if(block->endOffset >= nextEB->endOffset)
-               {
-                       /*
-                        * The next block is nested in the current block too.
-                        */
-                       nextEB->parent = block;
-                       lastNestedEB = nextEB;
-               }
-               else
-               {
-                       /* Partially overlapping blocks are not allowed */
-                       return 0;
-               }
-               nextEB = nextEB->nextNested;
-       }
-       block->nextNested = lastNestedEB->nextNested;
-       lastNestedEB->nextNested = 0;
-       if(prevEB)
-       {
-               prevEB->nextNested = block;
-       }
-       else
-       {
-               if(block->parent)
-               {
-                       nextEB = block->parent;
-                       nextEB->nested = block;
-               }
-               else
-               {
-                       nextEB = *firstEB;
-                       *firstEB = block;
-               }
-       }
-       return 1;
-}
-
-static int
-InsertExceptionBlock(ILCoderExceptions *coderExceptions,
-                                        ILCoderExceptionBlock *block)
-{
-       ILCoderExceptionBlock *prevEB;
-       ILCoderExceptionBlock *checkEB;
-
-       prevEB = 0;
-       checkEB = coderExceptions->firstBlock;
-       while(checkEB)
-       {
-               if(block->endOffset <= checkEB->startOffset)
-               {
-                       /* The current block is before the check block */
-                       if(prevEB)
-                       {
-                               block->nextNested = prevEB->nextNested;
-                               prevEB->nextNested = block;
-                               block->parent = prevEB->parent;
-                       }
-                       else
-                       {
-                               if(checkEB->parent)
-                               {
-                                       checkEB = checkEB->parent;
-                                       block->nextNested = checkEB->nested;
-                                       checkEB->nested = block;
-                                       block->parent = checkEB;
-                               }
-                               else
-                               {
-                                       block->nextNested = 
coderExceptions->firstBlock;
-                                       coderExceptions->firstBlock = block;
-                               }
-                       }
-                       break;
-               }
-               else if(block->startOffset >= checkEB->endOffset)
-               {
-                       /*
-                        * The current block starts after the check block.
-                        */
-                       if(checkEB->nextNested)
-                       {
-                               prevEB = checkEB;
-                               checkEB = checkEB->nextNested;
-                       }
-                       else
-                       {
-                               checkEB->nextNested = block;
-                               block->parent = checkEB->parent;
-                               break;
-                       }
-               }
-               else if(block->startOffset <= checkEB->startOffset &&
-                               block->endOffset >= checkEB->endOffset)
-               {
-                       /*
-                        * The current block encloses the check block.
-                        */
-                       if(!NestExceptionBlocks(block, prevEB, checkEB,
-                                                                       
&(coderExceptions->firstBlock)))
-                       {
-                               return 0;
-                       }
-                       break;
-               }
-               else if(block->startOffset >= checkEB->startOffset &&
-                               block->endOffset <= checkEB->endOffset)
-               {
-                       /*
-                        * The current try block is nested in the check try 
block.
-                        */
-                       if(checkEB->nested)
-                       {
-                               prevEB = 0;
-                               checkEB = checkEB->nested;
-                       }
-                       else
-                       {
-                               checkEB->nested = block;
-                               block->parent = checkEB;
-                               break;
-                       }
-               }
-               else
-               {
-                       /*
-                        * Partially overlapping blocks are not allowed.
-                        */
-                       return 0;
-               }
-       }
-       return 1;
-}
-
-static ILCoderExceptionBlock *
-FindOrAddTryBlock(ILCoderExceptions *coderExceptions,
-                                 ILUInt32 tryStart, ILUInt32 tryEnd)
-{
-       ILCoderExceptionBlock *block;
-       ILUInt32 current;
-       
-       current = 0;
-       while(current < coderExceptions->numBlocks)
-       {
-               block = &(coderExceptions->blocks[current]);
-               if((block->startOffset == tryStart) && (block->endOffset == 
tryEnd) &&
-                       (block->flags == IL_CODER_HANDLER_TYPE_TRY))
-               {
-                       return block;
-               }
-               ++current;
-       }
-       /* If we get here no matching try block was found */
-       block = &(coderExceptions->blocks[coderExceptions->numBlocks++]);
-       block->flags = IL_CODER_HANDLER_TYPE_TRY;
-       block->startOffset = tryStart;
-       block->endOffset = tryEnd;
-       block->un.tryBlock.handlerBlock = 0;
-       block->parent = 0;
-       block->nested = 0;
-       block->nextNested = 0;
-
-       /*
-        * Now insert the new try block at it's place in the exception block
-        * structure
-        */
-       if(!coderExceptions->firstBlock)
-       {
-               coderExceptions->firstBlock = block;
-       }
-       else
-       {
-               if(!InsertExceptionBlock(coderExceptions, block))
-               {
-                       --coderExceptions->numBlocks;
-                       return 0;
-               }
-       }
-       return block;
-}
-
-static void
-AddHandlerBlock(ILCoderExceptionBlock *tryBlock, ILCoderExceptionBlock 
*handler)
-{
-       if(!tryBlock->un.tryBlock.handlerBlock)
-       {
-               tryBlock->un.tryBlock.handlerBlock = handler;
-       }
-       else
-       {
-               ILCoderExceptionBlock *nextHandler;
-
-               nextHandler = tryBlock->un.tryBlock.handlerBlock;
-               while(nextHandler)
-               {
-                       if(!nextHandler->un.handlerBlock.nextHandler)
-                       {
-                               nextHandler->un.handlerBlock.nextHandler = 
handler;
-                               break;
-                       }
-                       nextHandler = nextHandler->un.handlerBlock.nextHandler;
-               }
-       }
-}
-
-static int
-AddExceptionBlock(ILCoderExceptions *coderExceptions,
-                                 ILMethod *method, ILException *exception)
-{
-       ILCoderExceptionBlock *tryBlock;
-       ILCoderExceptionBlock *handler;
-       ILUInt32 startOffset;
-       ILUInt32 endOffset;
-
-       startOffset = exception->tryOffset;
-       endOffset = exception->tryOffset + exception->tryLength;
-       if(endOffset < startOffset)
-       {
-               return IL_VERIFY_BRANCH_ERR;
-       }
-       /*
-        * Find the try block for this exception handler.
-        */
-       tryBlock = FindOrAddTryBlock(coderExceptions, startOffset, endOffset);
-       if(!tryBlock)
-       {
-               return IL_VERIFY_BRANCH_ERR;
-       }
-
-       startOffset = exception->handlerOffset;
-       endOffset = exception->handlerOffset + exception->handlerLength;
-       if(endOffset < startOffset)
-       {
-               return IL_VERIFY_BRANCH_ERR;
-       }
-
-       /*
-        * Allocate a new handler block.
-        */
-       handler = &(coderExceptions->blocks[coderExceptions->numBlocks++]);
-       handler->startOffset = startOffset;
-       handler->endOffset = endOffset;
-       handler->parent = 0;
-       handler->nested = 0;
-       handler->nextNested = 0;
-       handler->startLabel = 0;
-       handler->handlerLabel = 0;
-       if(exception->flags & (IL_META_EXCEPTION_FINALLY | 
IL_META_EXCEPTION_FAULT))
-       {
-               /*
-                * A finally or fault handler.
-                */
-               if(exception->flags & IL_META_EXCEPTION_FINALLY)
-               {
-                       handler->flags = IL_CODER_HANDLER_TYPE_FINALLY;
-               }
-               else
-               {
-                       handler->flags = IL_CODER_HANDLER_TYPE_FAULT;
-               }
-               handler->un.handlerBlock.nextHandler = 0;
-               handler->un.handlerBlock.filterBlock = 0;
-               handler->un.handlerBlock.exceptionClass = 0;
-               handler->un.handlerBlock.tryBlock = tryBlock;;
-       }
-       else
-       {
-               handler->un.handlerBlock.nextHandler = 0;
-               handler->un.handlerBlock.tryBlock = tryBlock;;
-               if(exception->flags & IL_META_EXCEPTION_FILTER)
-               {
-                       /*
-                        * A catch block with filter.
-                        */
-                       ILCoderExceptionBlock *filterBlock;
-
-                       filterBlock = 
&(coderExceptions->blocks[coderExceptions->numBlocks++]);
-                       filterBlock->flags = IL_CODER_HANDLER_TYPE_FILTER;
-                       filterBlock->startOffset = exception->extraArg;
-                       filterBlock->endOffset = exception->handlerOffset;
-                       filterBlock->parent = 0;
-                       filterBlock->nested = 0;
-                       filterBlock->nextNested = 0;
-                       filterBlock->startLabel = 0;
-                       filterBlock->handlerLabel = 0;
-                       if(!InsertExceptionBlock(coderExceptions, filterBlock))
-                       {
-                               return IL_VERIFY_BRANCH_ERR;
-                       }
-                       handler->flags = IL_CODER_HANDLER_TYPE_FILTEREDCATCH;
-                       handler->un.handlerBlock.filterBlock = filterBlock;
-                       handler->un.handlerBlock.exceptionClass = 0;
-               }
-               else
-               {
-                       /*
-                        * A catch block.
-                        */
-                       ILClass *classInfo;
-                       ILProgramItem *item;
-
-                       handler->flags = IL_CODER_HANDLER_TYPE_CATCH;
-                       handler->un.handlerBlock.filterBlock = 0;
-
-                       /* Validate the class token */
-                       item = ((ILProgramItem 
*)ILImageTokenInfo(ILProgramItem_Image(method),
-                                                                               
                          exception->extraArg));
-                       classInfo = ILProgramItemToClass(item);
-                       if(!classInfo ||
-                          !ILClassAccessible(classInfo, 
ILMethod_Owner(method)))
-                       {
-                               return IL_VERIFY_TYPE_ERR;
-                       }
-                       handler->un.handlerBlock.exceptionClass = classInfo;
-               }
-       }
-       if(!InsertExceptionBlock(coderExceptions, handler))
-       {
-               return IL_VERIFY_BRANCH_ERR;
-       }
-       AddHandlerBlock(tryBlock, handler);
-       return IL_VERIFY_OK;
-}
-
 /*
  * Push the appropriate synchronization object for a synchronized method.
  */
@@ -1181,15 +828,16 @@ int _ILVerify(ILCoder *coder, unsigned char **start, 
ILMethod *method,
                exception = exceptions;
                while(exception)
                {
-                       switch(AddExceptionBlock(&coderExceptions, method, 
exception))
+                       switch(_ILCoderAddExceptionBlock(&coderExceptions, 
method,
+                                                                               
         exception))
                        {
-                               case IL_VERIFY_BRANCH_ERR:
+                               case IL_CODER_BRANCH_ERR:
                                {
                                        VERIFY_BRANCH_ERROR();
                                }
                                break;
 
-                               case IL_VERIFY_TYPE_ERR:
+                               case IL_CODER_TYPE_ERR:
                                {
                                        VERIFY_TYPE_ERROR();
                                }
@@ -1246,15 +894,16 @@ int _ILVerify(ILCoder *coder, unsigned char **start, 
ILMethod *method,
                        tempException.ptrUserData = 0;
                        tempException.next = 0;
 
-                       switch(AddExceptionBlock(&coderExceptions, method, 
&tempException))
+                       switch(_ILCoderAddExceptionBlock(&coderExceptions, 
method,
+                                                                               
         &tempException))
                        {
-                               case IL_VERIFY_BRANCH_ERR:
+                               case IL_CODER_BRANCH_ERR:
                                {
                                        VERIFY_BRANCH_ERROR();
                                }
                                break;
 
-                               case IL_VERIFY_TYPE_ERR:
+                               case IL_CODER_TYPE_ERR:
                                {
                                        VERIFY_TYPE_ERROR();
                                }
@@ -1691,7 +1340,7 @@ restart:
         */
        if(isSynchronized)
        {
-               coderException = FindExceptionBlock(&coderExceptions, 
code->codeLen);
+               coderException = _ILCoderFindExceptionBlock(&coderExceptions, 
code->codeLen);
                /*
                 * This check is for catching bugs.
                 */
diff --git a/engine/verify_except.c b/engine/verify_except.c
index f83ccc2..852d465 100644
--- a/engine/verify_except.c
+++ b/engine/verify_except.c
@@ -21,54 +21,6 @@
 #if defined(IL_VERIFY_GLOBALS)
 
 /*
- * Find the most nested exception block where an offset is located.
- * Returns NULL if no such exception block could be found.
- */
-static ILCoderExceptionBlock *FindExceptionBlock(ILCoderExceptions 
*coderExceptions,
-                                                                               
                 ILUInt32 offset)
-{
-       ILCoderExceptionBlock *block;
-       ILCoderExceptionBlock *prevEB;
-
-       prevEB = 0;
-       block = coderExceptions->firstBlock;
-       while(block)
-       {
-               if(offset < block->startOffset)
-               {
-                       break;
-               }
-               else if(offset >= block->endOffset)
-               {
-                       block = block->nextNested;
-               }
-               else
-               {
-                       prevEB = block;
-                       block = block->nested;
-               }
-       }
-       return prevEB;
-}
-
-/*
- * Determine if an offset is inside an exception handler's "try" range.
- */
-static IL_INLINE int InsideExceptionBlock(ILException *exception,
-                                                                               
  ILUInt32 offset)
-{
-       if(offset >= exception->tryOffset &&
-          offset < (exception->tryOffset + exception->tryLength))
-       {
-               return 1;
-       }
-       else
-       {
-               return 0;
-       }
-}
-
-/*
  * Determine the most nested catch block where the offset is in..
  */
 static IL_INLINE ILCoderExceptionBlock *
@@ -76,7 +28,7 @@ InsideExceptionHandler(ILCoderExceptions *coderExceptions, 
ILUInt32 offset)
 {
        ILCoderExceptionBlock *block;
 
-       block = FindExceptionBlock(coderExceptions, offset);
+       block = _ILCoderFindExceptionBlock(coderExceptions, offset);
        while(block)
        {
                if(block->flags & IL_CODER_HANDLER_TYPE_CATCH)
@@ -88,51 +40,8 @@ InsideExceptionHandler(ILCoderExceptions *coderExceptions, 
ILUInt32 offset)
        return 0;
 }
 
-/*
- * Emit code to throw a system-level exception.
- */
-static void _ThrowSystem(ILCoder *coder, ILMethod *method, int hasExceptions,
-                                                const char *name, const char 
*namespace)
-{
-       ILClass *classInfo;
-       ILMethod *ctor;
-       ILCoderMethodInfo callInfo;
-
-       /* Find the no-argument constructor for the class */
-       classInfo = ILClassResolveSystem(ILProgramItem_Image(method), 0,
-                                                                    name, 
namespace);
-       if(!classInfo)
-       {
-               return;
-       }
-       ctor = 0;
-       while((ctor = (ILMethod *)ILClassNextMemberByKind
-                       (classInfo, (ILMember *)ctor, 
IL_META_MEMBERKIND_METHOD)) != 0)
-       {
-               if(ILMethod_IsConstructor(ctor) &&
-                  ILTypeNumParams(ILMethod_Signature(ctor)) == 0)
-               {
-                       break;
-               }
-       }
-       if(!ctor)
-       {
-               return;
-       }
-
-       /* Invoke the constructor */
-       callInfo.args = 0;
-       callInfo.numBaseArgs = 0;
-       callInfo.numVarArgs = 0;
-       callInfo.hasParamArray = 0;
-       ILCoderCallCtor(coder, &callInfo, ctor);
-
-       /* Set the stack trace & throw the object */
-       ILCoderSetStackTrace(coder);
-       ILCoderThrow(coder, hasExceptions);
-}
 #define        ThrowSystem(namespace,name)     \
-                       _ThrowSystem(coder, method, (exceptions != 0), (name), 
(namespace))
+                       _ILCoderThrowSystem(coder, method, (name), (namespace))
 
 #elif defined(IL_VERIFY_LOCALS)
 
@@ -203,7 +112,7 @@ case IL_OP_ENDFINALLY:
        /* End the current "finally" or "fault" clause */
        if(stackSize == 0)
        {
-               coderException = FindExceptionBlock(&coderExceptions, offset);
+               coderException = _ILCoderFindExceptionBlock(&coderExceptions, 
offset);
                if(!coderException ||
                   ((coderException->flags & IL_CODER_HANDLER_TYPE_FINALLY) == 
0))
                {
@@ -230,7 +139,7 @@ case IL_OP_PREFIX + IL_PREFIX_OP_ENDFILTER:
         */
        if(stackSize == 1)
        {
-               coderException = FindExceptionBlock(&coderExceptions, offset);
+               coderException = _ILCoderFindExceptionBlock(&coderExceptions, 
offset);
                if(!coderException ||
                   (coderException->flags != IL_CODER_HANDLER_TYPE_FILTER))
                {
@@ -264,7 +173,7 @@ processLeave:
        }
 
        /* Call any applicable "finally" handlers, but not "fault" handlers */
-       coderException = FindExceptionBlock(&coderExceptions, offset);
+       coderException = _ILCoderFindExceptionBlock(&coderExceptions, offset);
        while(coderException != 0)
        {
                /*

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

Summary of changes:
 ChangeLog              |   23 +++
 engine/coder.c         |  416 ++++++++++++++++++++++++++++++++++++++++++++++++
 engine/coder.h         |   32 ++++
 engine/verify.c        |  369 +-----------------------------------------
 engine/verify_except.c |  101 +-----------
 5 files changed, 485 insertions(+), 456 deletions(-)


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



reply via email to

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