From 5933179f43bf80f3b6e13cfb959d735a605fe9f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sat, 11 Nov 2017 12:03:41 +0100 Subject: [PATCH] Parser - Prevent built-ins from being declared local --- opparser.cc | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/opparser.cc b/opparser.cc index 1b23f13..d5e1572 100644 --- a/opparser.cc +++ b/opparser.cc @@ -210,7 +210,7 @@ struct T_ParserImpl_ M_DPARSER_( If ); M_DPARSER_( Input ); - M_DPARSER_( Local ); + M_DPARSER_( Locals ); M_DPARSER_( ODebug ); M_DPARSER_( Pipeline ); M_DPARSER_( Profile ); @@ -684,6 +684,13 @@ void T_ParserImpl_::parseFunctionArguments( continue; } + T_String const& id( token.stringValue( ) ); + if ( id == "time" || id == "width" || id == "height" ) { + errors.addNew( "cannot use built-in as argument" , + token.location( ) ); + continue; + } + const auto rv( function.addArgument( token ) ); if ( rv ) { T_StringBuilder esb; @@ -733,7 +740,7 @@ void T_ParserImpl_::parseInstructions( M_CASE_( FRAMEBUFFER , Framebuffer ); M_CASE_( IF , If ); M_CASE_( INPUT , Input ); - M_CASE_( LOCALS , Local ); + M_CASE_( LOCALS , Locals ); M_CASE_( ODBG , ODebug ); M_CASE_( PIPELINE , Pipeline ); M_CASE_( PROFILE , Profile ); @@ -959,11 +966,12 @@ M_INSTR_( Input ) /*----------------------------------------------------------------------------*/ -M_INSTR_( Local ) +M_INSTR_( Locals ) { const auto ni( input.size( ) ); if ( ni < 2 ) { - errors.addNew( "variable identifier expected" , input[ 0 ].location( ) ); + errors.addNew( "variable identifier expected" , + input[ 0 ].location( ) ); return; } @@ -978,6 +986,14 @@ M_INSTR_( Local ) token.location( ) ); continue; } + + T_String const& id( token.stringValue( ) ); + if ( id == "time" || id == "width" || id == "height" ) { + errors.addNew( "built-in cannot be declared local" , + token.location( ) ); + continue; + } + const auto prev{ instr.addVariable( token ) }; if ( !prev ) { continue;