From 77fc213d6deb1aac808277e27557e6cc27fd99d7 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sat, 7 Mar 2015 14:47:54 +0100 Subject: [PATCH] Remove unnecessary dynamic_casts --- lib/config/config_parser.yy | 60 ++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/lib/config/config_parser.yy b/lib/config/config_parser.yy index b2ca609e9..5ed34bf53 100644 --- a/lib/config/config_parser.yy +++ b/lib/config/config_parser.yy @@ -91,6 +91,7 @@ static void MakeRBinaryOp(Expression** result, Expression *left, Expression *rig double num; bool boolean; icinga::Expression *expr; + icinga::DictExpression *dexpr; icinga::Value *variant; CombinedSetOp csop; icinga::TypeSpecifier type; @@ -197,8 +198,8 @@ static void MakeRBinaryOp(Expression** result, Expression *left, Expression *rig %type lterm_items_inner %type rterm %type rterm_array -%type rterm_scope_require_side_effect -%type rterm_scope +%type rterm_scope_require_side_effect +%type rterm_scope %type else_if_branches %type else_if_branch %type rterm_side_effect @@ -467,8 +468,7 @@ object: String type = $3; free($3); - DictExpression *exprl = dynamic_cast($6); - exprl->MakeInline(); + $6->MakeInline(); bool seen_assign = context->m_SeenAssign.top(); context->m_SeenAssign.pop(); @@ -493,7 +493,7 @@ object: filter = assign; } - $$ = new ObjectExpression(abstract, type, $4, filter, context->GetZone(), $5, exprl, DebugInfoRange(@2, @5)); + $$ = new ObjectExpression(abstract, type, $4, filter, context->GetZone(), $5, $6, DebugInfoRange(@2, @5)); } ; @@ -623,27 +623,24 @@ lterm: type | object | T_FOR '(' identifier T_FOLLOWS identifier T_IN rterm ')' rterm_scope_require_side_effect { - DictExpression *aexpr = dynamic_cast($9); - aexpr->MakeInline(); + $9->MakeInline(); - $$ = new ForExpression($3, $5, $7, aexpr, @$); + $$ = new ForExpression($3, $5, $7, $9, @$); free($3); free($5); } | T_FOR '(' identifier T_IN rterm ')' rterm_scope_require_side_effect { - DictExpression *aexpr = dynamic_cast($7); - aexpr->MakeInline(); + $7->MakeInline(); - $$ = new ForExpression($3, "", $5, aexpr, @$); + $$ = new ForExpression($3, "", $5, $7, @$); free($3); } | T_FUNCTION identifier '(' identifier_items ')' use_specifier rterm_scope { - DictExpression *aexpr = dynamic_cast($7); - aexpr->MakeInline(); + $7->MakeInline(); - FunctionExpression *fexpr = new FunctionExpression(*$4, $6, aexpr, @$); + FunctionExpression *fexpr = new FunctionExpression(*$4, $6, $7, @$); delete $4; $$ = new SetExpression(MakeIndexer(ScopeCurrent, $2), OpSetLiteral, fexpr, @$); @@ -668,10 +665,9 @@ lterm: type } | T_WHILE '(' rterm ')' rterm_scope { - DictExpression *aloop = dynamic_cast($5); - aloop->MakeInline(); + $5->MakeInline(); - $$ = new WhileExpression($3, aloop, @$); + $$ = new WhileExpression($3, $5, @$); } | rterm_side_effect ; @@ -763,10 +759,9 @@ rterm_scope: '{' else_if_branch: T_ELSE T_IF '(' rterm ')' rterm_scope { - DictExpression *atrue = dynamic_cast($6); - atrue->MakeInline(); + $6->MakeInline(); - $$ = new std::pair($4, atrue); + $$ = new std::pair($4, $6); } ; @@ -810,8 +805,7 @@ rterm_side_effect: rterm '(' rterm_items ')' } | T_IF '(' rterm ')' rterm_scope else_if_branches { - DictExpression *atrue = dynamic_cast($5); - atrue->MakeInline(); + $5->MakeInline(); std::vector > ebranches = *$6; delete $6; @@ -823,27 +817,25 @@ rterm_side_effect: rterm '(' rterm_items ')' afalse = new ConditionalExpression(ebranch.first, ebranch.second, afalse, @6); } - $$ = new ConditionalExpression($3, atrue, afalse, @$); + $$ = new ConditionalExpression($3, $5, afalse, @$); } | T_IF '(' rterm ')' rterm_scope else_if_branches T_ELSE rterm_scope { - DictExpression *atrue = dynamic_cast($5); - atrue->MakeInline(); + $5->MakeInline(); std::vector > ebranches = *$6; delete $6; - DictExpression *afalsedict = dynamic_cast($8); - afalsedict->MakeInline(); + $8->MakeInline(); - Expression *afalse = afalsedict; + Expression *afalse = $8; for (int i = ebranches.size() - 1; i >= 0; i--) { const std::pair& ebranch = ebranches[i]; afalse = new ConditionalExpression(ebranch.first, ebranch.second, afalse, @6); } - $$ = new ConditionalExpression($3, atrue, afalse, @$); + $$ = new ConditionalExpression($3, $5, afalse, @$); } ; @@ -944,10 +936,9 @@ rterm_no_side_effect: T_STRING | rterm T_XOR rterm { MakeRBinaryOp(&$$, $1, $3, @1, @3); } | T_FUNCTION '(' identifier_items ')' use_specifier rterm_scope { - DictExpression *aexpr = dynamic_cast($6); - aexpr->MakeInline(); + $6->MakeInline(); - $$ = new FunctionExpression(*$3, $5, aexpr, @$); + $$ = new FunctionExpression(*$3, $5, $6, @$); delete $3; } | T_NULLARY_LAMBDA_BEGIN statements T_NULLARY_LAMBDA_END @@ -1089,8 +1080,7 @@ apply: BOOST_THROW_EXCEPTION(ScriptError("'apply' target type '" + target + "' is invalid", DebugInfoRange(@2, @5))); } - DictExpression *exprl = dynamic_cast($8); - exprl->MakeInline(); + $8->MakeInline(); bool seen_assign = context->m_SeenAssign.top(); context->m_SeenAssign.pop(); @@ -1129,7 +1119,7 @@ apply: Expression *fterm = context->m_FTerm.top(); context->m_FTerm.pop(); - $$ = new ApplyExpression(type, target, $4, filter, fkvar, fvvar, fterm, $7, exprl, DebugInfoRange(@2, @7)); + $$ = new ApplyExpression(type, target, $4, filter, fkvar, fvvar, fterm, $7, $8, DebugInfoRange(@2, @7)); } ;