From 12f580d3842192327ff46955ae2bfab5a47b3c59 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= <tseeker@nocternity.net>
Date: Fri, 17 Nov 2017 20:33:56 +0100
Subject: [PATCH] Parser - Overrides stored in the AST

---
 ebcl             |  2 +-
 opast.cc         |  3 ++-
 opast.hh         | 21 +++++++++++++++++++++
 opparser.cc      |  5 +++++
 sync.hh          |  6 ++++++
 syncoverrides.cc |  4 ++++
 6 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/ebcl b/ebcl
index 1ce16d6..5db2619 160000
--- a/ebcl
+++ b/ebcl
@@ -1 +1 @@
-Subproject commit 1ce16d63cbed4b152cd113121ecb06fb8358b9f1
+Subproject commit 5db261909a4883faf80a89a3211a11c9c5dfd7f0
diff --git a/opast.cc b/opast.cc
index e402fbe..105d2f5 100644
--- a/opast.cc
+++ b/opast.cc
@@ -1,5 +1,6 @@
 #include "externals.hh"
 #include "opast.hh"
+#include "sync.hh"
 #include <ebcl/Algorithms.hh>
 
 using namespace ebcl;
@@ -102,7 +103,7 @@ A_Node* opast::ASTVisitorBrowser(
 	    case A_Node::OP_PROGRAM: case A_Node::OP_PIPELINE:
 	    case A_Node::OP_INPUT: case A_Node::OP_FULLSCREEN:
 	    case A_Node::OP_ODBG: case A_Node::OP_LOCALS:
-	    case A_Node::OP_MAINOUT:
+	    case A_Node::OP_MAINOUT: case A_Node::OP_OVERRIDES:
 	    //
 	    case A_Node::OP_USE_FRAMEBUFFER: case A_Node::OP_USE_PIPELINE:
 	    case A_Node::OP_USE_PROGRAM: case A_Node::OP_USE_TEXTURE:
diff --git a/opast.hh b/opast.hh
index f1ab780..3c89fbc 100644
--- a/opast.hh
+++ b/opast.hh
@@ -4,6 +4,8 @@
 #include <ebcl/Sets.hh>
 
 
+struct T_SyncOverrideSection;
+
 namespace opast {
 
 
@@ -31,6 +33,7 @@ class A_Node
 		OP_LOCALS ,	// Declare local variables
 		OP_MAINOUT ,	// Select the output buffer
 		OP_ODBG ,	// Output debugging
+		OP_OVERRIDES ,	// Register input overrides
 		OP_PIPELINE ,	// Shader pipeline declaration
 		OP_PROFILE ,	// Profiling block
 		OP_PROGRAM ,	// Shader program declaration
@@ -949,6 +952,24 @@ class T_OutputDebugInstrNode : public A_InstructionNode
 		{ return locDescription_; }
 };
 
+// User interface overrides for inputs
+class T_OverridesInstrNode : public A_InstructionNode
+{
+    private:
+	T_OwnPtr< T_SyncOverrideSection > overrides_;
+
+    public:
+	T_OverridesInstrNode(
+			T_InstrListNode& parent ,
+			T_OwnPtr< T_SyncOverrideSection > overrides ) noexcept
+		: A_InstructionNode( OP_OVERRIDES , parent , E_InstrRestriction::FRAME ) ,
+			overrides_( std::move( overrides ) )
+	{ }
+
+	T_SyncOverrideSection& root( ) const noexcept
+		{ return *overrides_; }
+};
+
 // Profiling instruction
 class T_ProfileInstrNode : public A_InstructionNode
 {
diff --git a/opparser.cc b/opparser.cc
index 7a83a4c..dd69551 100644
--- a/opparser.cc
+++ b/opparser.cc
@@ -1394,7 +1394,12 @@ M_INSTR_( Overrides )
 			errors.addNew( "too many errors in UI overrides list" ,
 					input[ 0 ].location( ) );
 		}
+		return;
 	}
+
+	auto& instr{ instructions.add< T_OverridesInstrNode >(
+			ovParser.getData< T_SharedPtr< T_SyncOverrideSection > >( ).makeOwned( ) ) };
+	instr.location( ) = input[ 0 ].location( );
 }
 
 /*----------------------------------------------------------------------------*/
diff --git a/sync.hh b/sync.hh
index 99df68d..8f1d8bc 100644
--- a/sync.hh
+++ b/sync.hh
@@ -171,6 +171,7 @@ class A_SyncOverride
     private:
 	const T_String type_;
 	bool enabled_{ false };
+	ebcl::T_SRDLocation location_;
 
     protected:
 	ebcl::T_Buffer< char > title_;
@@ -197,6 +198,11 @@ class A_SyncOverride
 	bool enabled( ) const noexcept
 		{ return enabled_; }
 
+	ebcl::T_SRDLocation& location( ) noexcept
+		{ return location_; }
+	ebcl::T_SRDLocation const& location( ) const noexcept
+		{ return location_; }
+
 	// Connect the required inputs to the sync manager. Called once
 	// the inputs have been added.
 	virtual void setup( ) noexcept;
diff --git a/syncoverrides.cc b/syncoverrides.cc
index c90c72c..0ac4fe8 100644
--- a/syncoverrides.cc
+++ b/syncoverrides.cc
@@ -50,6 +50,7 @@ bool EnterFloat1_( T_SRDParserData const& data )
 	auto const& input( *( data.input ) );
 	SP_Float ptr{ NewShared< T_Float >(
 			input[ 1 ].stringValue( ) , input[ 2 ].stringValue( ) ) };
+	ptr->location( ) = input[ 0 ].location( );
 	*( data.targetData ) = std::move( ptr );
 	return true;
 }
@@ -60,6 +61,7 @@ bool EnterFloat2_( T_SRDParserData const& data )
 	SP_Float ptr{ NewShared< T_Float2 >(
 			input[ 1 ].stringValue( ) , input[ 2 ].stringValue( ) ,
 			input[ 3 ].stringValue( ) ) };
+	ptr->location( ) = input[ 0 ].location( );
 	*( data.targetData ) = std::move( ptr );
 	return true;
 }
@@ -70,6 +72,7 @@ bool EnterFloat3_( T_SRDParserData const& data )
 	SP_Float ptr{ NewShared< T_Float3 >(
 			input[ 1 ].stringValue( ) , input[ 2 ].stringValue( ) ,
 			input[ 3 ].stringValue( ) , input[ 4 ].stringValue( ) ) };
+	ptr->location( ) = input[ 0 ].location( );
 	*( data.targetData ) = std::move( ptr );
 	return true;
 }
@@ -81,6 +84,7 @@ bool EnterFloat4_( T_SRDParserData const& data )
 			input[ 1 ].stringValue( ) , input[ 2 ].stringValue( ) ,
 			input[ 3 ].stringValue( ) , input[ 4 ].stringValue( ) ,
 			input[ 5 ].stringValue( ) ) };
+	ptr->location( ) = input[ 0 ].location( );
 	*( data.targetData ) = std::move( ptr );
 	return true;
 }