ConfigCompiler::~ConfigCompiler(void)
{
DestroyScanner();
- delete m_Input;
}
/**
Loader::LoadExtensionLibrary(library);
}
-void ConfigCompiler::CompileHelper(void)
-{
- try {
- m_Promise.set_value(boost::shared_ptr<Expression>(Compile()));
- } catch (...) {
- m_Promise.set_exception(boost::current_exception());
- }
-
- delete this;
-}
-
/**
* Compiles a stream.
*
stream->exceptions(std::istream::badbit);
- ConfigCompiler* ctx = new ConfigCompiler(path, stream, zone, module);
+ ConfigCompiler ctx(path, stream, zone, module);
- if (async) {
- boost::shared_future<boost::shared_ptr<Expression> > ftr = boost::shared_future<boost::shared_ptr<Expression> >(ctx->m_Promise.get_future());
-
- Utility::QueueAsyncCallback(boost::bind(&ConfigCompiler::CompileHelper, ctx));
- return new FutureExpression(ftr);
- } else {
- Expression *expr;
-
- try {
- expr = ctx->Compile();
- } catch (...) {
- delete ctx;
- throw;
- }
-
- delete ctx;
- return expr;
+ try {
+ return ctx.Compile();
+ } catch (const ScriptError& ex) {
+ return new ThrowExpression(MakeLiteral(ex.what()), ex.GetDebugInfo());
+ } catch (const std::exception& ex) {
+ return new ThrowExpression(MakeLiteral(DiagnosticInformation(ex)));
}
}
{
CONTEXT("Compiling configuration file '" + path + "'");
- std::ifstream *stream = new std::ifstream();
- stream->open(path.CStr(), std::ifstream::in);
+ std::ifstream stream(path.CStr(), std::ifstream::in);
- if (!*stream)
+ if (!stream)
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("std::ifstream::open")
<< boost::errinfo_errno(errno)
Log(LogInformation, "ConfigCompiler")
<< "Compiling config file: " << path;
- return CompileStream(path, stream, async, zone, module);
+ return CompileStream(path, &stream, async, zone, module);
}
/**
Expression *ConfigCompiler::CompileText(const String& path, const String& text,
bool async, const String& zone, const String& module)
{
- std::stringstream *stream = new std::stringstream(text);
- return CompileStream(path, stream, async, zone, module);
+ std::stringstream stream(text);
+ return CompileStream(path, &stream, async, zone, module);
}
/**
keywords.push_back("if");
keywords.push_back("else");
keywords.push_back("while");
+ keywords.push_back("throw");
}
return keywords;
boost::shared_ptr<Expression> m_Expression;
};
-class I2_CONFIG_API FutureExpression : public Expression
-{
-public:
- FutureExpression(const boost::shared_future<boost::shared_ptr<Expression> >& future)
- : m_Future(future)
- { }
-
-protected:
- virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override
- {
- return m_Future.get()->DoEvaluate(frame, dhint);
- }
-
- virtual const DebugInfo& GetDebugInfo(void) const override
- {
- return m_Future.get()->GetDebugInfo();
- }
-
-private:
- mutable boost::shared_future<boost::shared_ptr<Expression> > m_Future;
-};
-
class I2_CONFIG_API LiteralExpression : public Expression
{
public:
I2_CONFIG_API void BindToScope(Expression *& expr, ScopeSpecifier scopeSpec);
+class I2_CONFIG_API ThrowExpression : public DebuggableExpression
+{
+public:
+ ThrowExpression(Expression *message, const DebugInfo& debugInfo = DebugInfo())
+ : DebuggableExpression(debugInfo), m_Message(message)
+ { }
+
+ ~ThrowExpression(void)
+ {
+ delete m_Message;
+ }
+
+protected:
+ virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
+
+private:
+ Expression *m_Message;
+};
+
class I2_CONFIG_API ImportExpression : public DebuggableExpression
{
public: