From 202008c4703f984cd4119310290bbaef97ef85be Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 2 Jan 2015 14:55:06 +0100 Subject: [PATCH] Support digraphs and alternate operator names in CPPParser --- dtool/src/cppparser/cppPreprocessor.cxx | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/dtool/src/cppparser/cppPreprocessor.cxx b/dtool/src/cppparser/cppPreprocessor.cxx index 474063e4a7..0911921510 100644 --- a/dtool/src/cppparser/cppPreprocessor.cxx +++ b/dtool/src/cppparser/cppPreprocessor.cxx @@ -824,6 +824,8 @@ internal_get_next_token() { } if (next_c == '<') return CPPToken(LSHIFT, first_line, first_col, first_file); if (next_c == '=') return CPPToken(LECOMPARE, first_line, first_col, first_file); + if (next_c == ':') return CPPToken('[', first_line, first_col, first_file); + if (next_c == '%') return CPPToken('{', first_line, first_col, first_file); break; case '>': @@ -867,6 +869,7 @@ internal_get_next_token() { case ':': if (next_c == ':') return CPPToken(SCOPE, first_line, first_col, first_file); + if (next_c == '>') return CPPToken(']', first_line, first_col, first_file); break; case '*': @@ -879,6 +882,7 @@ internal_get_next_token() { case '%': if (next_c == '=') return CPPToken(MODEQUAL, first_line, first_col, first_file); + if (next_c == '>') return CPPToken('}', first_line, first_col, first_file); break; } @@ -1411,7 +1415,7 @@ handle_include_directive(const string &args, int first_line, found_file = true; source = CPPFile::S_local; } - + // Search the same directory as the includer. if (!angle_quotes && !found_file) { Filename match(get_file()._filename.get_dirname(), filename); @@ -1439,7 +1443,7 @@ handle_include_directive(const string &args, int first_line, } } } - + if (!found_file) { warning("Cannot find " + filename.get_fullpath(), first_line, first_col, first_file); @@ -2058,6 +2062,19 @@ check_keyword(const string &name) { if (name == "volatile") return KW_VOLATILE; if (name == "while") return KW_WHILE; + // These are alternative ways to refer to built-in operators. + if (name == "and") return ANDAND; + if (name == "and_eq") return ANDEQUAL; + if (name == "bitand") return '&'; + if (name == "bitor") return '|'; + if (name == "compl") return '~'; + if (name == "not") return '!'; + if (name == "not_eq") return NECOMPARE; + if (name == "or") return OROR; + if (name == "or_eq") return OREQUAL; + if (name == "xor") return '^'; + if (name == "xor_eq") return XOREQUAL; + if (!cpp_longlong_keyword.empty() && name == cpp_longlong_keyword) { return KW_LONGLONG; }