Commit e63436b9 by zmo@google.com

Handle hex int constant in preprocessor

The patch is provided by jdashg and committed by zmo. (see angle issue 178) ANGLEBUG=178 TEST=shader-with-hex-int-constant-macro.html TBR=zmo Review URL: https://codereview.appspot.com/6037044 git-svn-id: https://angleproject.googlecode.com/svn/trunk@1041 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 36cc18b7
#define MAJOR_VERSION 1 #define MAJOR_VERSION 1
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 1039 #define BUILD_REVISION 1041
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -265,6 +265,8 @@ int ReadToken(TokenStream *pTok, yystypepp * yylvalpp) ...@@ -265,6 +265,8 @@ int ReadToken(TokenStream *pTok, yystypepp * yylvalpp)
char string_val[MAX_STRING_LEN + 1]; char string_val[MAX_STRING_LEN + 1];
int ltoken, len; int ltoken, len;
char ch; char ch;
int base, accum;
char ch_val;
ltoken = lReadByte(pTok); ltoken = lReadByte(pTok);
if (ltoken >= 0) { if (ltoken >= 0) {
...@@ -315,18 +317,41 @@ int ReadToken(TokenStream *pTok, yystypepp * yylvalpp) ...@@ -315,18 +317,41 @@ int ReadToken(TokenStream *pTok, yystypepp * yylvalpp)
break; break;
case CPP_INTCONSTANT: case CPP_INTCONSTANT:
len = 0; len = 0;
accum = 0;
ch = lReadByte(pTok); ch = lReadByte(pTok);
while ((ch >= '0' && ch <= '9')) if (ch == '0') {
{ symbol_name[len++] = ch;
if (len < MAX_SYMBOL_NAME_LEN) { ch = lReadByte(pTok);
if (ch == 'x' || ch == 'X') {
symbol_name[len++] = ch; symbol_name[len++] = ch;
base = 16;
ch = lReadByte(pTok); ch = lReadByte(pTok);
} else {
base = 8;
} }
} else {
base = 10;
}
while (len < MAX_SYMBOL_NAME_LEN)
{
ch_val = -1;
if (isdigit(ch))
ch_val = ch - '0';
else if (isxdigit(ch))
ch_val = tolower(ch) - 'a' + 10;
if (ch_val < 0 || ch_val >= base)
break;
symbol_name[len++] = ch;
accum = accum * base + ch_val;
ch = lReadByte(pTok);
} }
symbol_name[len] = '\0'; symbol_name[len] = '\0';
assert(ch == '\0'); assert(ch == '\0');
strcpy(yylvalpp->symbol_name,symbol_name); strcpy(yylvalpp->symbol_name, symbol_name);
yylvalpp->sc_int=atoi(yylvalpp->symbol_name); yylvalpp->sc_int = accum;
break; break;
case '(': case '(':
yylvalpp->sc_int = lReadByte(pTok); yylvalpp->sc_int = lReadByte(pTok);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment