Fix #1043: set all scan string-locations to have bias, not just the first one.

This commit is contained in:
John Kessenich 2017-09-11 20:35:49 -06:00
parent a25530cc18
commit 5002c26b5e
2 changed files with 9 additions and 9 deletions

View File

@ -222,6 +222,7 @@ inline const TString String(const int i, const int /*base*/ = 10)
struct TSourceLoc { struct TSourceLoc {
void init() { name = nullptr; string = 0; line = 0; column = 0; } void init() { name = nullptr; string = 0; line = 0; column = 0; }
void init(int stringNum) { init(); string = stringNum; }
// Returns the name if it exists. Otherwise, returns the string number. // Returns the name if it exists. Otherwise, returns the string number.
std::string getStringNameOrNum(bool quoteStringName = true) const std::string getStringNameOrNum(bool quoteStringName = true) const
{ {

View File

@ -51,25 +51,24 @@ const int EndOfInput = -1;
// //
class TInputScanner { class TInputScanner {
public: public:
TInputScanner(int n, const char* const s[], size_t L[], const char* const* names = nullptr, int b = 0, int f = 0, bool single = false) : TInputScanner(int n, const char* const s[], size_t L[], const char* const* names = nullptr,
int b = 0, int f = 0, bool single = false) :
numSources(n), numSources(n),
sources(reinterpret_cast<const unsigned char* const *>(s)), // up to this point, common usage is "char*", but now we need positive 8-bit characters // up to this point, common usage is "char*", but now we need positive 8-bit characters
lengths(L), currentSource(0), currentChar(0), stringBias(b), finale(f), singleLogical(single), endOfFileReached(false) sources(reinterpret_cast<const unsigned char* const *>(s)),
lengths(L), currentSource(0), currentChar(0), stringBias(b), finale(f), singleLogical(single),
endOfFileReached(false)
{ {
loc = new TSourceLoc[numSources]; loc = new TSourceLoc[numSources];
for (int i = 0; i < numSources; ++i) { for (int i = 0; i < numSources; ++i) {
loc[i].init(); loc[i].init(i - stringBias);
} }
if (names != nullptr) { if (names != nullptr) {
for (int i = 0; i < numSources; ++i) for (int i = 0; i < numSources; ++i)
loc[i].name = names[i]; loc[i].name = names[i];
} }
loc[currentSource].string = -stringBias;
loc[currentSource].line = 1; loc[currentSource].line = 1;
loc[currentSource].column = 0; logicalSourceLoc.init(1);
logicalSourceLoc.string = 0;
logicalSourceLoc.line = 1;
logicalSourceLoc.column = 0;
logicalSourceLoc.name = loc[0].name; logicalSourceLoc.name = loc[0].name;
} }