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/c c_ainit.tc,1.5,1.6 c_const.tc,1.


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/cscc/c c_ainit.tc,1.5,1.6 c_const.tc,1.4,1.5 c_defs.tc,1.23,1.24 c_grammar.y,1.55,1.56 c_lexutils.c,1.3,1.4 c_scanner.l,1.10,1.11 c_types.c,1.35,1.36 c_types.h,1.17,1.18
Date: Sat, 28 Jun 2003 01:28:49 -0400

Update of /cvsroot/dotgnu-pnet/pnet/cscc/c
In directory subversions:/tmp/cvs-serv25379/cscc/c

Modified Files:
        c_ainit.tc c_const.tc c_defs.tc c_grammar.y c_lexutils.c 
        c_scanner.l c_types.c c_types.h 
Log Message:


Add support for wide character and wide string constants.


Index: c_ainit.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_ainit.tc,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** c_ainit.tc  27 Jun 2003 10:18:20 -0000      1.5
--- c_ainit.tc  28 Jun 2003 05:28:47 -0000      1.6
***************
*** 193,196 ****
--- 193,212 ----
                        }
                }
+               else if(node && yyisa(node, ILNode_CWString) &&
+                       (ILTypeIdentical(elemType, ILType_Int16) ||
+                        ILTypeIdentical(elemType, ILType_UInt16) ||
+                        ILTypeIdentical(elemType, ILType_Char)))
+               {
+                       /* Assign a string to a "wchar" array */
+                       node = ILNode_ListIter_Next(iter);
+                       size = CGenWStringLength
+                                        (((ILNode_CWString *)node)->str,
+                                         ((ILNode_CWString *)node)->len);
+                       if(size > numElems)
+                       {
+                               CCWarningOnLine(yygetfilename(node), 
yygetlinenum(node),
+                             _("initializer-string for array of wide chars is 
too long"));
+                       }
+               }
                else
                {
***************
*** 386,389 ****
--- 402,426 ----
                }
        }
+       else if(yyisa(node->expr2, ILNode_CWString))
+       {
+               /* Assign the contents of a wide string */
+               elemType = 
CTypeWithoutQuals(CTypeGetElemType(CSemGetType(value1)));
+               if(elemType != ILType_Int16 && elemType != ILType_UInt16 &&
+                  elemType != ILType_Char)
+               {
+                       CCErrorOnLine(yygetfilename(node), yygetlinenum(node),
+                                                 _("invalid initializer"));
+                       return CSemValueError;
+               }
+               arraySize = CTypeGetNumElems(CSemGetType(value1));
+               initSize = CGenWStringLength
+                                        (((ILNode_CWString 
*)(node->expr2))->str,
+                                         ((ILNode_CWString 
*)(node->expr2))->len);
+               if(initSize > arraySize)
+               {
+                       CCWarningOnLine(yygetfilename(node), yygetlinenum(node),
+                           _("initializer-string for array of wide chars is 
too long"));
+               }
+       }
        else if(yyisa(node->expr2, ILNode_CArrayInit))
        {
***************
*** 478,481 ****
--- 515,519 ----
        ILUInt32 numElems;
        ILUInt32 index;
+       ILUInt32 wsize;
        ILType *elemType;
        ILClass *classInfo;
***************
*** 511,514 ****
--- 549,578 ----
                        ILGenAdjust(info, -3);
                }
+               else if(node && yyisa(node, ILNode_CWString) &&
+                       (ILTypeIdentical(elemType, ILType_Int16) ||
+                        ILTypeIdentical(elemType, ILType_UInt16) ||
+                        ILTypeIdentical(elemType, ILType_Char)))
+               {
+                       /* Populate a "wchar" array by copying a wide string 
into it */
+                       if(field)
+                       {
+                               ILGenFieldRef(info, IL_OP_LDFLDA, field);
+                       }
+                       node = ILNode_ListIter_Next(iter);
+                       ILNode_GenValue(node, info);
+                       size = CTypeGetNumElems(type);
+                       wsize = CGenWStringLength
+                                        (((ILNode_CWString *)node)->str,
+                                         ((ILNode_CWString *)node)->len);
+                       if(size > (wsize + 1))
+                       {
+                               size = wsize + 1;
+                       }
+                       ILGenUInt32(info, size * 2);
+                       ILGenAdjust(info, 1);
+                       ILGenByteInsn(info, IL_OP_PREFIX + 
IL_PREFIX_OP_UNALIGNED, 2);
+                       ILGenSimple(info, IL_OP_PREFIX + IL_PREFIX_OP_CPBLK);
+                       ILGenAdjust(info, -3);
+               }
                else
                {
***************
*** 660,663 ****
--- 724,728 ----
        ILNode_ListIter iter;
        ILUInt32 size;
+       ILUInt32 wsize;
  
        /* Get the address of the array */
***************
*** 676,679 ****
--- 741,761 ----
                ILGenAdjust(info, 1);
                ILGenByteInsn(info, IL_OP_PREFIX + IL_PREFIX_OP_UNALIGNED, 1);
+               ILGenSimple(info, IL_OP_PREFIX + IL_PREFIX_OP_CPBLK);
+               ILGenAdjust(info, -3);
+       }
+       else if(yyisa(node->expr2, ILNode_CWString))
+       {
+               ILNode_GenValue(node->expr2, info);
+               size = CTypeGetNumElems(node->type);
+               wsize = CGenWStringLength
+                                (((ILNode_CWString *)(node->expr2))->str,
+                                 ((ILNode_CWString *)(node->expr2))->len);
+               if(size > (wsize + 1))
+               {
+                       size = wsize + 1;
+               }
+               ILGenUInt32(info, size * 2);
+               ILGenAdjust(info, 1);
+               ILGenByteInsn(info, IL_OP_PREFIX + IL_PREFIX_OP_UNALIGNED, 2);
                ILGenSimple(info, IL_OP_PREFIX + IL_PREFIX_OP_CPBLK);
                ILGenAdjust(info, -3);

Index: c_const.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_const.tc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** c_const.tc  9 Feb 2003 01:58:35 -0000       1.4
--- c_const.tc  28 Jun 2003 05:28:47 -0000      1.5
***************
*** 27,30 ****
--- 27,40 ----
  
  /*
+  * Get the length of a wide character string.
+  */
+ ILUInt32 CGenWStringLength(const char *str, int len);
+ 
+ /*
+  * Get the index of a particular wide string within the string constant pool.
+  */
+ ILUInt32 CGenWStringIndex(ILGenInfo *info, const char *str, int len);
+ 
+ /*
   * Dump the contents of the string constant pool.
   */
***************
*** 403,406 ****
--- 413,462 ----
  }
  
+ /*
+  * Semantic analysis for "C wide string" constants.
+  */
+ ILNode_CSemAnalysis(ILNode_CWString)
+ {
+       CSemValue value;
+       CSemSetDynConstant(value, CTypeCreateWCharPtr(info));
+       return value;
+ }
+ 
+ /*
+  * Generate value code for a "C wide string" constant.
+  */
+ ILNode_GenValue(ILNode_CWString)
+ {
+       ILUInt32 len;
+       ILUInt32 index;
+ 
+       /* Look for this string in the string pool */
+       index = CGenWStringIndex(info, node->str, node->len);
+ 
+       /* Get the address of the string in the pool */
+       if(info->asmOutput)
+       {
+               len = CGenWStringLength(node->str, node->len);
+               fprintf(info->asmOutput,
+                       "\tldsflda\tvaluetype '$strings'/'wtype%lu' "
+                                       "'$strings'::'wstr%lu'\n",
+                               (unsigned long)(len + 1), (unsigned long)index);
+       }
+       ILGenAdjust(info, 1);
+ 
+       /* Strings are passed on the stack as unmanaged pointers (type I) */
+       return ILMachineType_UnmanagedPtr;
+ }
+ 
+ /*
+  * Evaluate a "C wide string" constant.
+  */
+ ILNode_EvalConst(ILNode_CWString)
+ {
+       /* C wide string constants must be evaluated at runtime because
+          we don't know what the address is yet */
+       return 0;
+ }
+ 
  %end %{
  
***************
*** 421,424 ****
--- 477,481 ----
        const char *str;
        int len;
+       int isWide;
        ILUInt32 index;
  
***************
*** 448,455 ****
                return 0;
        }
        return (elem->len == 0 || !ILMemCmp(elem->str, key->str, elem->len));
  }
  
! ILUInt32 CGenStringIndex(ILGenInfo *info, const char *str, int len)
  {
        StringHashEntry *entry;
--- 505,517 ----
                return 0;
        }
+       if(elem->isWide != key->isWide)
+       {
+               return 0;
+       }
        return (elem->len == 0 || !ILMemCmp(elem->str, key->str, elem->len));
  }
  
! static ILUInt32 GenStringIndex(ILGenInfo *info, const char *str,
!                                                          int len, int isWide)
  {
        StringHashEntry *entry;
***************
*** 463,466 ****
--- 525,529 ----
                key.str = str;
                key.len = len;
+               key.isWide = isWide;
                entry = ILHashFindType(poolHash, &key, StringHashEntry);
                if(entry)
***************
*** 521,524 ****
--- 584,588 ----
        entry->str = str;
        entry->len = len;
+       entry->isWide = isWide;
        entry->index = poolIndex;
        if(!ILHashAdd(poolHash, entry))
***************
*** 531,534 ****
--- 595,628 ----
  }
  
+ ILUInt32 CGenStringIndex(ILGenInfo *info, const char *str, int len)
+ {
+       return GenStringIndex(info, str, len, 0);
+ }
+ 
+ ILUInt32 CGenWStringLength(const char *str, int len)
+ {
+       unsigned long ch;
+       ILUInt32 slen = 0;
+       int posn = 0;
+       while(posn < len)
+       {
+               ch = ILUTF8ReadChar(str, len, &posn);
+               if(ch < 0x10000)
+               {
+                       ++slen;
+               }
+               else
+               {
+                       slen += 2;
+               }
+       }
+       return slen;
+ }
+ 
+ ILUInt32 CGenWStringIndex(ILGenInfo *info, const char *str, int len)
+ {
+       return GenStringIndex(info, str, len, 1);
+ }
+ 
  #if HAVE_QSORT
  
***************
*** 560,564 ****
--- 654,660 ----
        StringHashEntry *entry;
        int *lengths;
+       int *wideLengths;
        int numLengths;
+       int numWideLengths;
  
        /* Bail out if no assembly output stream or string pool */
***************
*** 579,590 ****
                ILGenOutOfMemory(info);
        }
        numLengths = 0;
        ILHashIterInit(&iter, poolHash);
        while((entry = ILHashIterNextType(&iter, StringHashEntry)) != 0)
        {
!               lengths[numLengths++] = entry->len + 1;
        }
  #if HAVE_QSORT
        qsort(lengths, numLengths, sizeof(int), IntCompare);
  #else
        {
--- 675,701 ----
                ILGenOutOfMemory(info);
        }
+       wideLengths = (int *)ILMalloc(sizeof(int) * poolIndex);
+       if(!wideLengths)
+       {
+               ILGenOutOfMemory(info);
+       }
        numLengths = 0;
+       numWideLengths = 0;
        ILHashIterInit(&iter, poolHash);
        while((entry = ILHashIterNextType(&iter, StringHashEntry)) != 0)
        {
!               if(!(entry->isWide))
!               {
!                       lengths[numLengths++] = entry->len + 1;
!               }
!               else
!               {
!                       wideLengths[numWideLengths++] =
!                               (int)(CGenWStringLength(entry->str, entry->len) 
+ 1);
!               }
        }
  #if HAVE_QSORT
        qsort(lengths, numLengths, sizeof(int), IntCompare);
+       qsort(wideLengths, numWideLengths, sizeof(int), IntCompare);
  #else
        {
***************
*** 602,605 ****
--- 713,728 ----
                        }
                }
+               for(x = 0; x < (numWideLengths - 1); ++x)
+               {
+                       for(y = x + 1; y < numWideLengths; ++y)
+                       {
+                               if(wideLengths[x] > wideLengths[y])
+                               {
+                                       len = wideLengths[x];
+                                       wideLengths[x] = wideLengths[y];
+                                       wideLengths[y] = len;
+                               }
+                       }
+               }
        }
  #endif
