From fd0df03428d602043fb5ed66a1d41caf5125e6db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Wed, 15 Nov 2017 18:58:37 +0100 Subject: [PATCH] Refactoring - Compiler & parser moved to separate header --- control.hh | 9 --------- demo.cc | 1 + opast.hh | 29 ----------------------------- opcomp.cc | 1 + opcomp.hh | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ opparser.cc | 1 + parsercheck.cc | 1 + 7 files changed, 54 insertions(+), 38 deletions(-) create mode 100644 opcomp.hh diff --git a/control.hh b/control.hh index 9e7149d..10376b2 100644 --- a/control.hh +++ b/control.hh @@ -217,12 +217,3 @@ class X_OpFailure : public std::exception }; } // namespace ops - - -class T_OpsCompiler : public ebcl::A_PrivateImplementation -{ - public: - T_OpsCompiler( ) noexcept; - - ops::P_OpProgram compile( T_OpsParserOutput const& input ) noexcept; -}; diff --git a/demo.cc b/demo.cc index 983eabd..af73df5 100644 --- a/demo.cc +++ b/demo.cc @@ -3,6 +3,7 @@ #include "sync.hh" #include "rendertarget.hh" #include "globals.hh" +#include "opcomp.hh" #include #include diff --git a/opast.hh b/opast.hh index c84778a..f1ab780 100644 --- a/opast.hh +++ b/opast.hh @@ -1334,32 +1334,3 @@ class T_BinaryOperatorNode : public A_ExpressionNode } // namespace opast - - -/*= PARSER ===================================================================*/ - -// Parser output. Consists in a root node as well as other details (table of -// constants, data types, etc...) -struct T_OpsParserOutput -{ - opast::T_RootNode root; - T_KeyValueTable< T_String , opast::E_DataType > types; -}; - -// The actual parser -class T_OpsParser : public ebcl::A_PrivateImplementation -{ - private: - T_Array< ebcl::T_SRDError > errors_; - T_OwnPtr< T_OpsParserOutput > output_; - - public: - T_OpsParser( ) noexcept; - - bool parse( ebcl::T_SRDList const& input ) noexcept; - - T_Array< ebcl::T_SRDError > const& errors( ) const noexcept - { return errors_; } - T_OwnPtr< T_OpsParserOutput > result( ) noexcept - { return std::move( output_ ); } -}; diff --git a/opcomp.cc b/opcomp.cc index 448ef3c..7074796 100644 --- a/opcomp.cc +++ b/opcomp.cc @@ -1,5 +1,6 @@ #include "externals.hh" #include "control.hh" +#include "opcomp.hh" #include #define INVASIVE_TRACES diff --git a/opcomp.hh b/opcomp.hh new file mode 100644 index 0000000..3a92270 --- /dev/null +++ b/opcomp.hh @@ -0,0 +1,50 @@ +#pragma once +#ifndef REAL_BUILD +# include "externals.hh" +#endif +#include + + +/*= PARSER ===================================================================*/ + +namespace opast { class T_RootNode; } + +// Parser output. Consists in a root node as well as other details (table of +// constants, data types, etc...) +struct T_OpsParserOutput +{ + opast::T_RootNode root; + T_KeyValueTable< T_String , opast::E_DataType > types; +}; + +// The actual parser +class T_OpsParser : public ebcl::A_PrivateImplementation +{ + private: + T_Array< ebcl::T_SRDError > errors_; + T_OwnPtr< T_OpsParserOutput > output_; + + public: + T_OpsParser( ) noexcept; + + bool parse( ebcl::T_SRDList const& input ) noexcept; + + T_Array< ebcl::T_SRDError > const& errors( ) const noexcept + { return errors_; } + T_OwnPtr< T_OpsParserOutput > result( ) noexcept + { return std::move( output_ ); } +}; + + +/*= COMPILER ===================================================================*/ + +namespace ops { struct T_OpProgram; using P_OpProgram = T_OwnPtr< T_OpProgram >; } + +// Generates bytecode based on the type-checked tree produced by the parser +class T_OpsCompiler : public ebcl::A_PrivateImplementation +{ + public: + T_OpsCompiler( ) noexcept; + + ops::P_OpProgram compile( T_OpsParserOutput const& input ) noexcept; +}; diff --git a/opparser.cc b/opparser.cc index d9aece6..cdcd973 100644 --- a/opparser.cc +++ b/opparser.cc @@ -1,5 +1,6 @@ #include "externals.hh" #include "opast.hh" +#include "opcomp.hh" #include using namespace ebcl; diff --git a/parsercheck.cc b/parsercheck.cc index 4935c7f..9469b53 100644 --- a/parsercheck.cc +++ b/parsercheck.cc @@ -1,6 +1,7 @@ #include "externals.hh" #include "opast.hh" #include "control.hh" +#include "opcomp.hh" #include #include #include