Skip to content

Instantly share code, notes, and snippets.

@guoxiaoqiao
Created October 26, 2016 15:15
Show Gist options
  • Save guoxiaoqiao/d9dd17723e5136ed13f78db0a8ecb7c8 to your computer and use it in GitHub Desktop.
Save guoxiaoqiao/d9dd17723e5136ed13f78db0a8ecb7c8 to your computer and use it in GitHub Desktop.
gcc支持中文变量名的补丁
--- gcc-4.7.0-20120604/libcpp/lex.c 2011-12-20 20:56:54.000000000 +0800
+++ gcc-4.7.0-20120604/libcpp/lex.umod.c 2012-07-05 21:53:30.184527392 +0800
@@ -1322,7 +1322,10 @@
raw_prefix_len++;
continue;
}
- break;
+ if (raw_prefix[raw_prefix_len] > 0x80)
+ raw_prefix_len++;
+ else
+ break;
}
if (raw_prefix[raw_prefix_len] != '(')
@@ -2090,6 +2093,7 @@
}
/* Fall through. */
+ cpp_name:
case '_':
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
@@ -2342,7 +2346,12 @@
}
default:
- create_literal (pfile, result, buffer->cur - 1, 1, CPP_OTHER);
+ if (c >= 0x80)
+ {
+ goto cpp_name;
+ }
+ else
+ create_literal (pfile, result, buffer->cur - 1, 1, CPP_OTHER);
break;
}
@@ -2451,13 +2460,7 @@
const unsigned char * name = NODE_NAME (token->val.node.node);
for (i = 0; i < NODE_LEN (token->val.node.node); i++)
- if (name[i] & ~0x7F)
- {
- i += utf8_to_ucn (buffer, name + i) - 1;
- buffer += 10;
- }
- else
- *buffer++ = NODE_NAME (token->val.node.node)[i];
+ *buffer++ = NODE_NAME (token->val.node.node)[i];
}
break;
@@ -2537,14 +2540,7 @@
const unsigned char * name = NODE_NAME (token->val.node.node);
for (i = 0; i < NODE_LEN (token->val.node.node); i++)
- if (name[i] & ~0x7F)
- {
- unsigned char buffer[10];
- i += utf8_to_ucn (buffer, name + i) - 1;
- fwrite (buffer, 1, 10, fp);
- }
- else
- fputc (NODE_NAME (token->val.node.node)[i], fp);
+ fputc (NODE_NAME (token->val.node.node)[i], fp);
}
break;
--- gcc-4.6.1-20111002/libiberty/safe-ctype.c 2011-03-15 22:32:36.000000000 +0800
+++ gcc-4.6.1-20111002/libiberty/safe-ctype.umod.c 2011-10-23 20:39:30.885345790 +0800
@@ -177,15 +177,15 @@
/* high half of unsigned char is locale-specific, so all tests are
false in "C" locale */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L,
+ L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L,
+ L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L,
+ L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L,
+ L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L,
+ L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L,
+ L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L,
};
const unsigned char _sch_tolower[256] =
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment