thomasb8138 2017-02-20 22:27:15 +01:00
parent aacd2a2c95
commit df0cd343c1
2 changed files with 15 additions and 4 deletions

View File

@ -251,7 +251,7 @@ std::string TokenStreamRewriter::getText(const Interval &interval) {
}
std::string TokenStreamRewriter::getText(const std::string &programName, const Interval &interval) {
std::vector<TokenStreamRewriter::RewriteOperation*> rewrites = _programs[programName];
std::vector<TokenStreamRewriter::RewriteOperation*> *rewrites = &_programs[programName];
size_t start = interval.a;
size_t stop = interval.b;
@ -263,7 +263,7 @@ std::string TokenStreamRewriter::getText(const std::string &programName, const I
start = 0;
}
if (rewrites.empty() || rewrites.empty()) {
if (rewrites->empty() || rewrites->empty()) {
return tokens->getText(interval); // no instructions to execute
}
std::string buf;
@ -305,7 +305,9 @@ std::string TokenStreamRewriter::getText(const std::string &programName, const I
}
std::unordered_map<size_t, TokenStreamRewriter::RewriteOperation*> TokenStreamRewriter::reduceToSingleOperationPerIndex(
std::vector<TokenStreamRewriter::RewriteOperation*> rewrites) {
std::vector<TokenStreamRewriter::RewriteOperation*> *rewrites2) {
std::vector<TokenStreamRewriter::RewriteOperation*> rewrites = *rewrites2;
// WALK REPLACES
for (size_t i = 0; i < rewrites.size(); ++i) {
@ -403,6 +405,15 @@ std::unordered_map<size_t, TokenStreamRewriter::RewriteOperation*> TokenStreamRe
m[op->index] = op;
}
std::vector<TokenStreamRewriter::RewriteOperation*>::iterator iter1 = rewrites.begin();
std::vector<TokenStreamRewriter::RewriteOperation*>::iterator iter2 = rewrites2->begin();
for(;iter1 != rewrites.end();iter1++,iter2++) {
if ((*iter1) == nullptr) {
rewrites2->erase(iter2);
}
}
return m;
}

View File

@ -267,7 +267,7 @@ namespace antlr4 {
///
/// Return a map from token index to operation.
/// </summary>
virtual std::unordered_map<size_t, RewriteOperation*> reduceToSingleOperationPerIndex(std::vector<RewriteOperation*> rewrites);
virtual std::unordered_map<size_t, RewriteOperation*> reduceToSingleOperationPerIndex(std::vector<RewriteOperation*> *rewrites);
virtual std::string catOpText(std::string *a, std::string *b);