🛰️航天仿真算法库 SpaceAST 0.0.1
载入中...
搜索中...
未找到
Interpreter.hpp
浏览该文件的文档.
1
20
21#pragma once
22
23#include "AstGlobal.h"
24#include "SymbolTable.hpp"
25#include "SymbolScope.hpp"
26#include "CallStack.hpp"
27#include "ScriptContext.hpp"
28#include <memory>
29#include <string>
30
31AST_NAMESPACE_BEGIN
32
33class ISymbolScope;
34
39class AST_SCRIPT_API Interpreter
40{
41public:
43
48 explicit Interpreter(ISymbolScope* symbolScope);
50
55 ISymbolScope* currentScope() { return symbolScope_.get(); }
56
62 void interpret(StringView code);
63
64
69 const std::string& errString() const { return errString_; }
70
71
76 void setErrString(StringView err) { errString_ = std::string(err); }
77
78
82 void clearErrString() { errString_.clear(); }
83
84protected:
85 std::unique_ptr<ISymbolScope> symbolScope_;
86 std::string errString_;
87};
88
89
91AST_SCRIPT_API Interpreter* aNewInterpreter();
92
96AST_SCRIPT_API Interpreter* aNewInterpreter(ISymbolScope* symbolScope);
97
98
101AST_SCRIPT_API void aDelInterpreter(Interpreter* interpreter);
102
103
107public:
108 explicit InterpreterContext(Interpreter& interpreter)
109 : InterpreterContext(&interpreter)
110 {
111 }
112 explicit InterpreterContext(Interpreter* interpreter)
113 {
114 oldInterpreter_ = aScript_SwapInterpreter(interpreter);
115 }
117 {
118 aScript_SetInterpreter(oldInterpreter_);
119 }
120private:
121 Interpreter* oldInterpreter_ = nullptr;
122
123 A_DISABLE_COPY(InterpreterContext);
124};
125
126
127
128AST_NAMESPACE_END
定义 SymbolScope.hpp:35
解释器上下文守卫
定义 Interpreter.hpp:106
解释器
定义 Interpreter.hpp:40
void clearErrString()
清除错误字符串
定义 Interpreter.hpp:82
std::unique_ptr< ISymbolScope > symbolScope_
当前作用域
定义 Interpreter.hpp:85
void setErrString(StringView err)
设置错误字符串
定义 Interpreter.hpp:76
std::string errString_
错误字符串
定义 Interpreter.hpp:86
ISymbolScope * currentScope()
获取当前作用域
定义 Interpreter.hpp:55
const std::string & errString() const
获取错误字符串
定义 Interpreter.hpp:69
Interpreter * aScript_SwapInterpreter(Interpreter *interpreter)
交换解释器指针
定义 ScriptContext.cpp:80
void aScript_SetInterpreter(Interpreter *interpreter)
设置解释器指针
定义 ScriptContext.cpp:90
Interpreter * aNewInterpreter()
创建新的解释器,用于解释执行脚本中的代码。
定义 Interpreter.cpp:50
void aDelInterpreter(Interpreter *interpreter)
删除解释器,释放其占用的资源。
定义 Interpreter.cpp:61