OSDN Git Service

IRCompiler::CompileTrackBlock() 追加
authorstarg <starg@users.osdn.me>
Fri, 26 Aug 2016 19:44:50 +0000 (04:44 +0900)
committerstarg <starg@users.osdn.me>
Fri, 26 Aug 2016 20:07:06 +0000 (05:07 +0900)
include/irprocessor/irprocessor.hpp
include/message/id.hpp
src/driver/msgcallback.cpp
src/irprocessor/irprocessor.cpp
src/irprocessor/pch.hpp

index 442ae16..ce24bad 100644 (file)
@@ -18,11 +18,17 @@ public:
     {
     }
 
+    IRCompiler(const IRCompiler&) = delete;
+    IRCompiler& operator=(const IRCompiler&) = delete;
+
     bool Compile();
 
+    std::string GetSourceName() const;
     const IR::Module& GetIR() const;
 
 private:
+    void CompileTrackBlock(std::size_t index);
+
     IR::Module m_IR;
 };
 
index 382bb78..d7dede3 100644 (file)
@@ -12,6 +12,7 @@ enum class MessageID : int
     Unknown,
     UnknownInPhrase2IR,
     UnknownInComposition2IR,
+    UnknownInIRProcessor,
     UnknownInIR2MIDI,
     UnprocessedAttribute,
     DuplicatedCompositionName,
@@ -74,6 +75,9 @@ enum class MessageID : int
     GrammarPhrase4,
     GrammarPhraseName,
 
+    // IRProcessor
+    InvalidAttributeName,
+
     // IR2MIDI
     InvalidCommandName,
     WrongNumberOfCommandArguments,
index d9b3ee6..ad678fd 100644 (file)
@@ -33,6 +33,7 @@ MessagePrinter::MessagePrinter(IStdErrWriter* pStdErrWriter)
         {Message::MessageID::Unknown, ICEMessage},
         {Message::MessageID::UnknownInPhrase2IR, ICEMessage + " (Phrase2IR: Phrase = '{0}', Message = '{1}')"},
         {Message::MessageID::UnknownInComposition2IR, ICEMessage + " (Composition2IR: Composition = '{0}', Message = '{1}')"},
+        {Message::MessageID::UnknownInIRProcessor, ICEMessage + " (IRProcessor: Message = '{0}')"},
         {Message::MessageID::UnknownInIR2MIDI, ICEMessage + " (IR2MIDI: Message = '{0}')"},
         {Message::MessageID::UnprocessedAttribute, ICEMessage + " (Unprocessed attribute: '{0}')"},
         {Message::MessageID::DuplicatedCompositionName, "composition named '{0}' is already defined"},
@@ -95,6 +96,9 @@ MessagePrinter::MessagePrinter(IStdErrWriter* pStdErrWriter)
         {Message::MessageID::GrammarPhrase4, "unexpected token '{0}', expecting notes"},
         {Message::MessageID::GrammarPhraseName, "expecting valid name for phrase"},
 
+        // IRProcessor
+        {Message::MessageID::InvalidAttributeName, "invalid attribute '{0}'"},
+
         // IR2MIDI
         {Message::MessageID::InvalidCommandName, "invalid command '{0}'"},
         {Message::MessageID::WrongNumberOfCommandArguments, "wrong number of arguments passed to command '{0}'; {2} expected, {1} found"},
index 19a9f9a..f282b1e 100644 (file)
@@ -1,5 +1,9 @@
 
+#include <exception>
+
+#include <exceptions/messageexception.hpp>
 #include <irprocessor/irprocessor.hpp>
+#include <message/message.hpp>
 
 namespace YAMML
 {
@@ -9,7 +13,41 @@ namespace IRProcessor
 
 bool IRCompiler::Compile()
 {
-    return true;
+    try
+    {
+        std::size_t numberOfTrackBlocks = m_IR.TrackBlocks.size();
+
+        for (std::size_t i = 0; i < numberOfTrackBlocks; i++)
+        {
+            CompileTrackBlock(i);
+        }
+
+        return !HasErrors();
+    }
+    catch (const Exceptions::MessageException& e)
+    {
+        AddMessage(e.Item);
+        return false;
+    }
+    catch (const std::exception& e)
+    {
+        AddMessage(
+            Message::MessageItem{
+                Message::MessageKind::FetalError,
+                Message::MessageID::UnknownInIRProcessor,
+                GetSourceName(),
+                {0, 0},
+                {e.what()}
+            }
+        );
+
+        return false;
+    }
+}
+
+std::string IRCompiler::GetSourceName() const
+{
+    return m_IR.Name;
 }
 
 const IR::Module& IRCompiler::GetIR() const
@@ -17,6 +55,26 @@ const IR::Module& IRCompiler::GetIR() const
     return m_IR;
 }
 
+void IRCompiler::CompileTrackBlock(std::size_t index)
+{
+    // TODO
+
+    if (!m_IR.TrackBlocks[index].Attributes.empty())
+    {
+        auto attribute = m_IR.TrackBlocks[index].Attributes.at(0);
+
+        throw Exceptions::MessageException(
+            Message::MessageItem{
+                Message::MessageKind::Error,
+                Message::MessageID::InvalidAttributeName,
+                GetSourceName(),
+                attribute.Location,
+                {attribute.Name}
+            }
+        );
+    }
+}
+
 } // namespace IRProcessor
 
 } // namespace YAMML
index 82b185e..fd4f8fd 100644 (file)
@@ -2,6 +2,7 @@
 #pragma once
 
 #include <algorithm>
+#include <exception>
 #include <functional>
 #include <string>
 #include <unordered_map>