From 1467541b8d1df4364ca2bebad0d45620dfdc9f60 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 1 Nov 2016 12:17:49 +0100 Subject: [PATCH] Interrogate issues: "fix #pragma once" for files specified on command-line, fix "unexpected $end" not having line numbers when parsing template parameter list --- dtool/src/cppparser/cppFile.h | 2 +- dtool/src/cppparser/cppParser.cxx | 15 ++++++++++++++- dtool/src/cppparser/cppPreprocessor.cxx | 6 +++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/dtool/src/cppparser/cppFile.h b/dtool/src/cppparser/cppFile.h index b284758615..f3644fce3c 100644 --- a/dtool/src/cppparser/cppFile.h +++ b/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; }; diff --git a/dtool/src/cppparser/cppParser.cxx b/dtool/src/cppparser/cppParser.cxx index 29874cb559..4b27a87d6d 100644 --- a/dtool/src/cppparser/cppParser.cxx +++ b/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; } diff --git a/dtool/src/cppparser/cppPreprocessor.cxx b/dtool/src/cppparser/cppPreprocessor.cxx index f0fe1c9819..a6ad3d1cad 100644 --- a/dtool/src/cppparser/cppPreprocessor.cxx +++ b/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; }