Use an AST node for the 'library' keyword

fixes #10017
This commit is contained in:
Gunnar Beutner 2015-08-27 14:47:31 +02:00
parent 865344ec57
commit f2a055c85a
5 changed files with 27 additions and 21 deletions

View File

@ -324,13 +324,6 @@ lterm_items_inner: lterm %dprec 2
} }
; ;
library: T_LIBRARY T_STRING
{
context->HandleLibrary($2);
free($2);
}
;
identifier: T_IDENTIFIER identifier: T_IDENTIFIER
| T_STRING | T_STRING
; ;
@ -436,9 +429,9 @@ combined_set_op: T_SET
| T_SET_BINARY_OR | T_SET_BINARY_OR
; ;
lterm: library lterm: T_LIBRARY rterm
{ {
$$ = MakeLiteral(); // ASTify this $$ = new LibraryExpression($2, @$);
} }
| rterm combined_set_op rterm | rterm combined_set_op rterm
{ {

View File

@ -217,16 +217,6 @@ Expression *ConfigCompiler::HandleIncludeZones(const String& tag, const String&
return new DictExpression(expressions); return new DictExpression(expressions);
} }
/**
* Handles the library directive.
*
* @param library The name of the library.
*/
void ConfigCompiler::HandleLibrary(const String& library)
{
Loader::LoadExtensionLibrary(library);
}
/** /**
* Compiles a stream. * Compiles a stream.
* *

View File

@ -109,7 +109,6 @@ public:
Expression *HandleInclude(const String& include, bool search, const DebugInfo& debuginfo = DebugInfo()); Expression *HandleInclude(const String& include, bool search, const DebugInfo& debuginfo = DebugInfo());
Expression *HandleIncludeRecursive(const String& path, const String& pattern, const DebugInfo& debuginfo = DebugInfo()); Expression *HandleIncludeRecursive(const String& path, const String& pattern, const DebugInfo& debuginfo = DebugInfo());
Expression *HandleIncludeZones(const String& tag, const String& path, const String& pattern, const DebugInfo& debuginfo = DebugInfo()); Expression *HandleIncludeZones(const String& tag, const String& path, const String& pattern, const DebugInfo& debuginfo = DebugInfo());
void HandleLibrary(const String& library);
size_t ReadInput(char *buffer, size_t max_bytes); size_t ReadInput(char *buffer, size_t max_bytes);
void *GetScanner(void) const; void *GetScanner(void) const;

View File

@ -26,6 +26,7 @@
#include "base/logger.hpp" #include "base/logger.hpp"
#include "base/exception.hpp" #include "base/exception.hpp"
#include "base/scriptglobal.hpp" #include "base/scriptglobal.hpp"
#include "base/loader.hpp"
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <boost/exception_ptr.hpp> #include <boost/exception_ptr.hpp>
#include <boost/exception/errinfo_nested_exception.hpp> #include <boost/exception/errinfo_nested_exception.hpp>
@ -780,3 +781,16 @@ ExpressionResult ForExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint)
return VMOps::For(frame, m_FKVar, m_FVVar, valueres.GetValue(), m_Expression, m_DebugInfo); return VMOps::For(frame, m_FKVar, m_FVVar, valueres.GetValue(), m_Expression, m_DebugInfo);
} }
ExpressionResult LibraryExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
{
if (frame.Sandboxed)
BOOST_THROW_EXCEPTION(ScriptError("Loading libraries is not allowed in sandbox mode.", m_DebugInfo));
ExpressionResult libres = m_Operand->Evaluate(frame, dhint);
CHECK_RESULT(libres);
Loader::LoadExtensionLibrary(libres.GetValue());
return Empty;
}

View File

@ -288,7 +288,6 @@ protected:
Expression *m_Operand2; Expression *m_Operand2;
}; };
class I2_CONFIG_API VariableExpression : public DebuggableExpression class I2_CONFIG_API VariableExpression : public DebuggableExpression
{ {
public: public:
@ -885,6 +884,17 @@ private:
Expression *m_Expression; Expression *m_Expression;
}; };
class I2_CONFIG_API LibraryExpression : public UnaryExpression
{
public:
LibraryExpression(Expression *expression, const DebugInfo& debugInfo = DebugInfo())
: UnaryExpression(expression, debugInfo)
{ }
protected:
virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
};
} }
#endif /* EXPRESSION_H */ #endif /* EXPRESSION_H */