String initconfig = Application::GetSysconfDir() + "/icinga2/init.conf";
if (Utility::PathExists(initconfig)) {
- Expression *expression;
+ std::unique_ptr<Expression> expression;
try {
expression = ConfigCompiler::CompileFile(initconfig);
ScriptFrame frame;
expression->Evaluate(frame);
} catch (const std::exception& ex) {
- delete expression;
-
Log(LogCritical, "config", DiagnosticInformation(ex));
return EXIT_FAILURE;
}
-
- delete expression;
}
if (!autocomplete)
extern "C" void dbg_eval(const char *text)
{
- Expression *expr = nullptr;
+ std::unique_ptr<Expression> expr;
try {
ScriptFrame frame;
} catch (const std::exception& ex) {
std::cout << "Error: " << DiagnosticInformation(ex) << "\n";
}
-
- delete expr;
}
extern "C" void dbg_eval_with_value(const Value& value, const char *text)
{
- Expression *expr = nullptr;
+ std::unique_ptr<Expression> expr;
try {
ScriptFrame frame;
} catch (const std::exception& ex) {
std::cout << "Error: " << DiagnosticInformation(ex) << "\n";
}
-
- delete expr;
}
extern "C" void dbg_eval_with_object(Object *object, const char *text)
{
- Expression *expr = nullptr;
+ std::unique_ptr<Expression> expr;
try {
ScriptFrame frame;
} catch (const std::exception& ex) {
std::cout << "Error: " << DiagnosticInformation(ex) << "\n";
}
-
- delete expr;
}
void ConsoleCommand::BreakpointHandler(ScriptFrame& frame, ScriptError *ex, const DebugInfo& di)
command += line;
- Expression *expr = nullptr;
+ std::unique_ptr<Expression> expr;
try {
lines[fileName] = command;
/* This relies on the fact that - for syntax errors - CompileText()
* returns an AST where the top-level expression is a 'throw'. */
- if (!syntaxOnly || dynamic_cast<ThrowExpression *>(expr)) {
+ if (!syntaxOnly || dynamic_cast<ThrowExpression *>(expr.get())) {
if (syntaxOnly)
std::cerr << " => " << command << std::endl;
result = Serialize(expr->Evaluate(scriptFrame), 0);
if (!commandOnce.IsEmpty())
return EXIT_FAILURE;
}
-
- delete expr;
}
return EXIT_SUCCESS;
/* register this zone path for cluster config sync */
ConfigCompiler::RegisterZoneDir("_etc", path, zoneName);
- std::vector<Expression *> expressions;
+ std::vector<std::unique_ptr<Expression> > expressions;
Utility::GlobRecursive(path, "*.conf", std::bind(&ConfigCompiler::CollectIncludes, std::ref(expressions), _1, zoneName, package), GlobFile);
- DictExpression expr(expressions);
+ DictExpression expr(std::move(expressions));
if (!ExecuteExpression(&expr))
success = false;
}
return;
}
- std::vector<Expression *> expressions;
+ std::vector<std::unique_ptr<Expression> > expressions;
Utility::GlobRecursive(zonePath, "*.conf", std::bind(&ConfigCompiler::CollectIncludes, std::ref(expressions), _1, zoneName, package), GlobFile);
- DictExpression expr(expressions);
+ DictExpression expr(std::move(expressions));
if (!ExecuteExpression(&expr))
success = false;
}
String packageName = Utility::BaseName(packagePath);
if (Utility::PathExists(packagePath + "/include.conf")) {
- Expression *expr = ConfigCompiler::CompileFile(packagePath + "/include.conf",
+ std::unique_ptr<Expression> expr = ConfigCompiler::CompileFile(packagePath + "/include.conf",
String(), packageName);
- if (!ExecuteExpression(expr))
+ if (!ExecuteExpression(&*expr))
success = false;
-
- delete expr;
}
}
if (!configs.empty()) {
for (const String& configPath : configs) {
try {
- Expression *expression = ConfigCompiler::CompileFile(configPath, String(), "_etc");
- success = ExecuteExpression(expression);
- delete expression;
+ std::unique_ptr<Expression> expression = ConfigCompiler::CompileFile(configPath, String(), "_etc");
+ success = ExecuteExpression(&*expression);
if (!success)
return false;
} catch (const std::exception& ex) {
template<typename T>
static void MakeRBinaryOp(Expression** result, Expression *left, Expression *right, const DebugInfo& diLeft, const DebugInfo& diRight)
{
- *result = new T(left, right, DebugInfoRange(diLeft, diRight));
+ *result = new T(std::unique_ptr<Expression>(left), std::unique_ptr<Expression>(right), DebugInfoRange(diLeft, diRight));
}
%}
%error-verbose
%glr-parser
-%parse-param { std::vector<std::pair<Expression *, EItemInfo> > *llist }
+%parse-param { std::vector<std::pair<std::unique_ptr<Expression>, EItemInfo> > *llist }
%parse-param { ConfigCompiler *context }
%lex-param { void *scanner }
icinga::DictExpression *dexpr;
CombinedSetOp csop;
std::vector<String> *slist;
- std::vector<std::pair<Expression *, EItemInfo> > *llist;
- std::vector<Expression *> *elist;
- std::vector<std::pair<Expression *, Expression *> > *ebranchlist;
- std::pair<Expression *, Expression *> *ebranch;
- std::pair<String, Expression *> *cvitem;
- std::map<String, Expression *> *cvlist;
+ std::vector<std::pair<std::unique_ptr<Expression>, EItemInfo> > *llist;
+ std::vector<std::unique_ptr<Expression> > *elist;
+ std::vector<std::pair<std::unique_ptr<Expression>, std::unique_ptr<Expression> > > *ebranchlist;
+ std::pair<std::unique_ptr<Expression>, std::unique_ptr<Expression> > *ebranch;
+ std::pair<String, std::unique_ptr<Expression> > *cvitem;
+ std::map<String, std::unique_ptr<Expression> > *cvlist;
icinga::ScopeSpecifier scope;
}
extern int yydebug;
-void yyerror(const YYLTYPE *locp, std::vector<std::pair<Expression *, EItemInfo> > *, ConfigCompiler *context, const char *err)
+void yyerror(const YYLTYPE *locp, std::vector<std::pair<std::unique_ptr<Expression>, EItemInfo> > *, ConfigCompiler *context, const char *err)
{
bool incomplete = context && context->m_Eof && (context->m_OpenBraces > 0);
BOOST_THROW_EXCEPTION(ScriptError(err, *locp, incomplete));
}
-int yyparse(std::vector<std::pair<Expression *, EItemInfo> > *llist, ConfigCompiler *context);
+int yyparse(std::vector<std::pair<std::unique_ptr<Expression>, EItemInfo> > *llist, ConfigCompiler *context);
static void BeginFlowControlBlock(ConfigCompiler *compiler, int allowedTypes, bool inherit)
{
BOOST_THROW_EXCEPTION(ScriptError("Invalid flow control statement.", location));
}
-Expression *ConfigCompiler::Compile(void)
+std::unique_ptr<Expression> ConfigCompiler::Compile(void)
{
- std::vector<std::pair<Expression *, EItemInfo> > llist;
+ std::vector<std::pair<std::unique_ptr<Expression>, EItemInfo> > llist;
//yydebug = 1;
EndFlowControlBlock(this);
m_IgnoreNewlines.pop();
- std::vector<Expression *> dlist;
- std::vector<std::pair<Expression *, EItemInfo> >::size_type num = 0;
- for (const auto& litem : llist) {
+ std::vector<std::unique_ptr<Expression> > dlist;
+ decltype(llist.size()) num = 0;
+ for (auto& litem : llist) {
if (!litem.second.SideEffect && num != llist.size() - 1) {
yyerror(&litem.second.DebugInfo, NULL, NULL, "Value computed is not used.");
}
- dlist.push_back(litem.first);
+ dlist.push_back(std::move(litem.first));
num++;
}
- DictExpression *expr = new DictExpression(dlist);
+ std::unique_ptr<DictExpression> expr{new DictExpression(std::move(dlist))};
expr->MakeInline();
- return expr;
+ return std::move(expr);
}
#define scanner (context->GetScanner())
lterm_items: /* empty */
{
- $$ = new std::vector<std::pair<Expression *, EItemInfo> >();
+ $$ = new std::vector<std::pair<std::unique_ptr<Expression>, EItemInfo> >();
}
| lterm_items_inner
| lterm_items_inner sep
lterm_items_inner: lterm %dprec 2
{
- $$ = new std::vector<std::pair<Expression *, EItemInfo> >();
+ $$ = new std::vector<std::pair<std::unique_ptr<Expression>, EItemInfo> >();
EItemInfo info = { true, @1 };
- $$->emplace_back($1, info);
+ $$->emplace_back(std::unique_ptr<Expression>($1), info);
}
| rterm_no_side_effect
{
- $$ = new std::vector<std::pair<Expression *, EItemInfo> >();
+ $$ = new std::vector<std::pair<std::unique_ptr<Expression>, EItemInfo> >();
EItemInfo info = { false, @1 };
- $$->emplace_back($1, info);
+ $$->emplace_back(std::unique_ptr<Expression>($1), info);
}
| lterm_items_inner sep lterm %dprec 1
{
if ($1)
$$ = $1;
else
- $$ = new std::vector<std::pair<Expression *, EItemInfo> >();
+ $$ = new std::vector<std::pair<std::unique_ptr<Expression>, EItemInfo> >();
if ($3) {
EItemInfo info = { true, @3 };
- $$->emplace_back($3, info);
+ $$->emplace_back(std::unique_ptr<Expression>($3), info);
}
}
| lterm_items_inner sep rterm_no_side_effect %dprec 1
if ($1)
$$ = $1;
else
- $$ = new std::vector<std::pair<Expression *, EItemInfo> >();
+ $$ = new std::vector<std::pair<std::unique_ptr<Expression>, EItemInfo> >();
if ($3) {
EItemInfo info = { false, @3 };
- $$->emplace_back($3, info);
+ $$->emplace_back(std::unique_ptr<Expression>($3), info);
}
}
;
bool seen_ignore = context->m_SeenIgnore.top();
context->m_SeenIgnore.pop();
- Expression *ignore = context->m_Ignore.top();
+ std::unique_ptr<Expression> ignore{std::move(context->m_Ignore.top())};
context->m_Ignore.pop();
- Expression *assign = context->m_Assign.top();
+ std::unique_ptr<Expression> assign{std::move(context->m_Assign.top())};
context->m_Assign.pop();
- Expression *filter = NULL;
+ std::unique_ptr<Expression> filter;
if (seen_assign) {
if (ignore) {
- Expression *rex = new LogicalNegateExpression(ignore, DebugInfoRange(@2, @5));
+ std::unique_ptr<Expression> rex{new LogicalNegateExpression(std::move(ignore), DebugInfoRange(@2, @5))};
- filter = new LogicalAndExpression(assign, rex, DebugInfoRange(@2, @5));
+ filter.reset(new LogicalAndExpression(std::move(assign), std::move(rex), DebugInfoRange(@2, @5)));
} else
- filter = assign;
+ filter.swap(assign);
} else if (seen_ignore) {
BOOST_THROW_EXCEPTION(ScriptError("object rule 'ignore where' cannot be used without 'assign where'", DebugInfoRange(@2, @4)));
}
- $$ = new ObjectExpression(abstract, $3, $4, filter, context->GetZone(), context->GetPackage(), $5, $6, $7, $9, DebugInfoRange(@2, @7));
+ $$ = new ObjectExpression(abstract, std::unique_ptr<Expression>($3), std::unique_ptr<Expression>($4),
+ std::move(filter), context->GetZone(), context->GetPackage(), std::move(*$5), $6, $7, std::unique_ptr<Expression>($9), DebugInfoRange(@2, @7));
+ delete $5;
}
;
lterm: T_LIBRARY rterm
{
- $$ = new LibraryExpression($2, @$);
+ $$ = new LibraryExpression(std::unique_ptr<Expression>($2), @$);
}
| rterm combined_set_op rterm
{
- $$ = new SetExpression($1, $2, $3, @$);
+ $$ = new SetExpression(std::unique_ptr<Expression>($1), $2, std::unique_ptr<Expression>($3), @$);
}
| T_INCLUDE rterm
{
- $$ = new IncludeExpression(Utility::DirName(context->GetPath()), $2, NULL, NULL, IncludeRegular, false, context->GetZone(), context->GetPackage(), @$);
+ $$ = new IncludeExpression(Utility::DirName(context->GetPath()), std::unique_ptr<Expression>($2), NULL, NULL, IncludeRegular, false, context->GetZone(), context->GetPackage(), @$);
}
| T_INCLUDE T_STRING_ANGLE
{
}
| T_INCLUDE_RECURSIVE rterm
{
- $$ = new IncludeExpression(Utility::DirName(context->GetPath()), $2, MakeLiteral("*.conf"), NULL, IncludeRecursive, false, context->GetZone(), context->GetPackage(), @$);
+ $$ = new IncludeExpression(Utility::DirName(context->GetPath()), std::unique_ptr<Expression>($2), MakeLiteral("*.conf"), NULL, IncludeRecursive, false, context->GetZone(), context->GetPackage(), @$);
}
| T_INCLUDE_RECURSIVE rterm ',' rterm
{
- $$ = new IncludeExpression(Utility::DirName(context->GetPath()), $2, $4, NULL, IncludeRecursive, false, context->GetZone(), context->GetPackage(), @$);
+ $$ = new IncludeExpression(Utility::DirName(context->GetPath()), std::unique_ptr<Expression>($2), std::unique_ptr<Expression>($4), NULL, IncludeRecursive, false, context->GetZone(), context->GetPackage(), @$);
}
| T_INCLUDE_ZONES rterm ',' rterm
{
- $$ = new IncludeExpression(Utility::DirName(context->GetPath()), $4, MakeLiteral("*.conf"), $2, IncludeZones, false, context->GetZone(), context->GetPackage(), @$);
+ $$ = new IncludeExpression(Utility::DirName(context->GetPath()), std::unique_ptr<Expression>($4), MakeLiteral("*.conf"), std::unique_ptr<Expression>($2), IncludeZones, false, context->GetZone(), context->GetPackage(), @$);
}
| T_INCLUDE_ZONES rterm ',' rterm ',' rterm
{
- $$ = new IncludeExpression(Utility::DirName(context->GetPath()), $4, $6, $2, IncludeZones, false, context->GetZone(), context->GetPackage(), @$);
+ $$ = new IncludeExpression(Utility::DirName(context->GetPath()), std::unique_ptr<Expression>($4), std::unique_ptr<Expression>($6), std::unique_ptr<Expression>($2), IncludeZones, false, context->GetZone(), context->GetPackage(), @$);
}
| T_IMPORT rterm
{
- $$ = new ImportExpression($2, @$);
+ $$ = new ImportExpression(std::unique_ptr<Expression>($2), @$);
}
| T_ASSIGN T_WHERE
{
context->m_SeenAssign.top() = true;
if (context->m_Assign.top())
- context->m_Assign.top() = new LogicalOrExpression(context->m_Assign.top(), $4, @$);
+ context->m_Assign.top() = new LogicalOrExpression(std::unique_ptr<Expression>(context->m_Assign.top()), std::unique_ptr<Expression>($4), @$);
else
context->m_Assign.top() = $4;
- $$ = MakeLiteral();
+ $$ = MakeLiteralRaw();
}
| T_ASSIGN T_WHERE rterm %dprec 1
{
context->m_SeenAssign.top() = true;
if (context->m_Assign.top())
- context->m_Assign.top() = new LogicalOrExpression(context->m_Assign.top(), $3, @$);
+ context->m_Assign.top() = new LogicalOrExpression(std::unique_ptr<Expression>(context->m_Assign.top()), std::unique_ptr<Expression>($3), @$);
else
context->m_Assign.top() = $3;
- $$ = MakeLiteral();
+ $$ = MakeLiteralRaw();
}
| T_IGNORE T_WHERE
{
context->m_SeenIgnore.top() = true;
if (context->m_Ignore.top())
- context->m_Ignore.top() = new LogicalOrExpression(context->m_Ignore.top(), $4, @$);
+ context->m_Ignore.top() = new LogicalOrExpression(std::unique_ptr<Expression>(context->m_Ignore.top()), std::unique_ptr<Expression>($4), @$);
else
context->m_Ignore.top() = $4;
- $$ = MakeLiteral();
+ $$ = MakeLiteralRaw();
}
| T_IGNORE T_WHERE rterm %dprec 1
{
context->m_SeenIgnore.top() = true;
if (context->m_Ignore.top())
- context->m_Ignore.top() = new LogicalOrExpression(context->m_Ignore.top(), $3, @$);
+ context->m_Ignore.top() = new LogicalOrExpression(std::unique_ptr<Expression>(context->m_Ignore.top()), std::unique_ptr<Expression>($3), @$);
else
context->m_Ignore.top() = $3;
- $$ = MakeLiteral();
+ $$ = MakeLiteralRaw();
}
| T_RETURN optional_rterm
{
UseFlowControl(context, FlowControlReturn, @$);
- $$ = new ReturnExpression($2, @$);
+ $$ = new ReturnExpression(std::unique_ptr<Expression>($2), @$);
}
| T_BREAK
{
}
| T_USING rterm
{
- $$ = new UsingExpression($2, @$);
+ $$ = new UsingExpression(std::unique_ptr<Expression>($2), @$);
}
| apply
| object
{
EndFlowControlBlock(context);
- $$ = new ForExpression(*$3, *$5, $7, $10, @$);
+ $$ = new ForExpression(*$3, *$5, std::unique_ptr<Expression>($7), std::unique_ptr<Expression>($10), @$);
delete $3;
delete $5;
}
{
EndFlowControlBlock(context);
- $$ = new ForExpression(*$3, "", $5, $8, @$);
+ $$ = new ForExpression(*$3, "", std::unique_ptr<Expression>($5), std::unique_ptr<Expression>($8), @$);
delete $3;
}
| T_FUNCTION identifier '(' identifier_items ')' use_specifier
{
EndFlowControlBlock(context);
- FunctionExpression *fexpr = new FunctionExpression(*$2, *$4, $6, $8, @$);
+ std::unique_ptr<FunctionExpression> fexpr{new FunctionExpression(*$2, *$4, std::move(*$6), std::unique_ptr<Expression>($8), @$)};
delete $4;
+ delete $6;
- $$ = new SetExpression(MakeIndexer(ScopeThis, *$2), OpSetLiteral, fexpr, @$);
+ $$ = new SetExpression(MakeIndexer(ScopeThis, *$2), OpSetLiteral, std::move(fexpr), @$);
delete $2;
}
| T_CONST T_IDENTIFIER T_SET rterm
{
- $$ = new SetExpression(MakeIndexer(ScopeGlobal, *$2), OpSetLiteral, $4);
+ $$ = new SetExpression(MakeIndexer(ScopeGlobal, *$2), OpSetLiteral, std::unique_ptr<Expression>($4));
delete $2;
}
| T_VAR rterm
{
- Expression *expr = $2;
+ std::unique_ptr<Expression> expr{$2};
BindToScope(expr, ScopeLocal);
- $$ = new SetExpression(expr, OpSetLiteral, MakeLiteral(), @$);
+ $$ = new SetExpression(std::move(expr), OpSetLiteral, MakeLiteral(), @$);
}
| T_VAR rterm combined_set_op rterm
{
- Expression *expr = $2;
+ std::unique_ptr<Expression> expr{$2};
BindToScope(expr, ScopeLocal);
- $$ = new SetExpression(expr, $3, $4, @$);
+ $$ = new SetExpression(std::move(expr), $3, std::unique_ptr<Expression>($4), @$);
}
| T_WHILE '(' rterm ')'
{
{
EndFlowControlBlock(context);
- $$ = new WhileExpression($3, $6, @$);
+ $$ = new WhileExpression(std::unique_ptr<Expression>($3), std::unique_ptr<Expression>($6), @$);
}
| T_THROW rterm
{
- $$ = new ThrowExpression($2, false, @$);
+ $$ = new ThrowExpression(std::unique_ptr<Expression>($2), false, @$);
}
| T_TRY rterm_scope T_EXCEPT rterm_scope
{
- $$ = new TryExceptExpression($2, $4, @$);
+ $$ = new TryExceptExpression(std::unique_ptr<Expression>($2), std::unique_ptr<Expression>($4), @$);
}
| rterm_side_effect
;
rterm_items: /* empty */
{
- $$ = new std::vector<Expression *>();
+ $$ = new std::vector<std::unique_ptr<Expression> >();
}
| rterm_items_inner
| rterm_items_inner ','
rterm_items_inner: rterm
{
- $$ = new std::vector<Expression *>();
- $$->push_back($1);
+ $$ = new std::vector<std::unique_ptr<Expression> >();
+ $$->emplace_back($1);
}
| rterm_items_inner arraysep rterm
{
$$ = $1;
- $$->push_back($3);
+ $$->emplace_back($3);
}
;
newlines rterm_items ']'
{
context->m_OpenBraces--;
- $$ = new ArrayExpression(*$4, @$);
+ $$ = new ArrayExpression(std::move(*$4), @$);
delete $4;
}
| '['
rterm_items ']'
{
context->m_OpenBraces--;
- $$ = new ArrayExpression(*$3, @$);
+ $$ = new ArrayExpression(std::move(*$3), @$);
delete $3;
}
;
EndFlowControlBlock(context);
context->m_OpenBraces--;
context->m_IgnoreNewlines.pop();
- std::vector<Expression *> dlist;
- typedef std::pair<Expression *, EItemInfo> EListItem;
- int num = 0;
- for (const EListItem& litem : *$3) {
+ std::vector<std::unique_ptr<Expression> > dlist;
+ for (auto& litem : *$3) {
if (!litem.second.SideEffect)
yyerror(&litem.second.DebugInfo, NULL, NULL, "Value computed is not used.");
- dlist.push_back(litem.first);
- num++;
+ dlist.push_back(std::move(litem.first));
}
delete $3;
- $$ = new DictExpression(dlist, @$);
+ $$ = new DictExpression(std::move(dlist), @$);
}
;
{
context->m_OpenBraces--;
context->m_IgnoreNewlines.pop();
- std::vector<Expression *> dlist;
- typedef std::pair<Expression *, EItemInfo> EListItem;
- int num = 0;
- for (const EListItem& litem : *$3) {
+ std::vector<std::unique_ptr<Expression> > dlist;
+ for (auto& litem : *$3) {
if (!litem.second.SideEffect)
yyerror(&litem.second.DebugInfo, NULL, NULL, "Value computed is not used.");
- dlist.push_back(litem.first);
- num++;
+ dlist.push_back(std::move(litem.first));
}
delete $3;
- $$ = new DictExpression(dlist, @$);
+ $$ = new DictExpression(std::move(dlist), @$);
$$->MakeInline();
}
;
{
context->m_OpenBraces--;
context->m_IgnoreNewlines.pop();
- std::vector<Expression *> dlist;
- typedef std::pair<Expression *, EItemInfo> EListItem;
- std::vector<std::pair<Expression *, EItemInfo> >::size_type num = 0;
- for (const EListItem& litem : *$3) {
+ std::vector<std::unique_ptr<Expression> > dlist;
+ decltype($3->size()) num = 0;
+ for (auto& litem : *$3) {
if (!litem.second.SideEffect && num != $3->size() - 1)
yyerror(&litem.second.DebugInfo, NULL, NULL, "Value computed is not used.");
- dlist.push_back(litem.first);
+ dlist.push_back(std::move(litem.first));
num++;
}
delete $3;
- $$ = new DictExpression(dlist, @$);
+ $$ = new DictExpression(std::move(dlist), @$);
$$->MakeInline();
}
;
else_if_branch: T_ELSE T_IF '(' rterm ')' rterm_scope
{
- $$ = new std::pair<Expression *, Expression *>($4, $6);
+ $$ = new std::pair<std::unique_ptr<Expression>, std::unique_ptr<Expression> >(std::unique_ptr<Expression>($4), std::unique_ptr<Expression>($6));
}
;
else_if_branches: /* empty */
{
- $$ = new std::vector<std::pair<Expression *, Expression *> >();
+ $$ = new std::vector<std::pair<std::unique_ptr<Expression>, std::unique_ptr<Expression> > >();
}
| else_if_branches else_if_branch
{
$$ = $1;
- $$->push_back(*$2);
+ $$->push_back(std::move(*$2));
delete $2;
}
;
rterm_side_effect: rterm '(' rterm_items ')'
{
- $$ = new FunctionCallExpression($1, *$3, @$);
+ $$ = new FunctionCallExpression(std::unique_ptr<Expression>($1), std::move(*$3), @$);
delete $3;
}
| T_IF '(' rterm ')' rterm_scope else_if_branches
{
- std::vector<std::pair<Expression *, Expression *> > ebranches = *$6;
+ std::vector<std::pair<std::unique_ptr<Expression>, std::unique_ptr<Expression> > > ebranches;
+ $6->swap(ebranches);
delete $6;
- Expression *afalse = NULL;
+ std::unique_ptr<Expression> afalse;
for (int i = ebranches.size() - 1; i >= 0; i--) {
- const std::pair<Expression *, Expression *>& ebranch = ebranches[i];
- afalse = new ConditionalExpression(ebranch.first, ebranch.second, afalse, @6);
+ auto& ebranch = ebranches[i];
+ afalse.reset(new ConditionalExpression(std::move(ebranch.first), std::move(ebranch.second), std::move(afalse), @6));
}
- $$ = new ConditionalExpression($3, $5, afalse, @$);
+ $$ = new ConditionalExpression(std::unique_ptr<Expression>($3), std::unique_ptr<Expression>($5), std::move(afalse), @$);
}
| T_IF '(' rterm ')' rterm_scope else_if_branches T_ELSE rterm_scope
{
- std::vector<std::pair<Expression *, Expression *> > ebranches = *$6;
+ std::vector<std::pair<std::unique_ptr<Expression>, std::unique_ptr<Expression> > > ebranches;
+ $6->swap(ebranches);
delete $6;
$8->MakeInline();
- Expression *afalse = $8;
+ std::unique_ptr<Expression> afalse{$8};
for (int i = ebranches.size() - 1; i >= 0; i--) {
- const std::pair<Expression *, Expression *>& ebranch = ebranches[i];
- afalse = new ConditionalExpression(ebranch.first, ebranch.second, afalse, @6);
+ auto& ebranch = ebranches[i];
+ afalse.reset(new ConditionalExpression(std::move(ebranch.first), std::move(ebranch.second), std::move(afalse), @6));
}
- $$ = new ConditionalExpression($3, $5, afalse, @$);
+ $$ = new ConditionalExpression(std::unique_ptr<Expression>($3), std::unique_ptr<Expression>($5), std::move(afalse), @$);
}
;
rterm_no_side_effect_no_dict: T_STRING
{
- $$ = MakeLiteral(*$1);
+ $$ = MakeLiteralRaw(*$1);
delete $1;
}
| T_NUMBER
{
- $$ = MakeLiteral($1);
+ $$ = MakeLiteralRaw($1);
}
| T_BOOLEAN
{
- $$ = MakeLiteral($1);
+ $$ = MakeLiteralRaw($1);
}
| T_NULL
{
- $$ = MakeLiteral();
+ $$ = MakeLiteralRaw();
}
| rterm '.' T_IDENTIFIER %dprec 2
{
- $$ = new IndexerExpression($1, MakeLiteral(*$3), @$);
+ $$ = new IndexerExpression(std::unique_ptr<Expression>($1), MakeLiteral(*$3), @$);
delete $3;
}
| rterm '[' rterm ']'
{
- $$ = new IndexerExpression($1, $3, @$);
+ $$ = new IndexerExpression(std::unique_ptr<Expression>($1), std::unique_ptr<Expression>($3), @$);
}
| T_IDENTIFIER
{
}
| '!' rterm
{
- $$ = new LogicalNegateExpression($2, @$);
+ $$ = new LogicalNegateExpression(std::unique_ptr<Expression>($2), @$);
}
| '~' rterm
{
- $$ = new NegateExpression($2, @$);
+ $$ = new NegateExpression(std::unique_ptr<Expression>($2), @$);
}
| T_PLUS rterm %prec UNARY_PLUS
{
}
| T_MINUS rterm %prec UNARY_MINUS
{
- $$ = new SubtractExpression(MakeLiteral(0), $2, @$);
+ $$ = new SubtractExpression(MakeLiteral(0), std::unique_ptr<Expression>($2), @$);
}
| T_THIS
{
}
| T_CURRENT_FILENAME
{
- $$ = MakeLiteral(@$.Path);
+ $$ = MakeLiteralRaw(@$.Path);
}
| T_CURRENT_LINE
{
- $$ = MakeLiteral(@$.FirstLine);
+ $$ = MakeLiteralRaw(@$.FirstLine);
}
| identifier T_FOLLOWS
{
args.push_back(*$1);
delete $1;
- $$ = new FunctionExpression("<anonymous>", args, new std::map<String, Expression *>(), $4, @$);
+ $$ = new FunctionExpression("<anonymous>", args, {}, std::unique_ptr<Expression>($4), @$);
}
| identifier T_FOLLOWS rterm %dprec 1
{
args.push_back(*$1);
delete $1;
- $$ = new FunctionExpression("<anonymous>", args, new std::map<String, Expression *>(), $3, @$);
+ $$ = new FunctionExpression("<anonymous>", args, {}, std::unique_ptr<Expression>($3), @$);
}
| '(' identifier_items ')' T_FOLLOWS
{
{
EndFlowControlBlock(context);
- $$ = new FunctionExpression("<anonymous>", *$2, new std::map<String, Expression *>(), $6, @$);
+ $$ = new FunctionExpression("<anonymous>", *$2, {}, std::unique_ptr<Expression>($6), @$);
delete $2;
}
| '(' identifier_items ')' T_FOLLOWS rterm %dprec 1
{
ASSERT(!dynamic_cast<DictExpression *>($5));
- $$ = new FunctionExpression("<anonymous>", *$2, new std::map<String, Expression *>(), $5, @$);
+ $$ = new FunctionExpression("<anonymous>", *$2, {}, std::unique_ptr<Expression>($5), @$);
delete $2;
}
| rterm_array
{
EndFlowControlBlock(context);
- $$ = new FunctionExpression("<anonymous>", *$3, $5, $7, @$);
+ $$ = new FunctionExpression("<anonymous>", *$3, std::move(*$5), std::unique_ptr<Expression>($7), @$);
delete $3;
+ delete $5;
}
| T_NULLARY_LAMBDA_BEGIN
{
{
EndFlowControlBlock(context);
- std::vector<Expression *> dlist;
- typedef std::pair<Expression *, EItemInfo> EListItem;
- std::vector<std::pair<Expression *, EItemInfo> >::size_type num = 0;
- for (const EListItem& litem : *$3) {
+ std::vector<std::unique_ptr<Expression> > dlist;
+ decltype(dlist.size()) num = 0;
+ for (auto& litem : *$3) {
if (!litem.second.SideEffect && num != $3->size() - 1)
yyerror(&litem.second.DebugInfo, NULL, NULL, "Value computed is not used.");
- dlist.push_back(litem.first);
+ dlist.push_back(std::move(litem.first));
num++;
}
delete $3;
- DictExpression *aexpr = new DictExpression(dlist, @$);
+ std::unique_ptr<DictExpression> aexpr{new DictExpression(std::move(dlist), @$)};
aexpr->MakeInline();
- $$ = new FunctionExpression("<anonymous>", std::vector<String>(), NULL, aexpr, @$);
+ $$ = new FunctionExpression("<anonymous>", {}, {}, std::move(aexpr), @$);
}
;
rterm_no_side_effect_no_dict %dprec 1
| rterm_dict %dprec 2
{
- Expression *expr = $1;
+ std::unique_ptr<Expression> expr{$1};
BindToScope(expr, ScopeThis);
- $$ = expr;
+ $$ = expr.release();
}
;
use_specifier: /* empty */
{
- $$ = NULL;
+ $$ = new std::map<String, std::unique_ptr<Expression> >();
}
| T_USE '(' use_specifier_items ')'
{
use_specifier_items: use_specifier_item
{
- $$ = new std::map<String, Expression *>();
- $$->insert(*$1);
+ $$ = new std::map<String, std::unique_ptr<Expression> >();
+ $$->insert(std::move(*$1));
delete $1;
}
| use_specifier_items ',' use_specifier_item
{
$$ = $1;
- $$->insert(*$3);
+ $$->insert(std::move(*$3));
delete $3;
}
;
use_specifier_item: identifier
{
- $$ = new std::pair<String, Expression *>(*$1, new VariableExpression(*$1, @1));
+ $$ = new std::pair<String, std::unique_ptr<Expression> >(*$1, std::unique_ptr<Expression>(new VariableExpression(*$1, @1)));
delete $1;
}
| identifier T_SET rterm
{
- $$ = new std::pair<String, Expression *>(*$1, $3);
+ $$ = new std::pair<String, std::unique_ptr<Expression> >(*$1, std::unique_ptr<Expression>($3));
delete $1;
}
;
optional_rterm: /* empty */
{
- $$ = MakeLiteral();
+ $$ = MakeLiteralRaw();
}
| rterm
;
if (!seen_assign && !context->m_FTerm.top())
BOOST_THROW_EXCEPTION(ScriptError("'apply' is missing 'assign'/'for'", DebugInfoRange(@2, @3)));
- Expression *ignore = context->m_Ignore.top();
+ std::unique_ptr<Expression> ignore{context->m_Ignore.top()};
context->m_Ignore.pop();
- Expression *assign;
+ std::unique_ptr<Expression> assign;
if (!seen_assign)
assign = MakeLiteral(true);
else
- assign = context->m_Assign.top();
+ assign.reset(context->m_Assign.top());
context->m_Assign.pop();
- Expression *filter;
+ std::unique_ptr<Expression> filter;
if (ignore) {
- Expression *rex = new LogicalNegateExpression(ignore, DebugInfoRange(@2, @5));
+ std::unique_ptr<Expression>rex{new LogicalNegateExpression(std::move(ignore), DebugInfoRange(@2, @5))};
- filter = new LogicalAndExpression(assign, rex, DebugInfoRange(@2, @5));
+ filter.reset(new LogicalAndExpression(std::move(assign), std::move(rex), DebugInfoRange(@2, @5)));
} else
- filter = assign;
+ filter.swap(assign);
String fkvar = context->m_FKVar.top();
context->m_FKVar.pop();
String fvvar = context->m_FVVar.top();
context->m_FVVar.pop();
- Expression *fterm = context->m_FTerm.top();
+ std::unique_ptr<Expression> fterm{context->m_FTerm.top()};
context->m_FTerm.pop();
- $$ = new ApplyExpression(type, target, $4, filter, context->GetPackage(), fkvar, fvvar, fterm, $7, $8, $10, DebugInfoRange(@2, @8));
+ $$ = new ApplyExpression(type, target, std::unique_ptr<Expression>($4), std::move(filter), context->GetPackage(), fkvar, fvvar, std::move(fterm), std::move(*$7), $8, std::unique_ptr<Expression>($10), DebugInfoRange(@2, @8));
+ delete $7;
}
;
return m_Package;
}
-void ConfigCompiler::CollectIncludes(std::vector<Expression *>& expressions,
+void ConfigCompiler::CollectIncludes(std::vector<std::unique_ptr<Expression> >& expressions,
const String& file, const String& zone, const String& package)
{
try {
- Expression *expr = CompileFile(file, zone, package);
- expressions.push_back(expr);
+ expressions.emplace_back(CompileFile(file, zone, package));
} catch (const std::exception& ex) {
Log(LogWarning, "ConfigCompiler")
<< "Cannot compile file '"
* @param search Whether to search global include dirs.
* @param debuginfo Debug information.
*/
-Expression *ConfigCompiler::HandleInclude(const String& relativeBase, const String& path,
+std::unique_ptr<Expression> ConfigCompiler::HandleInclude(const String& relativeBase, const String& path,
bool search, const String& zone, const String& package, const DebugInfo& debuginfo)
{
String upath;
}
}
- std::vector<Expression *> expressions;
+ std::vector<std::unique_ptr<Expression> > expressions;
if (!Utility::Glob(includePath, std::bind(&ConfigCompiler::CollectIncludes, std::ref(expressions), _1, zone, package), GlobFile) && includePath.FindFirstOf("*?") == String::NPos) {
std::ostringstream msgbuf;
BOOST_THROW_EXCEPTION(ScriptError(msgbuf.str(), debuginfo));
}
- DictExpression *expr = new DictExpression(expressions);
+ std::unique_ptr<DictExpression> expr{new DictExpression(std::move(expressions))};
expr->MakeInline();
- return expr;
+ return std::move(expr);
}
/**
* @param pattern The file pattern.
* @param debuginfo Debug information.
*/
-Expression *ConfigCompiler::HandleIncludeRecursive(const String& relativeBase, const String& path,
+std::unique_ptr<Expression> ConfigCompiler::HandleIncludeRecursive(const String& relativeBase, const String& path,
const String& pattern, const String& zone, const String& package, const DebugInfo&)
{
String ppath;
else
ppath = relativeBase + "/" + path;
- std::vector<Expression *> expressions;
+ std::vector<std::unique_ptr<Expression> > expressions;
Utility::GlobRecursive(ppath, pattern, std::bind(&ConfigCompiler::CollectIncludes, std::ref(expressions), _1, zone, package), GlobFile);
- DictExpression *dict = new DictExpression(expressions);
+ std::unique_ptr<DictExpression> dict{new DictExpression(std::move(expressions))};
dict->MakeInline();
- return dict;
+ return std::move(dict);
}
-void ConfigCompiler::HandleIncludeZone(const String& relativeBase, const String& tag, const String& path, const String& pattern, const String& package, std::vector<Expression *>& expressions)
+void ConfigCompiler::HandleIncludeZone(const String& relativeBase, const String& tag, const String& path, const String& pattern, const String& package, std::vector<std::unique_ptr<Expression> >& expressions)
{
String zoneName = Utility::BaseName(path);
* @param pattern The file pattern.
* @param debuginfo Debug information.
*/
-Expression *ConfigCompiler::HandleIncludeZones(const String& relativeBase, const String& tag,
+std::unique_ptr<Expression> ConfigCompiler::HandleIncludeZones(const String& relativeBase, const String& tag,
const String& path, const String& pattern, const String& package, const DebugInfo&)
{
String ppath;
newRelativeBase = ".";
}
- std::vector<Expression *> expressions;
+ std::vector<std::unique_ptr<Expression> > expressions;
Utility::Glob(ppath + "/*", std::bind(&ConfigCompiler::HandleIncludeZone, newRelativeBase, tag, _1, pattern, package, std::ref(expressions)), GlobDirectory);
- return new DictExpression(expressions);
+ return std::unique_ptr<Expression>(new DictExpression(std::move(expressions)));
}
/**
* @param stream The input stream.
* @returns Configuration items.
*/
-Expression *ConfigCompiler::CompileStream(const String& path,
+std::unique_ptr<Expression> ConfigCompiler::CompileStream(const String& path,
std::istream *stream, const String& zone, const String& package)
{
CONTEXT("Compiling configuration stream with name '" + path + "'");
try {
return ctx.Compile();
} catch (const ScriptError& ex) {
- return new ThrowExpression(MakeLiteral(ex.what()), ex.IsIncompleteExpression(), ex.GetDebugInfo());
+ return std::unique_ptr<Expression>(new ThrowExpression(MakeLiteral(ex.what()), ex.IsIncompleteExpression(), ex.GetDebugInfo()));
} catch (const std::exception& ex) {
- return new ThrowExpression(MakeLiteral(DiagnosticInformation(ex)), false);
+ return std::unique_ptr<Expression>(new ThrowExpression(MakeLiteral(DiagnosticInformation(ex)), false));
}
}
* @param path The path.
* @returns Configuration items.
*/
-Expression *ConfigCompiler::CompileFile(const String& path, const String& zone,
+std::unique_ptr<Expression> ConfigCompiler::CompileFile(const String& path, const String& zone,
const String& package)
{
CONTEXT("Compiling configuration file '" + path + "'");
* @param text The text.
* @returns Configuration items.
*/
-Expression *ConfigCompiler::CompileText(const String& path, const String& text,
+std::unique_ptr<Expression> ConfigCompiler::CompileText(const String& path, const String& text,
const String& zone, const String& package)
{
std::stringstream stream(text);
const String& zone = String(), const String& package = String());
virtual ~ConfigCompiler(void);
- Expression *Compile(void);
+ std::unique_ptr<Expression> Compile(void);
- static Expression *CompileStream(const String& path, std::istream *stream,
+ static std::unique_ptr<Expression>CompileStream(const String& path, std::istream *stream,
const String& zone = String(), const String& package = String());
- static Expression *CompileFile(const String& path, const String& zone = String(),
+ static std::unique_ptr<Expression>CompileFile(const String& path, const String& zone = String(),
const String& package = String());
- static Expression *CompileText(const String& path, const String& text,
+ static std::unique_ptr<Expression>CompileText(const String& path, const String& text,
const String& zone = String(), const String& package = String());
static void AddIncludeSearchDir(const String& dir);
void SetPackage(const String& package);
String GetPackage(void) const;
- static void CollectIncludes(std::vector<Expression *>& expressions,
+ static void CollectIncludes(std::vector<std::unique_ptr<Expression> >& expressions,
const String& file, const String& zone, const String& package);
- static Expression *HandleInclude(const String& relativeBase, const String& path, bool search,
+ static std::unique_ptr<Expression> HandleInclude(const String& relativeBase, const String& path, bool search,
const String& zone, const String& package, const DebugInfo& debuginfo = DebugInfo());
- static Expression *HandleIncludeRecursive(const String& relativeBase, const String& path,
+ static std::unique_ptr<Expression> HandleIncludeRecursive(const String& relativeBase, const String& path,
const String& pattern, const String& zone, const String& package, const DebugInfo& debuginfo = DebugInfo());
- static Expression *HandleIncludeZones(const String& relativeBase, const String& tag,
+ static std::unique_ptr<Expression> HandleIncludeZones(const String& relativeBase, const String& tag,
const String& path, const String& pattern, const String& package, const DebugInfo& debuginfo = DebugInfo());
size_t ReadInput(char *buffer, size_t max_bytes);
void InitializeScanner(void);
void DestroyScanner(void);
- static void HandleIncludeZone(const String& relativeBase, const String& tag, const String& path, const String& pattern, const String& package, std::vector<Expression *>& expressions);
+ static void HandleIncludeZone(const String& relativeBase, const String& tag, const String& path, const String& pattern, const String& package, std::vector<std::unique_ptr<Expression> >& expressions);
static bool IsAbsolutePath(const String& path);
#define REGISTER_CONFIG_FRAGMENT(name, fragment) \
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
- icinga::Expression *expression = icinga::ConfigCompiler::CompileText(name, fragment); \
+ std::unique_ptr<icinga::Expression> expression = icinga::ConfigCompiler::CompileText(name, fragment); \
VERIFY(expression); \
try { \
icinga::ScriptFrame frame; \
std::cerr << icinga::DiagnosticInformation(ex) << std::endl; \
icinga::Application::Exit(1); \
} \
- delete expression; \
}, 5)
#endif /* CONFIGFRAGMENT_H */
if (withModAttrs) {
/* restore modified attributes */
if (Utility::PathExists(Application::GetModAttrPath())) {
- Expression *expression = ConfigCompiler::CompileFile(Application::GetModAttrPath());
+ std::unique_ptr<Expression> expression = ConfigCompiler::CompileFile(Application::GetModAttrPath());
if (expression) {
try {
Log(LogCritical, "config", DiagnosticInformation(ex));
}
}
-
- delete expression;
}
}
void ConfigItemBuilder::AddExpression(Expression *expr)
{
- m_Expressions.push_back(expr);
+ m_Expressions.emplace_back(expr);
}
void ConfigItemBuilder::SetFilter(const std::shared_ptr<Expression>& filter)
BOOST_THROW_EXCEPTION(ScriptError(msgbuf.str(), m_DebugInfo));
}
- std::vector<Expression *> exprs;
+ std::vector<std::unique_ptr<Expression> > exprs;
Array::Ptr templateArray = new Array();
templateArray->Add(m_Name);
- exprs.push_back(new SetExpression(MakeIndexer(ScopeThis, "templates"), OpSetAdd,
- new LiteralExpression(templateArray), m_DebugInfo));
-
- DictExpression *dexpr = new DictExpression(m_Expressions, m_DebugInfo);
- dexpr->MakeInline();
- exprs.push_back(dexpr);
+ exprs.emplace_back(new SetExpression(MakeIndexer(ScopeThis, "templates"), OpSetAdd,
+ std::unique_ptr<LiteralExpression>(new LiteralExpression(templateArray)), m_DebugInfo));
#ifdef I2_DEBUG
if (!m_Abstract) {
bool foundDefaultImport = false;
- for (Expression *expr : m_Expressions) {
- if (dynamic_cast<ImportDefaultTemplatesExpression *>(expr)) {
+ for (const std::unique_ptr<Expression>& expr : m_Expressions) {
+ if (dynamic_cast<ImportDefaultTemplatesExpression *>(expr.get())) {
foundDefaultImport = true;
break;
}
}
#endif /* I2_DEBUG */
- std::shared_ptr<DictExpression> exprl = std::make_shared<DictExpression>(exprs, m_DebugInfo);
+ DictExpression *dexpr = new DictExpression(std::move(m_Expressions), m_DebugInfo);
+ dexpr->MakeInline();
+ exprs.emplace_back(dexpr);
+
+ std::shared_ptr<DictExpression> exprl = std::make_shared<DictExpression>(std::move(exprs), m_DebugInfo);
exprl->MakeInline();
return new ConfigItem(m_Type, m_Name, m_Abstract, exprl, m_Filter,
Type::Ptr m_Type; /**< The object type. */
String m_Name; /**< The name. */
bool m_Abstract; /**< Whether the item is abstract. */
- std::vector<Expression *> m_Expressions; /**< Expressions for this item. */
+ std::vector<std::unique_ptr<Expression> > m_Expressions; /**< Expressions for this item. */
std::shared_ptr<Expression> m_Filter; /**< Filter expression. */
DebugInfo m_DebugInfo; /**< Debug information. */
Dictionary::Ptr m_Scope; /**< variable scope. */
return debugInfo;
}
-Expression *icinga::MakeIndexer(ScopeSpecifier scopeSpec, const String& index)
+std::unique_ptr<Expression> icinga::MakeIndexer(ScopeSpecifier scopeSpec, const String& index)
{
- Expression *scope = new GetScopeExpression(scopeSpec);
- return new IndexerExpression(scope, MakeLiteral(index));
+ std::unique_ptr<Expression> scope{new GetScopeExpression(scopeSpec)};
+ return std::unique_ptr<Expression>(new IndexerExpression(std::move(scope), MakeLiteral(index)));
}
void DictExpression::MakeInline(void)
if (vfunc.IsObjectType<Type>()) {
std::vector<Value> arguments;
arguments.reserve(m_Args.size());
- for (Expression *arg : m_Args) {
+ for (const auto& arg : m_Args) {
ExpressionResult argres = arg->Evaluate(frame);
CHECK_RESULT(argres);
std::vector<Value> arguments;
arguments.reserve(m_Args.size());
- for (Expression *arg : m_Args) {
+ for (const auto& arg : m_Args) {
ExpressionResult argres = arg->Evaluate(frame);
CHECK_RESULT(argres);
Array::Ptr result = new Array();
result->Reserve(m_Expressions.size());
- for (Expression *aexpr : m_Expressions) {
+ for (const auto& aexpr : m_Expressions) {
ExpressionResult element = aexpr->Evaluate(frame);
CHECK_RESULT(element);
Value result;
try {
- for (Expression *aexpr : m_Expressions) {
+ for (const auto& aexpr : m_Expressions) {
ExpressionResult element = aexpr->Evaluate(frame, m_Inline ? dhint : nullptr);
CHECK_RESULT(element);
result = element.GetValue();
return true;
}
-void icinga::BindToScope(Expression *& expr, ScopeSpecifier scopeSpec)
+void icinga::BindToScope(std::unique_ptr<Expression>& expr, ScopeSpecifier scopeSpec)
{
- DictExpression *dexpr = dynamic_cast<DictExpression *>(expr);
+ DictExpression *dexpr = dynamic_cast<DictExpression *>(expr.get());
if (dexpr) {
- for (Expression *& expr : dexpr->m_Expressions)
+ for (auto& expr : dexpr->m_Expressions)
BindToScope(expr, scopeSpec);
return;
}
- SetExpression *aexpr = dynamic_cast<SetExpression *>(expr);
+ SetExpression *aexpr = dynamic_cast<SetExpression *>(expr.get());
if (aexpr) {
BindToScope(aexpr->m_Operand1, scopeSpec);
return;
}
- IndexerExpression *iexpr = dynamic_cast<IndexerExpression *>(expr);
+ IndexerExpression *iexpr = dynamic_cast<IndexerExpression *>(expr.get());
if (iexpr) {
BindToScope(iexpr->m_Operand1, scopeSpec);
return;
}
- LiteralExpression *lexpr = dynamic_cast<LiteralExpression *>(expr);
+ LiteralExpression *lexpr = dynamic_cast<LiteralExpression *>(expr.get());
if (lexpr && lexpr->GetValue().IsString()) {
- Expression *scope = new GetScopeExpression(scopeSpec);
- expr = new IndexerExpression(scope, lexpr, lexpr->GetDebugInfo());
+ std::unique_ptr<Expression> scope{new GetScopeExpression(scopeSpec)};
+ expr.reset(new IndexerExpression(std::move(scope), std::move(expr), lexpr->GetDebugInfo()));
}
- VariableExpression *vexpr = dynamic_cast<VariableExpression *>(expr);
+ VariableExpression *vexpr = dynamic_cast<VariableExpression *>(expr.get());
if (vexpr) {
- Expression *scope = new GetScopeExpression(scopeSpec);
- Expression *new_expr = new IndexerExpression(scope, MakeLiteral(vexpr->GetVariable()), vexpr->GetDebugInfo());
- delete expr;
- expr = new_expr;
+ std::unique_ptr<Expression> scope{new GetScopeExpression(scopeSpec)};
+ expr.reset(new IndexerExpression(std::move(scope), MakeLiteral(vexpr->GetVariable()), vexpr->GetDebugInfo()));
}
}
if (frame.Sandboxed)
BOOST_THROW_EXCEPTION(ScriptError("Includes are not allowed in sandbox mode.", m_DebugInfo));
- Expression *expr;
+ std::unique_ptr<Expression> expr;
String name, path, pattern;
switch (m_Type) {
try {
res = expr->Evaluate(frame, dhint);
} catch (const std::exception&) {
- delete expr;
throw;
}
- delete expr;
-
return res;
}
static void ScriptBreakpoint(ScriptFrame& frame, ScriptError *ex, const DebugInfo& di);
};
-I2_CONFIG_API Expression *MakeIndexer(ScopeSpecifier scopeSpec, const String& index);
+I2_CONFIG_API std::unique_ptr<Expression> MakeIndexer(ScopeSpecifier scopeSpec, const String& index);
class I2_CONFIG_API OwnedExpression : public Expression
{
Value m_Value;
};
-inline LiteralExpression *MakeLiteral(const Value& literal = Value())
+inline LiteralExpression *MakeLiteralRaw(const Value& literal = Value())
{
return new LiteralExpression(literal);
}
+inline std::unique_ptr<LiteralExpression> MakeLiteral(const Value& literal = Value())
+{
+ return std::unique_ptr<LiteralExpression>(MakeLiteralRaw(literal));
+}
+
class I2_CONFIG_API DebuggableExpression : public Expression
{
public:
class I2_CONFIG_API UnaryExpression : public DebuggableExpression
{
public:
- UnaryExpression(Expression *operand, const DebugInfo& debugInfo = DebugInfo())
- : DebuggableExpression(debugInfo), m_Operand(operand)
+ UnaryExpression(std::unique_ptr<Expression> operand, const DebugInfo& debugInfo = DebugInfo())
+ : DebuggableExpression(debugInfo), m_Operand(std::move(operand))
{ }
- ~UnaryExpression(void)
- {
- delete m_Operand;
- }
-
protected:
- Expression *m_Operand;
+ std::unique_ptr<Expression> m_Operand;
};
class I2_CONFIG_API BinaryExpression : public DebuggableExpression
{
public:
- BinaryExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : DebuggableExpression(debugInfo), m_Operand1(operand1), m_Operand2(operand2)
+ BinaryExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : DebuggableExpression(debugInfo), m_Operand1(std::move(operand1)), m_Operand2(std::move(operand2))
{ }
- ~BinaryExpression(void)
- {
- delete m_Operand1;
- delete m_Operand2;
- }
-
protected:
- Expression *m_Operand1;
- Expression *m_Operand2;
+ std::unique_ptr<Expression> m_Operand1;
+ std::unique_ptr<Expression> m_Operand2;
};
class I2_CONFIG_API VariableExpression : public DebuggableExpression
private:
String m_Variable;
- friend I2_CONFIG_API void BindToScope(Expression *& expr, ScopeSpecifier scopeSpec);
+ friend I2_CONFIG_API void BindToScope(std::unique_ptr<Expression>& expr, ScopeSpecifier scopeSpec);
};
class I2_CONFIG_API NegateExpression : public UnaryExpression
{
public:
- NegateExpression(Expression *operand, const DebugInfo& debugInfo = DebugInfo())
- : UnaryExpression(operand, debugInfo)
+ NegateExpression(std::unique_ptr<Expression> operand, const DebugInfo& debugInfo = DebugInfo())
+ : UnaryExpression(std::move(operand), debugInfo)
{ }
protected:
class I2_CONFIG_API LogicalNegateExpression : public UnaryExpression
{
public:
- LogicalNegateExpression(Expression *operand, const DebugInfo& debugInfo = DebugInfo())
- : UnaryExpression(operand, debugInfo)
+ LogicalNegateExpression(std::unique_ptr<Expression> operand, const DebugInfo& debugInfo = DebugInfo())
+ : UnaryExpression(std::move(operand), debugInfo)
{ }
protected:
class I2_CONFIG_API AddExpression : public BinaryExpression
{
public:
- AddExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo)
+ AddExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
class I2_CONFIG_API SubtractExpression : public BinaryExpression
{
public:
- SubtractExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo)
+ SubtractExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
class I2_CONFIG_API MultiplyExpression : public BinaryExpression
{
public:
- MultiplyExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo)
+ MultiplyExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
class I2_CONFIG_API DivideExpression : public BinaryExpression
{
public:
- DivideExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo)
+ DivideExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
class I2_CONFIG_API ModuloExpression : public BinaryExpression
{
public:
- ModuloExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo)
+ ModuloExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
class I2_CONFIG_API XorExpression : public BinaryExpression
{
public:
- XorExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo)
+ XorExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
class I2_CONFIG_API BinaryAndExpression : public BinaryExpression
{
public:
- BinaryAndExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo)
+ BinaryAndExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
class I2_CONFIG_API BinaryOrExpression : public BinaryExpression
{
public:
- BinaryOrExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo)
+ BinaryOrExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
class I2_CONFIG_API ShiftLeftExpression : public BinaryExpression
{
public:
- ShiftLeftExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo)
+ ShiftLeftExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
class I2_CONFIG_API ShiftRightExpression : public BinaryExpression
{
public:
- ShiftRightExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo)
+ ShiftRightExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
class I2_CONFIG_API EqualExpression : public BinaryExpression
{
public:
- EqualExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo)
+ EqualExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
class I2_CONFIG_API NotEqualExpression : public BinaryExpression
{
public:
- NotEqualExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo)
+ NotEqualExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
class I2_CONFIG_API LessThanExpression : public BinaryExpression
{
public:
- LessThanExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo)
+ LessThanExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
class I2_CONFIG_API GreaterThanExpression : public BinaryExpression
{
public:
- GreaterThanExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo)
+ GreaterThanExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
class I2_CONFIG_API LessThanOrEqualExpression : public BinaryExpression
{
public:
- LessThanOrEqualExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo)
+ LessThanOrEqualExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
class I2_CONFIG_API GreaterThanOrEqualExpression : public BinaryExpression
{
public:
- GreaterThanOrEqualExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo)
+ GreaterThanOrEqualExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
class I2_CONFIG_API InExpression : public BinaryExpression
{
public:
- InExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo)
+ InExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
class I2_CONFIG_API NotInExpression : public BinaryExpression
{
public:
- NotInExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo)
+ NotInExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
class I2_CONFIG_API LogicalAndExpression : public BinaryExpression
{
public:
- LogicalAndExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo)
+ LogicalAndExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
class I2_CONFIG_API LogicalOrExpression : public BinaryExpression
{
public:
- LogicalOrExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo)
+ LogicalOrExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
class I2_CONFIG_API FunctionCallExpression : public DebuggableExpression
{
public:
- FunctionCallExpression(Expression *fname, const std::vector<Expression *>& args, const DebugInfo& debugInfo = DebugInfo())
- : DebuggableExpression(debugInfo), m_FName(fname), m_Args(args)
+ FunctionCallExpression(std::unique_ptr<Expression> fname, std::vector<std::unique_ptr<Expression> >&& args, const DebugInfo& debugInfo = DebugInfo())
+ : DebuggableExpression(debugInfo), m_FName(std::move(fname)), m_Args(std::move(args))
{ }
- ~FunctionCallExpression(void)
- {
- delete m_FName;
-
- for (Expression *expr : m_Args)
- delete expr;
- }
-
protected:
virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
public:
- Expression *m_FName;
- std::vector<Expression *> m_Args;
+ std::unique_ptr<Expression> m_FName;
+ std::vector<std::unique_ptr<Expression> > m_Args;
};
class I2_CONFIG_API ArrayExpression : public DebuggableExpression
{
public:
- ArrayExpression(const std::vector<Expression *>& expressions, const DebugInfo& debugInfo = DebugInfo())
- : DebuggableExpression(debugInfo), m_Expressions(expressions)
+ ArrayExpression(std::vector<std::unique_ptr<Expression > >&& expressions, const DebugInfo& debugInfo = DebugInfo())
+ : DebuggableExpression(debugInfo), m_Expressions(std::move(expressions))
{ }
- ~ArrayExpression(void)
- {
- for (Expression *expr : m_Expressions)
- delete expr;
- }
-
protected:
virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
- std::vector<Expression *> m_Expressions;
+ std::vector<std::unique_ptr<Expression> > m_Expressions;
};
class I2_CONFIG_API DictExpression : public DebuggableExpression
{
public:
- DictExpression(const std::vector<Expression *>& expressions = std::vector<Expression *>(), const DebugInfo& debugInfo = DebugInfo())
- : DebuggableExpression(debugInfo), m_Expressions(expressions), m_Inline(false)
+ DictExpression(std::vector<std::unique_ptr<Expression> >&& expressions = {}, const DebugInfo& debugInfo = DebugInfo())
+ : DebuggableExpression(debugInfo), m_Expressions(std::move(expressions)), m_Inline(false)
{ }
- ~DictExpression(void)
- {
- for (Expression *expr : m_Expressions)
- delete expr;
- }
-
void MakeInline(void);
protected:
virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
- std::vector<Expression *> m_Expressions;
+ std::vector<std::unique_ptr<Expression> > m_Expressions;
bool m_Inline;
- friend I2_CONFIG_API void BindToScope(Expression *& expr, ScopeSpecifier scopeSpec);
+ friend I2_CONFIG_API void BindToScope(std::unique_ptr<Expression>& expr, ScopeSpecifier scopeSpec);
};
class I2_CONFIG_API SetExpression : public BinaryExpression
{
public:
- SetExpression(Expression *operand1, CombinedSetOp op, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo), m_Op(op)
+ SetExpression(std::unique_ptr<Expression> operand1, CombinedSetOp op, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo), m_Op(op)
{ }
protected:
private:
CombinedSetOp m_Op;
- friend I2_CONFIG_API void BindToScope(Expression *& expr, ScopeSpecifier scopeSpec);
+ friend I2_CONFIG_API void BindToScope(std::unique_ptr<Expression>& expr, ScopeSpecifier scopeSpec);
};
class I2_CONFIG_API ConditionalExpression : public DebuggableExpression
{
public:
- ConditionalExpression(Expression *condition, Expression *true_branch, Expression *false_branch, const DebugInfo& debugInfo = DebugInfo())
- : DebuggableExpression(debugInfo), m_Condition(condition), m_TrueBranch(true_branch), m_FalseBranch(false_branch)
+ ConditionalExpression(std::unique_ptr<Expression> condition, std::unique_ptr<Expression> true_branch, std::unique_ptr<Expression> false_branch, const DebugInfo& debugInfo = DebugInfo())
+ : DebuggableExpression(debugInfo), m_Condition(std::move(condition)), m_TrueBranch(std::move(true_branch)), m_FalseBranch(std::move(false_branch))
{ }
- ~ConditionalExpression(void)
- {
- delete m_Condition;
- delete m_TrueBranch;
- delete m_FalseBranch;
- }
-
protected:
virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
- Expression *m_Condition;
- Expression *m_TrueBranch;
- Expression *m_FalseBranch;
+ std::unique_ptr<Expression> m_Condition;
+ std::unique_ptr<Expression> m_TrueBranch;
+ std::unique_ptr<Expression> m_FalseBranch;
};
class I2_CONFIG_API WhileExpression : public DebuggableExpression
{
public:
- WhileExpression(Expression *condition, Expression *loop_body, const DebugInfo& debugInfo = DebugInfo())
- : DebuggableExpression(debugInfo), m_Condition(condition), m_LoopBody(loop_body)
+ WhileExpression(std::unique_ptr<Expression> condition, std::unique_ptr<Expression> loop_body, const DebugInfo& debugInfo = DebugInfo())
+ : DebuggableExpression(debugInfo), m_Condition(std::move(condition)), m_LoopBody(std::move(loop_body))
{ }
- ~WhileExpression(void)
- {
- delete m_Condition;
- delete m_LoopBody;
- }
-
protected:
virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
- Expression *m_Condition;
- Expression *m_LoopBody;
+ std::unique_ptr<Expression> m_Condition;
+ std::unique_ptr<Expression> m_LoopBody;
};
class I2_CONFIG_API ReturnExpression : public UnaryExpression
{
public:
- ReturnExpression(Expression *expression, const DebugInfo& debugInfo = DebugInfo())
- : UnaryExpression(expression, debugInfo)
+ ReturnExpression(std::unique_ptr<Expression> expression, const DebugInfo& debugInfo = DebugInfo())
+ : UnaryExpression(std::move(expression), debugInfo)
{ }
protected:
class I2_CONFIG_API IndexerExpression : public BinaryExpression
{
public:
- IndexerExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
- : BinaryExpression(operand1, operand2, debugInfo)
+ IndexerExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
virtual bool GetReference(ScriptFrame& frame, bool init_dict, Value *parent, String *index, DebugHint **dhint) const override;
- friend I2_CONFIG_API void BindToScope(Expression *& expr, ScopeSpecifier scopeSpec);
+ friend I2_CONFIG_API void BindToScope(std::unique_ptr<Expression>& expr, ScopeSpecifier scopeSpec);
};
-I2_CONFIG_API void BindToScope(Expression *& expr, ScopeSpecifier scopeSpec);
+I2_CONFIG_API void BindToScope(std::unique_ptr<Expression>& expr, ScopeSpecifier scopeSpec);
class I2_CONFIG_API ThrowExpression : public DebuggableExpression
{
public:
- ThrowExpression(Expression *message, bool incompleteExpr, const DebugInfo& debugInfo = DebugInfo())
- : DebuggableExpression(debugInfo), m_Message(message), m_IncompleteExpr(incompleteExpr)
+ ThrowExpression(std::unique_ptr<Expression> message, bool incompleteExpr, const DebugInfo& debugInfo = DebugInfo())
+ : DebuggableExpression(debugInfo), m_Message(std::move(message)), m_IncompleteExpr(incompleteExpr)
{ }
- ~ThrowExpression(void)
- {
- delete m_Message;
- }
-
protected:
virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
- Expression *m_Message;
+ std::unique_ptr<Expression> m_Message;
bool m_IncompleteExpr;
};
class I2_CONFIG_API ImportExpression : public DebuggableExpression
{
public:
- ImportExpression(Expression *name, const DebugInfo& debugInfo = DebugInfo())
- : DebuggableExpression(debugInfo), m_Name(name)
+ ImportExpression(std::unique_ptr<Expression> name, const DebugInfo& debugInfo = DebugInfo())
+ : DebuggableExpression(debugInfo), m_Name(std::move(name))
{ }
- ~ImportExpression(void)
- {
- delete m_Name;
- }
-
protected:
virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
- Expression *m_Name;
+ std::unique_ptr<Expression> m_Name;
};
class I2_CONFIG_API ImportDefaultTemplatesExpression : public DebuggableExpression
{
public:
FunctionExpression(const String& name, const std::vector<String>& args,
- std::map<String, Expression *> *closedVars, Expression *expression, const DebugInfo& debugInfo = DebugInfo())
- : DebuggableExpression(debugInfo), m_Name(name), m_Args(args), m_ClosedVars(closedVars), m_Expression(expression)
+ std::map<String, std::unique_ptr<Expression> >&& closedVars, std::unique_ptr<Expression> expression, const DebugInfo& debugInfo = DebugInfo())
+ : DebuggableExpression(debugInfo), m_Name(name), m_Args(args), m_ClosedVars(std::move(closedVars)), m_Expression(std::move(expression))
{ }
- ~FunctionExpression(void)
- {
- if (m_ClosedVars) {
- typedef std::pair<String, Expression *> kv_pair;
- for (const kv_pair& kv : *m_ClosedVars) {
- delete kv.second;
- }
- }
-
- delete m_ClosedVars;
- }
-
protected:
virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
String m_Name;
std::vector<String> m_Args;
- std::map<String, Expression *> *m_ClosedVars;
+ std::map<String, std::unique_ptr<Expression> > m_ClosedVars;
std::shared_ptr<Expression> m_Expression;
};
class I2_CONFIG_API ApplyExpression : public DebuggableExpression
{
public:
- ApplyExpression(const String& type, const String& target, Expression *name,
- Expression *filter, const String& package, const String& fkvar, const String& fvvar,
- Expression *fterm, std::map<String, Expression *> *closedVars, bool ignoreOnError,
- Expression *expression, const DebugInfo& debugInfo = DebugInfo())
+ ApplyExpression(const String& type, const String& target, std::unique_ptr<Expression> name,
+ std::unique_ptr<Expression> filter, const String& package, const String& fkvar, const String& fvvar,
+ std::unique_ptr<Expression> fterm, std::map<String, std::unique_ptr<Expression> >&& closedVars, bool ignoreOnError,
+ std::unique_ptr<Expression> expression, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_Type(type), m_Target(target),
- m_Name(name), m_Filter(filter), m_Package(package), m_FKVar(fkvar), m_FVVar(fvvar),
- m_FTerm(fterm), m_IgnoreOnError(ignoreOnError), m_ClosedVars(closedVars),
- m_Expression(expression)
+ m_Name(std::move(name)), m_Filter(std::move(filter)), m_Package(package), m_FKVar(fkvar), m_FVVar(fvvar),
+ m_FTerm(std::move(fterm)), m_IgnoreOnError(ignoreOnError), m_ClosedVars(std::move(closedVars)),
+ m_Expression(std::move(expression))
{ }
- ~ApplyExpression(void)
- {
- delete m_Name;
-
- if (m_ClosedVars) {
- typedef std::pair<String, Expression *> kv_pair;
- for (const kv_pair& kv : *m_ClosedVars) {
- delete kv.second;
- }
- }
-
- delete m_ClosedVars;
- }
-
protected:
virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
String m_Type;
String m_Target;
- Expression *m_Name;
+ std::unique_ptr<Expression> m_Name;
std::shared_ptr<Expression> m_Filter;
String m_Package;
String m_FKVar;
String m_FVVar;
std::shared_ptr<Expression> m_FTerm;
bool m_IgnoreOnError;
- std::map<String, Expression *> *m_ClosedVars;
+ std::map<String, std::unique_ptr<Expression> > m_ClosedVars;
std::shared_ptr<Expression> m_Expression;
};
class I2_CONFIG_API ObjectExpression : public DebuggableExpression
{
public:
- ObjectExpression(bool abstract, Expression *type, Expression *name, Expression *filter,
- const String& zone, const String& package, std::map<String, Expression *> *closedVars,
- bool defaultTmpl, bool ignoreOnError, Expression *expression, const DebugInfo& debugInfo = DebugInfo())
- : DebuggableExpression(debugInfo), m_Abstract(abstract), m_Type(type),
- m_Name(name), m_Filter(filter), m_Zone(zone), m_Package(package), m_DefaultTmpl(defaultTmpl),
- m_IgnoreOnError(ignoreOnError), m_ClosedVars(closedVars), m_Expression(expression)
+ ObjectExpression(bool abstract, std::unique_ptr<Expression> type, std::unique_ptr<Expression> name, std::unique_ptr<Expression> filter,
+ const String& zone, const String& package, std::map<String, std::unique_ptr<Expression> >&& closedVars,
+ bool defaultTmpl, bool ignoreOnError, std::unique_ptr<Expression> expression, const DebugInfo& debugInfo = DebugInfo())
+ : DebuggableExpression(debugInfo), m_Abstract(abstract), m_Type(std::move(type)),
+ m_Name(std::move(name)), m_Filter(std::move(filter)), m_Zone(zone), m_Package(package), m_DefaultTmpl(defaultTmpl),
+ m_IgnoreOnError(ignoreOnError), m_ClosedVars(std::move(closedVars)), m_Expression(std::move(expression))
{ }
- ~ObjectExpression(void)
- {
- delete m_Name;
-
- if (m_ClosedVars) {
- typedef std::pair<String, Expression *> kv_pair;
- for (const kv_pair& kv : *m_ClosedVars) {
- delete kv.second;
- }
- }
-
- delete m_ClosedVars;
- }
-
protected:
virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
bool m_Abstract;
- Expression *m_Type;
- Expression *m_Name;
+ std::unique_ptr<Expression> m_Type;
+ std::unique_ptr<Expression> m_Name;
std::shared_ptr<Expression> m_Filter;
String m_Zone;
String m_Package;
bool m_DefaultTmpl;
bool m_IgnoreOnError;
- std::map<String, Expression *> *m_ClosedVars;
+ std::map<String, std::unique_ptr<Expression> > m_ClosedVars;
std::shared_ptr<Expression> m_Expression;
};
class I2_CONFIG_API ForExpression : public DebuggableExpression
{
public:
- ForExpression(const String& fkvar, const String& fvvar, Expression *value, Expression *expression, const DebugInfo& debugInfo = DebugInfo())
- : DebuggableExpression(debugInfo), m_FKVar(fkvar), m_FVVar(fvvar), m_Value(value), m_Expression(expression)
+ ForExpression(const String& fkvar, const String& fvvar, std::unique_ptr<Expression> value, std::unique_ptr<Expression> expression, const DebugInfo& debugInfo = DebugInfo())
+ : DebuggableExpression(debugInfo), m_FKVar(fkvar), m_FVVar(fvvar), m_Value(std::move(value)), m_Expression(std::move(expression))
{ }
- ~ForExpression(void)
- {
- delete m_Value;
- delete m_Expression;
- }
-
protected:
virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
String m_FKVar;
String m_FVVar;
- Expression *m_Value;
- Expression *m_Expression;
+ std::unique_ptr<Expression> m_Value;
+ std::unique_ptr<Expression> m_Expression;
};
class I2_CONFIG_API LibraryExpression : public UnaryExpression
{
public:
- LibraryExpression(Expression *expression, const DebugInfo& debugInfo = DebugInfo())
- : UnaryExpression(expression, debugInfo)
+ LibraryExpression(std::unique_ptr<Expression> expression, const DebugInfo& debugInfo = DebugInfo())
+ : UnaryExpression(std::move(expression), debugInfo)
{ }
protected:
class I2_CONFIG_API IncludeExpression : public DebuggableExpression
{
public:
- IncludeExpression(const String& relativeBase, Expression *path, Expression *pattern, Expression *name,
+ IncludeExpression(const String& relativeBase, std::unique_ptr<Expression> path, std::unique_ptr<Expression> pattern, std::unique_ptr<Expression> name,
IncludeType type, bool searchIncludes, const String& zone, const String& package, const DebugInfo& debugInfo = DebugInfo())
- : DebuggableExpression(debugInfo), m_RelativeBase(relativeBase), m_Path(path), m_Pattern(pattern),
- m_Name(name), m_Type(type), m_SearchIncludes(searchIncludes), m_Zone(zone), m_Package(package)
+ : DebuggableExpression(debugInfo), m_RelativeBase(relativeBase), m_Path(std::move(path)), m_Pattern(std::move(pattern)),
+ m_Name(std::move(name)), m_Type(type), m_SearchIncludes(searchIncludes), m_Zone(zone), m_Package(package)
{ }
- ~IncludeExpression(void)
- {
- delete m_Path;
- delete m_Pattern;
- delete m_Name;
- }
-
protected:
virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
String m_RelativeBase;
- Expression *m_Path;
- Expression *m_Pattern;
- Expression *m_Name;
+ std::unique_ptr<Expression> m_Path;
+ std::unique_ptr<Expression> m_Pattern;
+ std::unique_ptr<Expression> m_Name;
IncludeType m_Type;
bool m_SearchIncludes;
String m_Zone;
class I2_CONFIG_API UsingExpression : public DebuggableExpression
{
public:
- UsingExpression(Expression *name, const DebugInfo& debugInfo = DebugInfo())
- : DebuggableExpression(debugInfo), m_Name(name)
+ UsingExpression(std::unique_ptr<Expression> name, const DebugInfo& debugInfo = DebugInfo())
+ : DebuggableExpression(debugInfo), m_Name(std::move(name))
{ }
- ~UsingExpression(void)
- {
- delete m_Name;
- }
-
protected:
virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
- Expression *m_Name;
+ std::unique_ptr<Expression> m_Name;
};
class I2_CONFIG_API TryExceptExpression : public DebuggableExpression
{
public:
- TryExceptExpression(Expression *tryBody, Expression *exceptBody, const DebugInfo& debugInfo = DebugInfo())
- : DebuggableExpression(debugInfo), m_TryBody(tryBody), m_ExceptBody(exceptBody)
+ TryExceptExpression(std::unique_ptr<Expression> tryBody, std::unique_ptr<Expression> exceptBody, const DebugInfo& debugInfo = DebugInfo())
+ : DebuggableExpression(debugInfo), m_TryBody(std::move(tryBody)), m_ExceptBody(std::move(exceptBody))
{ }
- ~TryExceptExpression(void)
- {
- delete m_TryBody;
- delete m_ExceptBody;
- }
-
protected:
virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
- Expression *m_TryBody;
- Expression *m_ExceptBody;
+ std::unique_ptr<Expression> m_TryBody;
+ std::unique_ptr<Expression> m_ExceptBody;
};
}
}
static inline Value NewFunction(ScriptFrame& frame, const String& name, const std::vector<String>& argNames,
- std::map<String, Expression *> *closedVars, const std::shared_ptr<Expression>& expression)
+ const std::map<String, std::unique_ptr<Expression> >& closedVars, const std::shared_ptr<Expression>& expression)
{
auto evaluatedClosedVars = EvaluateClosedVars(frame, closedVars);
}
static inline Value NewApply(ScriptFrame& frame, const String& type, const String& target, const String& name, const std::shared_ptr<Expression>& filter,
- const String& package, const String& fkvar, const String& fvvar, const std::shared_ptr<Expression>& fterm, std::map<String, Expression *> *closedVars,
+ const String& package, const String& fkvar, const String& fvvar, const std::shared_ptr<Expression>& fterm, const std::map<String, std::unique_ptr<Expression> >& closedVars,
bool ignoreOnError, const std::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
{
ApplyRule::AddRule(type, target, name, expression, filter, package, fkvar,
}
static inline Value NewObject(ScriptFrame& frame, bool abstract, const Type::Ptr& type, const String& name, const std::shared_ptr<Expression>& filter,
- const String& zone, const String& package, bool defaultTmpl, bool ignoreOnError, std::map<String, Expression *> *closedVars, const std::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
+ const String& zone, const String& package, bool defaultTmpl, bool ignoreOnError, const std::map<String, std::unique_ptr<Expression> >& closedVars, const std::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
{
ConfigItemBuilder::Ptr item = new ConfigItemBuilder(debugInfo);
return Empty;
}
- static inline ExpressionResult For(ScriptFrame& frame, const String& fkvar, const String& fvvar, const Value& value, Expression *expression, const DebugInfo& debugInfo = DebugInfo())
+ static inline ExpressionResult For(ScriptFrame& frame, const String& fkvar, const String& fvvar, const Value& value, const std::unique_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
{
if (value.IsObjectType<Array>()) {
if (!fvvar.IsEmpty())
}
private:
- static inline Dictionary::Ptr EvaluateClosedVars(ScriptFrame& frame, std::map<String, Expression *> *closedVars)
+ static inline Dictionary::Ptr EvaluateClosedVars(ScriptFrame& frame, const std::map<String, std::unique_ptr<Expression> >& closedVars)
{
Dictionary::Ptr locals;
- if (closedVars) {
+ if (!closedVars.empty()) {
locals = new Dictionary();
- typedef std::pair<String, Expression *> ClosedVar;
- for (const ClosedVar& cvar : *closedVars) {
+ for (const auto& cvar : closedVars) {
locals->Set(cvar.first, cvar.second->Evaluate(frame));
}
}
fp << config;
fp.close();
- Expression *expr = ConfigCompiler::CompileFile(path, String(), "_api");
+ std::unique_ptr<Expression> expr = ConfigCompiler::CompileFile(path, String(), "_api");
try {
ActivationScope ascope;
ScriptFrame frame;
expr->Evaluate(frame);
- delete expr;
- expr = nullptr;
+ expr.reset();
WorkQueue upq;
std::vector<ConfigItem::Ptr> newItems;
ApiListener::UpdateObjectAuthority();
} catch (const std::exception& ex) {
- delete expr;
-
if (unlink(path.CStr()) < 0 && errno != ENOENT) {
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("unlink")
Array::Ptr results = new Array();
Dictionary::Ptr resultInfo = new Dictionary();
- Expression *expr = nullptr;
+ std::unique_ptr<Expression> expr;
Value exprResult;
try {
debugInfo->Set("last_line", di.LastLine);
debugInfo->Set("last_column", di.LastColumn);
resultInfo->Set("debug_info", debugInfo);
- } catch (...) {
- delete expr;
- throw;
}
- delete expr;
results->Add(resultInfo);
Value value;
try {
- Expression *expr = ConfigCompiler::CompileText("temp", pword);
+ std::unique_ptr<Expression> expr = ConfigCompiler::CompileText("temp", pword);
if (expr)
value = expr->Evaluate(frame);
AddSuggestions(matches, word, pword, true, value);
-
} catch (...) { /* Ignore the exception */ }
}
using namespace icinga;
EventQueue::EventQueue(const String& name)
- : m_Name(name), m_Filter(nullptr)
+ : m_Name(name)
{ }
-EventQueue::~EventQueue(void)
-{
- delete m_Filter;
-}
-
bool EventQueue::CanProcessEvent(const String& type) const
{
boost::mutex::scoped_lock lock(m_Mutex);
frame.Sandboxed = true;
try {
- if (!FilterUtility::EvaluateFilter(frame, m_Filter, event, "event"))
+ if (!FilterUtility::EvaluateFilter(frame, &*m_Filter, event, "event"))
return;
} catch (const std::exception& ex) {
Log(LogWarning, "EventQueue")
m_Types = types;
}
-void EventQueue::SetFilter(Expression *filter)
+void EventQueue::SetFilter(std::unique_ptr<Expression> filter)
{
boost::mutex::scoped_lock lock(m_Mutex);
- delete m_Filter;
- m_Filter = filter;
+ m_Filter.swap(filter);
}
Dictionary::Ptr EventQueue::WaitForEvent(void *client, double timeout)
DECLARE_PTR_TYPEDEFS(EventQueue);
EventQueue(const String& name);
- ~EventQueue(void);
bool CanProcessEvent(const String& type) const;
void ProcessEvent(const Dictionary::Ptr& event);
void RemoveClient(void *client);
void SetTypes(const std::set<String>& types);
- void SetFilter(Expression *filter);
+ void SetFilter(std::unique_ptr<Expression> filter);
Dictionary::Ptr WaitForEvent(void *client, double timeout = 5);
boost::condition_variable m_CV;
std::set<String> m_Types;
- Expression *m_Filter;
+ std::unique_ptr<Expression> m_Filter;
std::map<void *, std::deque<Dictionary::Ptr> > m_Events;
};
String filter = HttpUtility::GetLastParameter(params, "filter");
- Expression *ufilter = nullptr;
+ std::unique_ptr<Expression> ufilter;
if (!filter.IsEmpty())
ufilter = ConfigCompiler::CompileText("<API query>", filter);
}
queue->SetTypes(types->ToSet<String>());
- queue->SetFilter(ufilter);
+ queue->SetFilter(std::move(ufilter));
queue->AddClient(&request);
foundPermission = true;
if (filter && permissionFilter) {
- std::vector<Expression *> args;
- args.push_back(new GetScopeExpression(ScopeLocal));
- FunctionCallExpression *fexpr = new FunctionCallExpression(new IndexerExpression(MakeLiteral(filter), MakeLiteral("call")), args);
+ std::vector<std::unique_ptr<Expression> > args;
+ args.emplace_back(new GetScopeExpression(ScopeLocal));
+ std::unique_ptr<Expression> indexer{new IndexerExpression(std::unique_ptr<Expression>(MakeLiteral(filter)), std::unique_ptr<Expression>(MakeLiteral("call")))};
+ FunctionCallExpression *fexpr = new FunctionCallExpression(std::move(indexer), std::move(args));
if (!*permissionFilter)
*permissionFilter = fexpr;
else
- *permissionFilter = new LogicalOrExpression(*permissionFilter, fexpr);
+ *permissionFilter = new LogicalOrExpression(std::unique_ptr<Expression>(*permissionFilter), std::unique_ptr<Expression>(fexpr));
}
}
}
frame.Sandboxed = true;
Dictionary::Ptr uvars = new Dictionary();
- Expression *ufilter = nullptr;
+ std::unique_ptr<Expression> ufilter;
if (query->Contains("filter")) {
String filter = HttpUtility::GetLastParameter(query, "filter");
frame.Self = uvars;
- try {
- provider->FindTargets(type, std::bind(&FilteredAddTarget,
- std::ref(permissionFrame), permissionFilter,
- std::ref(frame), ufilter, std::ref(result), variableName, _1));
- } catch (const std::exception&) {
- delete ufilter;
- throw;
- }
-
- delete ufilter;
+ provider->FindTargets(type, std::bind(&FilteredAddTarget,
+ std::ref(permissionFrame), permissionFilter,
+ std::ref(frame), &*ufilter, std::ref(result), variableName, _1));
}
return result;
BOOST_AUTO_TEST_CASE(simple)
{
ScriptFrame frame;
- Expression *expr;
+ std::unique_ptr<Expression> expr;
Dictionary::Ptr dict;
expr = ConfigCompiler::CompileText("<test>", "");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == Empty);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "\n3");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 3);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "{ 3\n\n5 }");
BOOST_CHECK_THROW(expr->Evaluate(frame).GetValue(), ScriptError);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "1 + 3");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 4);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "3 - 1");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 2);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "5m * 10");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 3000);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "5m / 5");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 60);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "7 & 3");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 3);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "2 | 3");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 3);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "true && false");
BOOST_CHECK(!expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "true || false");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "3 < 5");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "3 > 5");
BOOST_CHECK(!expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "3 <= 3");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "3 >= 3");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "2 + 3 * 4");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 14);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "(2 + 3) * 4");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 20);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "2 * - 3");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == -6);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "-(2 + 3)");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == -5);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "- 2 * 2 - 2 * 3 - 4 * - 5");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 10);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "!0 == true");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "~0");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == (double)~(long)0);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "4 << 8");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 1024);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "1024 >> 4");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 64);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "2 << 3 << 4");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 256);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "256 >> 4 >> 3");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 2);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "\"hello\" == \"hello\"");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "\"hello\" != \"hello\"");
BOOST_CHECK(!expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "\"foo\" in [ \"foo\", \"bar\" ]");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "\"foo\" in [ \"bar\", \"baz\" ]");
BOOST_CHECK(!expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "\"foo\" in null");
BOOST_CHECK(!expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "\"foo\" in \"bar\"");
BOOST_CHECK_THROW(expr->Evaluate(frame).GetValue(), ScriptError);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "\"foo\" !in [ \"bar\", \"baz\" ]");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "\"foo\" !in [ \"foo\", \"bar\" ]");
BOOST_CHECK(!expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "\"foo\" !in null");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "\"foo\" !in \"bar\"");
BOOST_CHECK_THROW(expr->Evaluate(frame).GetValue(), ScriptError);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "{ a += 3 }");
dict = expr->Evaluate(frame).GetValue();
- delete expr;
BOOST_CHECK(dict->GetLength() == 1);
BOOST_CHECK(dict->Get("a") == 3);
expr = ConfigCompiler::CompileText("<test>", "test");
BOOST_CHECK_THROW(expr->Evaluate(frame).GetValue(), ScriptError);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "null + 3");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 3);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "3 + null");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 3);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "\"test\" + 3");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == "test3");
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "\"\\\"te\\\\st\"");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == "\"te\\st");
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "\"\\'test\"");
BOOST_CHECK_THROW(expr->Evaluate(frame).GetValue(), ScriptError);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "({ a = 3\nb = 3 })");
BOOST_CHECK(expr->Evaluate(frame).GetValue().IsObjectType<Dictionary>());
- delete expr;
}
BOOST_AUTO_TEST_CASE(advanced)
{
ScriptFrame frame;
- Expression *expr;
+ std::unique_ptr<Expression> expr;
Function::Ptr func;
expr = ConfigCompiler::CompileText("<test>", "regex(\"^Hello\", \"Hello World\")");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "__boost_test()");
BOOST_CHECK_THROW(expr->Evaluate(frame).GetValue(), ScriptError);
- delete expr;
Object::Ptr self = new Object();
ScriptFrame frame2(self);
expr = ConfigCompiler::CompileText("<test>", "this");
BOOST_CHECK(expr->Evaluate(frame2).GetValue() == Value(self));
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "var v = 7; v");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "{ a = 3 }.a");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 3);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "[ 2, 3 ][1]");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 3);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "var v = { a = 3}; v.a");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 3);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "a = 3 b = 3");
BOOST_CHECK_THROW(expr->Evaluate(frame).GetValue(), ScriptError);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "function() { 3 }()");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 3);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "function() { return 3, 5 }()");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 3);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "typeof([]) == Array");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "typeof({}) == Dictionary");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "typeof(3) == Number");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "typeof(\"test\") == String");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "(7 | 8) == 15");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "(7 ^ 8) == 15");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "(7 & 15) == 7");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "7 in [7] == true");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "7 !in [7] == false");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "(7 | 8) > 14");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "(7 ^ 8) > 14");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "(7 & 15) > 6");
BOOST_CHECK(expr->Evaluate(frame).GetValue());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "\"a\" = 3");
BOOST_CHECK_THROW(expr->Evaluate(frame).GetValue(), ScriptError);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "3 = 3");
BOOST_CHECK_THROW(expr->Evaluate(frame).GetValue(), ScriptError);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "var e; e");
BOOST_CHECK(expr->Evaluate(frame).GetValue().IsEmpty());
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "var e = 3; e");
BOOST_CHECK(expr->Evaluate(frame).GetValue() == 3);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "Array.x");
BOOST_CHECK_THROW(expr->Evaluate(frame).GetValue(), ScriptError);
- delete expr;
expr = ConfigCompiler::CompileText("<test>", "{{ 3 }}");
func = expr->Evaluate(frame).GetValue();
BOOST_CHECK(func->Invoke() == 3);
- delete expr;
}
BOOST_AUTO_TEST_SUITE_END()
}
)CONFIG";
- Expression *expr = ConfigCompiler::CompileText("<livestatus>", config);
+ std::unique_ptr<Expression> expr = ConfigCompiler::CompileText("<livestatus>", config);
expr->Evaluate(*ScriptFrame::GetCurrentFrame());
}
};