Visitar URL original
Support of #line directive · dummyunit/simplecpp@ede2989 · GitHub
Skip to content

Commit ede2989

Browse files
committed
Support of #line directive
1 parent 6c55e17 commit ede2989

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎simplecpp.cpp‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <algorithm>
2222
#include <cctype>
23+
#include <cstdlib>
2324
#include <limits>
2425
#include <list>
2526
#include <map>
@@ -32,6 +33,7 @@
3233
#include <fstream>
3334
#include <iostream>
3435
#include <stack>
36+
#include <string>
3537

3638
#if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
3739
#include <windows.h>
@@ -392,8 +394,14 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
392394
loc.push(location);
393395
location.fileIndex = fileIndex(cback()->str.substr(1U, cback()->str.size() - 2U));
394396
location.line = 1U;
397+
} else if (lastline == "# line %num%") {
398+
loc.push(location);
399+
location.line = std::atol(cback()->str.c_str());
400+
} else if (lastline == "# line %num% %str%") {
401+
loc.push(location);
402+
location.fileIndex = fileIndex(cback()->str.substr(1U, cback()->str.size() - 2U));
403+
location.line = std::atol(cback()->previous->str.c_str());
395404
}
396-
397405
// #endfile
398406
else if (lastline == "# endfile" && !loc.empty()) {
399407
location = loc.top();
@@ -870,7 +878,8 @@ std::string simplecpp::TokenList::lastLine(int maxsize) const {
870878
continue;
871879
if (!ret.empty())
872880
ret = ' ' + ret;
873-
ret = (tok->str[0] == '\"' ? std::string("%str%") : tok->str) + ret;
881+
ret = (tok->str[0] == '\"' ? std::string("%str%")
882+
: std::isdigit(static_cast<unsigned char>(tok->str[0])) ? std::string("%num%") : tok->str) + ret;
874883
if (++count > maxsize)
875884
return "";
876885
}

0 commit comments

Comments
 (0)