Unicode literals

This commit is contained in:
Vladimir Kalinin 2013-01-16 08:01:27 +04:00 • committed by William S Fulton
commit 7d800a655d
9 changed files with 137 additions and 14 deletions

View file

@ -274,7 +274,7 @@ int Swig_cargs(Wrapper *w, ParmList *p) {
Delete(defname);
Delete(defvalue);
}
} else if (!pvalue && ((tycode == T_POINTER) || (tycode == T_STRING))) {
} else if (!pvalue && ((tycode == T_POINTER) || (tycode == T_STRING) || (tycode == T_WSTRING))) {
pvalue = (String *) "0";
}
if (!altty) {

View file

@ -509,7 +509,6 @@ static int look(Scanner * s) {
state = 4; /* Possibly a SWIG directive */
/* Look for possible identifiers or unicode/delimiter strings */
else if ((isalpha(c)) || (c == '_') ||
(s->idstart && strchr(s->idstart, c))) {
state = 7;
@ -867,11 +866,15 @@ static int look(Scanner * s) {
break;
case 7: /* Identifier or true/false or unicode/custom delimiter string */
if (c=='R') { /* Possibly CUSTOM DELIMITER string */
if (c == 'R') { /* Possibly CUSTOM DELIMITER string */
state = 72;
break;
}
else if (c!='u' && c!='U' && c!='L') { /* Definitely an identifier */
else if (c == 'L') { /* Probably identifier but may be a wide string literal */
state = 77;
break;
}
else if (c != 'u' && c != 'U') { /* Definitely an identifier */
state = 70;
break;
}
@ -879,14 +882,14 @@ static int look(Scanner * s) {
if ((c = nextchar(s)) == 0) {
state = 76;
}
else if (c=='\"') { /* Definitely u, U or L string */
else if (c == '\"') { /* Definitely u, U or L string */
retract(s, 1);
state = 1000;
}
else if (c=='R') { /* Possibly CUSTOM DELIMITER u, U, L string */
else if (c == 'R') { /* Possibly CUSTOM DELIMITER u, U, L string */
state = 73;
}
else if (c=='8') { /* Possibly u8 string */
else if (c == '8') { /* Possibly u8 string */
state = 71;
}
else {
@ -950,6 +953,59 @@ static int look(Scanner * s) {
break;
case 77: /*identifier or wide string literal*/
if ((c = nextchar(s)) == 0)
return SWIG_TOKEN_ID;
else if (c == '\"') {
s->start_line = s->line;
Clear(s->text);
state = 78;
}
else if (c == '\'') {
s->start_line = s->line;
Clear(s->text);
state = 79;
}
else if (isalnum(c) || (c == '_') || (c == '$'))
state = 7;
else {
retract(s, 1);
return SWIG_TOKEN_ID;
}
break;
case 78: /* Processing a wide string literal*/
if ((c = nextchar(s)) == 0) {
Swig_error(cparse_file, cparse_start_line, "Unterminated wide string\n");
return SWIG_TOKEN_ERROR;
}
if (c == '\"') {
Delitem(s->text, DOH_END);
return SWIG_TOKEN_WSTRING;
} else if (c == '\\') {
if ((c = nextchar(s)) == 0) {
Swig_error(cparse_file, cparse_start_line, "Unterminated wide string\n");
return SWIG_TOKEN_ERROR;
}
}
break;
case 79: /* Processing a wide char literal */
if ((c = nextchar(s)) == 0) {
Swig_error(cparse_file, cparse_start_line, "Unterminated character constant\n");
return SWIG_TOKEN_ERROR;
}
if (c == '\'') {
Delitem(s->text, DOH_END);
return (SWIG_TOKEN_WCHAR);
} else if (c == '\\') {
if ((c = nextchar(s)) == 0) {
Swig_error(cparse_file, cparse_start_line, "Unterminated wide char literal\n");
return SWIG_TOKEN_ERROR;
}
}
break;
case 75: /* Special identifier $ */
if ((c = nextchar(s)) == 0)
return SWIG_TOKEN_DOLLAR;

View file

@ -131,12 +131,21 @@ SwigType *NewSwigType(int t) {
case T_UCHAR:
return NewString("unsigned char");
break;
case T_STRING:{
case T_STRING: {
SwigType *t = NewString("char");
SwigType_add_pointer(t);
return t;
break;
}
case T_WCHAR:
return NewString("wchar_t");
break;
case T_WSTRING: {
SwigType *t = NewString("wchar_t");
SwigType_add_pointer(t);
return t;
break;
}
case T_LONGLONG:
return NewString("long long");
break;

View file

@ -100,6 +100,9 @@ extern "C" {
#define T_SYMBOL 98
#define T_ERROR 99
/* wide string literal, may contain escaped wide chars like \x1234 as well as normal escape sequences */
#define T_WSTRING 39
/* --- File interface --- */

View file

@ -67,6 +67,9 @@ extern void Scanner_freeze_line(Scanner *s, int val);
#define SWIG_TOKEN_QUESTION 30 /* ? */
#define SWIG_TOKEN_COMMENT 31 /* C or C++ comment */
#define SWIG_TOKEN_BOOL 32 /* true or false */
#define SWIG_TOKEN_WSTRING 33 /* L"str" */
#define SWIG_TOKEN_WCHAR 34 /* L'c' */
#define SWIG_TOKEN_ILLEGAL 99
#define SWIG_TOKEN_ERROR -1

View file

@ -1194,6 +1194,8 @@ int SwigType_type(SwigType *t) {
if (strncmp(c, "p.", 2) == 0) {
if (SwigType_type(c + 2) == T_CHAR)
return T_STRING;
else if (SwigType_type(c + 2) == T_WCHAR)
return T_WSTRING;
else
return T_POINTER;
}
@ -1236,6 +1238,8 @@ int SwigType_type(SwigType *t) {
return T_SCHAR;
if (strcmp(c, "unsigned char") == 0)
return T_UCHAR;
if (strcmp(c, "wchar_t") == 0)
return T_WCHAR;
if (strcmp(c, "float") == 0)
return T_FLOAT;
if (strcmp(c, "double") == 0)