Browse Source

Interrogate issues: "fix #pragma once" for files specified on command-line, fix "unexpected $end" not having line numbers when parsing template parameter list

rdb 9 years ago
parent
commit
1467541b8d

+ 1 - 1
dtool/src/cppparser/cppFile.h

@@ -55,7 +55,7 @@ public:
 
   Filename _filename;
   Filename _filename_as_referenced;
-  Source _source;
+  mutable Source _source;
   mutable bool _pragma_once;
 };
 

+ 14 - 1
dtool/src/cppparser/cppParser.cxx

@@ -45,7 +45,20 @@ is_fully_specified() const {
  */
 bool CPPParser::
 parse_file(const Filename &filename) {
-  if (!init_cpp(CPPFile(filename, filename, CPPFile::S_local))) {
+  Filename canonical(filename);
+  canonical.make_canonical();
+
+  CPPFile file(canonical, filename, CPPFile::S_local);
+
+  // Don't read it if we included it before and it had #pragma once.
+  ParsedFiles::iterator it = _parsed_files.find(file);
+  if (it != _parsed_files.end() && it->_pragma_once) {
+    // But mark it as local.
+    it->_source = CPPFile::S_local;
+    return true;
+  }
+
+  if (!init_cpp(file)) {
     cerr << "Unable to read " << filename << "\n";
     return false;
   }

+ 3 - 3
dtool/src/cppparser/cppPreprocessor.cxx

@@ -951,7 +951,7 @@ internal_get_next_token() {
     case ',':
       if (_paren_nesting <= 0) {
         _state = S_end_nested;
-        return CPPToken::eof();
+        return CPPToken(0, loc);
       }
       break;
 
@@ -959,7 +959,7 @@ internal_get_next_token() {
       if (_paren_nesting <= 0) {
         _parsing_template_params = false;
         _state = S_end_nested;
-        return CPPToken::eof();
+        return CPPToken(0, loc);
       }
     }
   }
@@ -1639,7 +1639,7 @@ handle_include_directive(const string &args, const YYLTYPE &loc) {
       _last_c = '\0';
 
       // If it was explicitly named on the command-line, mark it S_local.
-      filename.make_absolute();
+      filename.make_canonical();
       if (_explicit_files.count(filename)) {
         source = CPPFile::S_local;
       }