Browse Source

Support digraphs and alternate operator names in CPPParser

rdb 11 years ago
parent
commit
202008c470
1 changed files with 19 additions and 2 deletions
  1. 19 2
      dtool/src/cppparser/cppPreprocessor.cxx

+ 19 - 2
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(LSHIFT, first_line, first_col, first_file);
     if (next_c == '=') return CPPToken(LECOMPARE, 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;
     break;
 
 
   case '>':
   case '>':
@@ -867,6 +869,7 @@ internal_get_next_token() {
 
 
   case ':':
   case ':':
     if (next_c == ':') return CPPToken(SCOPE, first_line, first_col, first_file);
     if (next_c == ':') return CPPToken(SCOPE, first_line, first_col, first_file);
+    if (next_c == '>') return CPPToken(']', first_line, first_col, first_file);
     break;
     break;
 
 
   case '*':
   case '*':
@@ -879,6 +882,7 @@ internal_get_next_token() {
 
 
   case '%':
   case '%':
     if (next_c == '=') return CPPToken(MODEQUAL, first_line, first_col, first_file);
     if (next_c == '=') return CPPToken(MODEQUAL, first_line, first_col, first_file);
+    if (next_c == '>') return CPPToken('}', first_line, first_col, first_file);
     break;
     break;
   }
   }
 
 
@@ -1411,7 +1415,7 @@ handle_include_directive(const string &args, int first_line,
       found_file = true;
       found_file = true;
       source = CPPFile::S_local;
       source = CPPFile::S_local;
     }
     }
-    
+
     // Search the same directory as the includer.
     // Search the same directory as the includer.
     if (!angle_quotes && !found_file) {
     if (!angle_quotes && !found_file) {
       Filename match(get_file()._filename.get_dirname(), filename);
       Filename match(get_file()._filename.get_dirname(), filename);
@@ -1439,7 +1443,7 @@ handle_include_directive(const string &args, int first_line,
         }
         }
       }
       }
     }
     }
-    
+
     if (!found_file) {
     if (!found_file) {
       warning("Cannot find " + filename.get_fullpath(),
       warning("Cannot find " + filename.get_fullpath(),
               first_line, first_col, first_file);
               first_line, first_col, first_file);
@@ -2058,6 +2062,19 @@ check_keyword(const string &name) {
   if (name == "volatile") return KW_VOLATILE;
   if (name == "volatile") return KW_VOLATILE;
   if (name == "while") return KW_WHILE;
   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) {
   if (!cpp_longlong_keyword.empty() && name == cpp_longlong_keyword) {
     return KW_LONGLONG;
     return KW_LONGLONG;
   }
   }