***************
*** 617,625 ****
                fprintf(stream, "{\n\t.pack 1\n\t.size %d\n}\n", lengths[len]);
        }
  
!       /* Dump the contents of all strings to the ".sdata" section */
        ILHashIterInit(&iter, poolHash);
        while((entry = ILHashIterNextType(&iter, StringHashEntry)) != 0)
        {
                fprintf(stream, ".data StrData%lu = bytearray(\n",
                                (unsigned long)(entry->index));
--- 740,769 ----
                fprintf(stream, "{\n\t.pack 1\n\t.size %d\n}\n", lengths[len]);
        }
+       for(len = 0; len < numWideLengths; ++len)
+       {
+               if(len < (numWideLengths - 1) &&
+                  wideLengths[len] == wideLengths[len + 1])
+               {
+                       continue;
+               }
+               fprintf(stream, ".class nested public sealed explicit "
+                                               "'wtype%d' extends 
[.library]System.ValueType\n",
+                               wideLengths[len]);
+               fprintf(stream, "{\n\t.pack 2\n\t.size %d\n}\n",
+                       wideLengths[len] * 2);
+       }
  
!       /* Dump the contents of all "char *" strings to the ".sdata" section */
        ILHashIterInit(&iter, poolHash);
        while((entry = ILHashIterNextType(&iter, StringHashEntry)) != 0)
        {
+               if(entry->isWide)
+               {
+                       fprintf(stream, ".field public static valuetype "
+                                                       "'$strings'/'wtype%d' 
wstr%lu\n",
+                                       CGenWStringLength(entry->str, 
entry->len) + 1,
+                                   (unsigned long)(entry->index));
+                       continue;
+               }
                fprintf(stream, ".data StrData%lu = bytearray(\n",
                                (unsigned long)(entry->index));
***************
*** 649,654 ****
--- 793,830 ----
        fputs("}\n", stream);
  
+       /* Dump the contents of all "wchar *" strings to an initializer method 
*/
+       if(numWideLengths > 0)
+       {
+               fputs(".method private static specialname void 
'.init-wstrings'() "
+                                       "cil managed\n", stream);
+               fputs("{\n", stream);
+               fputs(".custom instance void 
OpenSystem.C.InitializerAttribute::.ctor()"
+                               " = (01 00 00 00)\n", stream);
+               fputs(".custom instance void 
OpenSystem.C.InitializerOrderAttribute"
+                               "::.ctor(int32) = (01 00 FF FF FF FF 00 00)\n", 
stream);
+               fputs("\t.maxstack 2\n", stream);
+               ILHashIterInit(&iter, poolHash);
+               while((entry = ILHashIterNextType(&iter, StringHashEntry)) != 0)
+               {
+                       if(!(entry->isWide))
+                       {
+                               continue;
+                       }
+                       fprintf(stream, "\tldsflda valuetype 
'$strings'/'wtype%d' "
+                                                       "'$strings'::wstr%lu\n",
+                                   (int)(CGenWStringLength(entry->str, 
entry->len) + 1),
+                                       (unsigned long)(entry->index));
+                       ILGenLoadString(info, entry->str, entry->len);
+                       fputs("\tcall void [OpenSystem.C]OpenSystem.C.Crt0::"
+                                 "SetWideString(char *, class 
[.library]System.String)\n",
+                                 stream);
+               }
+               fputs("\tret\n", stream);
+               fputs("}\n", stream);
+       }
+ 
        /* Done */
        ILFree(lengths);
+       ILFree(wideLengths);
  }
  

Index: c_defs.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_defs.tc,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -r1.23 -r1.24
*** c_defs.tc   27 Jun 2003 06:19:54 -0000      1.23
--- c_defs.tc   28 Jun 2003 05:28:47 -0000      1.24
***************
*** 299,302 ****
--- 299,303 ----
   */
  %node ILNode_CString ILNode_String
+ %node ILNode_CWString ILNode_String
  %node ILNode_SizeOfExpr ILNode_UnaryExpression =
  {

Index: c_grammar.y
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_grammar.y,v
retrieving revision 1.55
retrieving revision 1.56
diff -C2 -r1.55 -r1.56
*** c_grammar.y 28 Jun 2003 02:41:42 -0000      1.55
--- c_grammar.y 28 Jun 2003 05:28:47 -0000      1.56
***************
*** 318,321 ****
--- 318,325 ----
                stmt = ILNode_CAssignArray_create(var, init);
        }
+       else if(CTypeIsArray(type) && yyisa(init, ILNode_CWString))
+       {
+               stmt = ILNode_CAssignArray_create(var, init);
+       }
        else
        {
***************
*** 565,573 ****
  static ILUInt32 ArrayInitializerSize(ILType *type, ILNode *init)
  {
!       /* Handle the string case first */
        if(yyisa(init, ILNode_CString))
        {
                return (ILUInt32)(((ILNode_CString *)init)->len) + 1;
        }
  
        /* If this isn't an array initializer, then bail out */
--- 569,583 ----
  static ILUInt32 ArrayInitializerSize(ILType *type, ILNode *init)
  {
!       /* Handle the string cases first */
        if(yyisa(init, ILNode_CString))
        {
                return (ILUInt32)(((ILNode_CString *)init)->len) + 1;
        }
+       else if(yyisa(init, ILNode_CWString))
+       {
+               return CGenWStringLength
+                               ((((ILNode_CWString *)init)->str),
+                                (((ILNode_CWString *)init)->len)) + 1;
+       }
  
        /* If this isn't an array initializer, then bail out */
***************
*** 978,981 ****
--- 988,992 ----
  %token IMAG_CONSTANT  "an imaginary value"
  %token STRING_LITERAL "a string literal"
+ %token WSTRING_LITERAL        "a wide string literal"
  %token TYPE_NAME              "a type identifier"
  
***************
*** 1065,1069 ****
  %type <integer>               INTEGER_CONSTANT
  %type <real>          FLOAT_CONSTANT IMAG_CONSTANT
! %type <string>                STRING_LITERAL StringLiteral
  
  %type <name>          AnyIdentifier Identifier
--- 1076,1081 ----
  %type <integer>               INTEGER_CONSTANT
  %type <real>          FLOAT_CONSTANT IMAG_CONSTANT
! %type <string>                STRING_LITERAL WSTRING_LITERAL StringLiteral
! %type <string>                WStringLiteral
  
  %type <name>          AnyIdentifier Identifier
***************
*** 1296,1299 ****
--- 1308,1314 ----
                                $$ = ILNode_CString_create($1.string, $1.len);
                        }
+       | WStringLiteral                        {
+                               $$ = ILNode_CWString_create($1.string, $1.len);
+                       }
        | K_FUNC                                {
                                /* Create a reference to the local "__func__" 
array.
***************
*** 1320,1323 ****
--- 1335,1345 ----
                                $$ = ILInternAppendedString
                                        ($1, ILInternString(functionName, 
strlen(functionName)));
+                       }
+       ;
+ 
+ WStringLiteral
+       : WSTRING_LITERAL       { $$ = $1; }
+       | WStringLiteral WSTRING_LITERAL        {
+                               $$ = ILInternAppendedString($1, $2);
                        }
        ;

Index: c_lexutils.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_lexutils.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** c_lexutils.c        10 Aug 2002 02:16:42 -0000      1.3
--- c_lexutils.c        28 Jun 2003 05:28:47 -0000      1.4
***************
*** 429,432 ****
--- 429,436 ----
  
        /* Skip the leading "'" */
+       if(*text == 'L' || *text == 'l')
+       {
+               ++text;
+       }
        ++text;
  
***************
*** 491,494 ****
--- 495,502 ----
  
        /* Initialize the value to be returned */
+       if(*text == 'L' || *text == 'l')
+       {
+               ++text;
+       }
        ++text;
        value->string = text;

Index: c_scanner.l
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_scanner.l,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** c_scanner.l 22 Aug 2002 00:56:35 -0000      1.10
--- c_scanner.l 28 Jun 2003 05:28:47 -0000      1.11
***************
*** 168,171 ****
--- 168,189 ----
  "__func__"                            { return K_FUNC; }
  
+ \"(\\.|[^\\"])*\"                             { CLexParseString(yytext, 
&(yylval.string));
+                                                                 
RETURNTOK(STRING_LITERAL); }
+ 
+ L\"(\\.|[^\\"])*\"                            { CLexParseString(yytext, 
&(yylval.string));
+                                                                 
RETURNTOK(WSTRING_LITERAL); }
+ 
+ l\"(\\.|[^\\"])*\"                            { CLexParseString(yytext, 
&(yylval.string));
+                                                                 
RETURNTOK(WSTRING_LITERAL); }
+ 
+ '(\\.|[^\\'])+'                                       { CLexParseChar(yytext, 
&(yylval.integer));
+                                                                 
RETURNTOK(INTEGER_CONSTANT); }
+ 
+ L'(\\.|[^\\'])+'                              { CLexParseChar(yytext, 
&(yylval.integer));
+                                                                 
RETURNTOK(INTEGER_CONSTANT); }
+ 
+ l'(\\.|[^\\'])+'                              { CLexParseChar(yytext, 
&(yylval.integer));
+                                                                 
RETURNTOK(INTEGER_CONSTANT); }
+ 
  {IDALPHA}({DIGIT}|{IDALPHA})* {
                        /* Use the scope to determine if this is a typedef'ed 
name */
***************
*** 209,217 ****
  {DIGIT}+{ITYPE}?                              { CLexParseInt(yytext, 
&(yylval.integer));
                                                                  
RETURNTOK(INTEGER_CONSTANT); }
- '(\\.|[^\\'])+'                                       { CLexParseChar(yytext, 
&(yylval.integer));
-                                                                 
RETURNTOK(INTEGER_CONSTANT); }
- 
- \"(\\.|[^\\"])*\"                             { CLexParseString(yytext, 
&(yylval.string));
-                                                                 
RETURNTOK(STRING_LITERAL); }
  
  {WHITE}+                                              ;
--- 227,230 ----

Index: c_types.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_types.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -C2 -r1.35 -r1.36
*** c_types.c   28 Jun 2003 02:10:54 -0000      1.35
--- c_types.c   28 Jun 2003 05:28:47 -0000      1.36
***************
*** 358,361 ****
--- 358,371 ----
  }
  
+ ILType *CTypeCreateWCharPtr(ILGenInfo *info)
+ {
+       static ILType *wcharPtr = 0;
+       if(!wcharPtr)
+       {
+               wcharPtr = CTypeCreatePointer(info, ILType_Char);
+       }
+       return wcharPtr;
+ }
+ 
  ILType *CTypeAddConst(ILGenInfo *info, ILType *type)
  {

Index: c_types.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/cscc/c/c_types.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -r1.17 -r1.18
*** c_types.h   26 Jun 2003 07:05:47 -0000      1.17
--- c_types.h   28 Jun 2003 05:28:47 -0000      1.18
***************
*** 84,87 ****
--- 84,92 ----
  
  /*
+  * Create a C type reference for "wchar_t *".
+  */
+ ILType *CTypeCreateWCharPtr(ILGenInfo *info);
+ 
+ /*
   * Mark a C type with a "const" qualifier.
   */





reply via email to

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