Found a solution to make RVO in ATNDeserializer work.

Visual Studio needs a move constructor. The move assignment is not enough. No need for the copy constructor anymore, so it can go.
This commit is contained in:
Mike Lischke 2016-04-24 12:12:45 +02:00
parent 0e5b501aa8
commit e79f917437
3 changed files with 14 additions and 16 deletions

View File

@ -20,6 +20,7 @@ using namespace antlrcpptest;
using namespace org::antlr::v4::runtime;
int main(int argc, const char * argv[]) {
ANTLRInputStream input(L"divideŴ and conquer");
TLexer lexer(&input);
CommonTokenStream tokens(&lexer);
@ -27,7 +28,7 @@ int main(int argc, const char * argv[]) {
TParser parser(&tokens);
std::shared_ptr<tree::ParseTree> tree = parser.main();
std::wstring s = tree->toStringTree(&parser);
std::wstring s = tree->toStringTree(&parser) + L"\n";
OutputDebugString(s.data());
return 0;

View File

@ -49,19 +49,16 @@ using namespace antlrcpp;
ATN::ATN() : ATN(ATNType::LEXER, 0) {
}
/**
* Required to be defined (even though not used) as we have an explicit move assignment operator.
*/
ATN::ATN(const ATN &other) {
states = other.states;
decisionToState = other.decisionToState;
ruleToStartState = other.ruleToStartState;
ruleToStopState = other.ruleToStopState;
grammarType = other.grammarType;
maxTokenType = other.maxTokenType;
ruleToTokenType = other.ruleToTokenType;
ruleToActionIndex = other.ruleToActionIndex;
modeToStartState = other.modeToStartState;
ATN::ATN(ATN &&other) {
states = std::move(other.states);
decisionToState = std::move(other.decisionToState);
ruleToStartState = std::move(other.ruleToStartState);
ruleToStopState = std::move(other.ruleToStopState);
grammarType = std::move(other.grammarType);
maxTokenType = std::move(other.maxTokenType);
ruleToTokenType = std::move(other.ruleToTokenType);
ruleToActionIndex = std::move(other.ruleToActionIndex);
modeToStartState = std::move(other.modeToStartState);
}
ATN::ATN(ATNType grammarType, size_t maxTokenType) : grammarType(grammarType), maxTokenType(maxTokenType) {
@ -69,7 +66,7 @@ ATN::ATN(ATNType grammarType, size_t maxTokenType) : grammarType(grammarType), m
ATN::~ATN() {
for (ATNState *state : states) {
//delete state;
delete state;
}
}

View File

@ -45,7 +45,7 @@ namespace atn {
/// Used for runtime deserialization of ATNs from strings.
ATN();
ATN(const ATN &other);
ATN(ATN &&other);
ATN(ATNType grammarType, size_t maxTokenType);
~ATN();