diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/preproc/Makefile | 2 | ||||
-rw-r--r-- | tools/preproc/asm_file.cpp | 22 | ||||
-rw-r--r-- | tools/preproc/asm_file.h | 2 | ||||
-rw-r--r-- | tools/preproc/charmap.cpp | 10 | ||||
-rw-r--r-- | tools/preproc/preproc.h | 20 | ||||
-rw-r--r-- | tools/preproc/utf8.cpp | 2 | ||||
-rw-r--r-- | tools/scaninc/scaninc.cpp | 9 |
7 files changed, 31 insertions, 36 deletions
diff --git a/tools/preproc/Makefile b/tools/preproc/Makefile index 10f930ebd..f504e45bd 100644 --- a/tools/preproc/Makefile +++ b/tools/preproc/Makefile @@ -1,6 +1,6 @@ CXX := g++ -CXXFLAGS := -std=c++14 -O2 +CXXFLAGS := -std=c++14 -O2 -Wall -Wno-switch SRCS := asm_file.cpp charmap.cpp preproc.cpp utf8.cpp diff --git a/tools/preproc/asm_file.cpp b/tools/preproc/asm_file.cpp index 0b42d9ab2..e2f6d81c9 100644 --- a/tools/preproc/asm_file.cpp +++ b/tools/preproc/asm_file.cpp @@ -77,15 +77,14 @@ AsmFile::~AsmFile() void AsmFile::RemoveComments() { long pos = 0; - bool inString = false; - char stringChar; + char stringChar = 0; for (;;) { if (m_buffer[pos] == 0) return; - if (inString) + if (stringChar != 0) { if (m_buffer[pos] == '\\' && m_buffer[pos + 1] == stringChar) { @@ -94,7 +93,7 @@ void AsmFile::RemoveComments() else { if (m_buffer[pos] == stringChar) - inString = false; + stringChar = 0; pos++; } } @@ -108,15 +107,14 @@ void AsmFile::RemoveComments() m_buffer[pos++] = ' '; m_buffer[pos++] = ' '; - bool inCommentString = false; - char commentStringChar; + char commentStringChar = 0; for (;;) { if (m_buffer[pos] == 0) return; - if (inCommentString) + if (commentStringChar != 0) { if (m_buffer[pos] == '\\' && m_buffer[pos + 1] == commentStringChar) { @@ -126,7 +124,7 @@ void AsmFile::RemoveComments() else { if (m_buffer[pos] == commentStringChar) - inCommentString = false; + commentStringChar = 0; if (m_buffer[pos] != '\n') m_buffer[pos] = ' '; pos++; @@ -143,10 +141,7 @@ void AsmFile::RemoveComments() else { if (m_buffer[pos] == '"' || m_buffer[pos] == '\'') - { commentStringChar = m_buffer[pos]; - inCommentString = true; - } if (m_buffer[pos] != '\n') m_buffer[pos] = ' '; pos++; @@ -157,10 +152,7 @@ void AsmFile::RemoveComments() else { if (m_buffer[pos] == '"' || m_buffer[pos] == '\'') - { stringChar = m_buffer[pos]; - inString = true; - } pos++; } } @@ -553,7 +545,7 @@ do \ void AsmFile::RaiseError(const char* format, ...) { DO_REPORT("error"); - exit(1); + std::exit(1); } // Reports a warning diagnostic. diff --git a/tools/preproc/asm_file.h b/tools/preproc/asm_file.h index 1c137d7d3..f6bfe8a36 100644 --- a/tools/preproc/asm_file.h +++ b/tools/preproc/asm_file.h @@ -65,7 +65,7 @@ private: void ExpectEmptyRestOfLine(); void ReportDiagnostic(const char* type, const char* format, std::va_list args); void RaiseError(const char* format, ...); - void RaiseWarning(const char *format, ...); + void RaiseWarning(const char* format, ...); }; #endif // ASM_FILE_H diff --git a/tools/preproc/charmap.cpp b/tools/preproc/charmap.cpp index de693eda5..c7091c4b8 100644 --- a/tools/preproc/charmap.cpp +++ b/tools/preproc/charmap.cpp @@ -51,6 +51,7 @@ public: void ExpectEqualsSign(); std::string ReadSequence(); void ExpectEmptyRestOfLine(); + void RaiseError(const char* format, ...); private: char* m_buffer; @@ -59,7 +60,6 @@ private: long m_lineNum; std::string m_filename; - void RaiseError(const char* format, ...); void RemoveComments(); std::string ReadConstant(); void SkipWhitespace(); @@ -309,6 +309,8 @@ void CharmapReader::RaiseError(const char* format, ...) va_end(args); std::fprintf(stderr, "%s:%ld: error: %s\n", m_filename.c_str(), m_lineNum, buffer); + + std::exit(1); } void CharmapReader::RemoveComments() @@ -382,12 +384,18 @@ Charmap::Charmap(std::string filename) switch (lhs.type) { case LhsType::Char: + if (m_chars.find(lhs.code) != m_chars.end()) + reader.RaiseError("redefining char"); m_chars[lhs.code] = sequence; break; case LhsType::Escape: + if (m_escapes[lhs.code].length() != 0) + reader.RaiseError("redefining escape"); m_escapes[lhs.code] = sequence; break; case LhsType::Constant: + if (m_constants.find(lhs.name) != m_constants.end()) + reader.RaiseError("redefining constant"); m_constants[lhs.name] = sequence; break; } diff --git a/tools/preproc/preproc.h b/tools/preproc/preproc.h index c9e1a8414..926748efd 100644 --- a/tools/preproc/preproc.h +++ b/tools/preproc/preproc.h @@ -25,20 +25,20 @@ #ifdef _MSC_VER -#define FATAL_ERROR(format, ...) \ -do \ -{ \ - fprintf(stderr, format, __VA_ARGS__); \ - exit(1); \ +#define FATAL_ERROR(format, ...) \ +do \ +{ \ + std::fprintf(stderr, format, __VA_ARGS__); \ + std::exit(1); \ } while (0) #else -#define FATAL_ERROR(format, ...) \ -do \ -{ \ - fprintf(stderr, format, ##__VA_ARGS__); \ - exit(1); \ +#define FATAL_ERROR(format, ...) \ +do \ +{ \ + std::fprintf(stderr, format, ##__VA_ARGS__); \ + std::exit(1); \ } while (0) #endif // _MSC_VER diff --git a/tools/preproc/utf8.cpp b/tools/preproc/utf8.cpp index 0aed83f4a..7facfd44e 100644 --- a/tools/preproc/utf8.cpp +++ b/tools/preproc/utf8.cpp @@ -61,8 +61,6 @@ static const unsigned char s_transitionTable[] = }; // Decodes UTF-8 encoded Unicode code point at "s". -// If the encoding is valid, it returns the code point and advances "s" past the byte sequence. -// If the encoding is not valid, it returns -1 and doesn't advance "s". UnicodeChar DecodeUtf8(const char* s) { UnicodeChar unicodeChar; diff --git a/tools/scaninc/scaninc.cpp b/tools/scaninc/scaninc.cpp index 9a228180a..3bd6b81a5 100644 --- a/tools/scaninc/scaninc.cpp +++ b/tools/scaninc/scaninc.cpp @@ -218,12 +218,9 @@ std::string AsmFile::ReadPath() if (c == '\n') FATAL_INPUT_ERROR("unexpected end of line character in include string\n"); - if (c == '\\') { - c = GetChar(); - - if (c != '"') - FATAL_INPUT_ERROR("unknown escape \"\\%c\" in include string\n", c); - } + // Don't bother allowing any escape sequences. + if (c == '\\') + FATAL_INPUT_ERROR("unexpected escape '\\%c' in include string\n", c); length++; |