From b7e61837d84c9fbc058b49557b8c2ec57a96dc60 Mon Sep 17 00:00:00 2001 From: starg Date: Wed, 31 Aug 2016 13:06:04 +0900 Subject: [PATCH] =?utf8?q?=E5=AD=90=E8=A6=81=E7=B4=A0=E3=82=92=20NoteAndEx?= =?utf8?q?pression=20=E3=81=8B=E3=82=89=20NoteSequence=20=E3=81=B8?= =?utf8?q?=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- include/ast/phrase.hpp | 4 ++-- src/ast2ir/phrase2ir.cpp | 6 +++--- src/parser/action_state_phrase.hpp | 8 ++------ test/parser/parsertest.cpp | 8 ++++---- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/include/ast/phrase.hpp b/include/ast/phrase.hpp index 95ffd8a..17a91e5 100644 --- a/include/ast/phrase.hpp +++ b/include/ast/phrase.hpp @@ -128,14 +128,14 @@ public: class NoteAndExpression final { public: - std::vector>> Notes; + std::vector> Notes; SourceLocation Location; }; class NoteSequence final { public: - std::vector Notes; + std::vector> Notes; SourceLocation Location; }; diff --git a/src/ast2ir/phrase2ir.cpp b/src/ast2ir/phrase2ir.cpp index db984d1..cf13e31 100644 --- a/src/ast2ir/phrase2ir.cpp +++ b/src/ast2ir/phrase2ir.cpp @@ -147,7 +147,7 @@ std::vector Phrase2IRCompiler::operator()(const AST::NoteS for (auto&& i : ast.Notes) { - auto events = (*this)(i); + auto events = i.apply_visitor(*this); ret.insert(ret.end(), events.begin(), events.end()); } @@ -163,7 +163,7 @@ std::vector Phrase2IRCompiler::operator()(const AST::NoteA for (auto&& i : ast.Notes) { - auto events = i.apply_visitor(*this); + auto events = (*this)(i.get()); ret.insert(ret.end(), events.begin(), events.end()); endTime = std::max(endTime, m_RelativeTime); @@ -220,7 +220,7 @@ std::vector Phrase2IRCompiler::operator()(const AST::NoteR { for (std::size_t k = 0; k < ast.Count; k++) { - auto events = (*this)(j); + auto events = j.apply_visitor(*this); ret.insert(ret.end(), events.begin(), events.end()); } } diff --git a/src/parser/action_state_phrase.hpp b/src/parser/action_state_phrase.hpp index 0c22945..8a55b53 100644 --- a/src/parser/action_state_phrase.hpp +++ b/src/parser/action_state_phrase.hpp @@ -24,13 +24,9 @@ namespace Parser template AST::NoteSequence MakeNoteSequence(T node) { - AST::NoteAndExpression nae; - nae.Location = node.Location; - nae.Notes.emplace_back(node); - AST::NoteSequence ns; ns.Location = node.Location; - ns.Notes.push_back(std::move(nae)); + ns.Notes.emplace_back(std::move(node)); return ns; } @@ -194,7 +190,7 @@ public: template void success(TParentState& st, TCommonStates&...) { - st.ASTNode.Notes.emplace_back(ASTNode); + st.ASTNode.Notes.emplace_back(MakeNoteSequence(ASTNode)); } void OnParse(AST::NoteSequence node) diff --git a/test/parser/parsertest.cpp b/test/parser/parsertest.cpp index c097895..17cc3b5 100644 --- a/test/parser/parsertest.cpp +++ b/test/parser/parsertest.cpp @@ -64,25 +64,25 @@ composition Main BOOST_REQUIRE_EQUAL(noteSeq.Notes.size(), 1u); - auto noteAndExpr = noteSeq.Notes.at(0); + auto noteAndExpr = boost::get(noteSeq.Notes.at(0)); BOOST_REQUIRE_EQUAL(noteAndExpr.Notes.size(), 3u); { - auto noteAndDuration = boost::get(boost::get(noteAndExpr.Notes.at(0)).Notes.at(0).Notes.at(0)); + auto noteAndDuration = boost::get(noteAndExpr.Notes.at(0).get().Notes.at(0)); BOOST_CHECK(!noteAndDuration.Duration.is_initialized()); BOOST_CHECK_EQUAL(boost::get(noteAndDuration.Note).Name.Name, 'C'); BOOST_CHECK(!boost::get(noteAndDuration.Note).Octave.is_initialized()); } { - auto noteAndDuration = boost::get(boost::get(noteAndExpr.Notes.at(1)).Notes.at(0).Notes.at(0)); + auto noteAndDuration = boost::get(noteAndExpr.Notes.at(1).get().Notes.at(0)); BOOST_CHECK(!noteAndDuration.Duration.is_initialized()); BOOST_CHECK_EQUAL(boost::get(noteAndDuration.Note).Name.Name, 'E'); BOOST_CHECK(!boost::get(noteAndDuration.Note).Octave.is_initialized()); } { - auto noteAndDuration = boost::get(boost::get(noteAndExpr.Notes.at(2)).Notes.at(0).Notes.at(0)); + auto noteAndDuration = boost::get(noteAndExpr.Notes.at(2).get().Notes.at(0)); BOOST_CHECK(!noteAndDuration.Duration.is_initialized()); BOOST_CHECK_EQUAL(boost::get(noteAndDuration.Note).Name.Name, 'G'); BOOST_CHECK(!boost::get(noteAndDuration.Note).Octave.is_initialized()); -- 2.11.0