2013-04-10 22:49:22 +02:00
|
|
|
#ifndef CSM_WORLD_SCRIPTCONTEXT_H
|
|
|
|
#define CSM_WORLD_SCRIPTCONTEXT_H
|
|
|
|
|
2014-02-14 12:46:54 +01:00
|
|
|
#include <map>
|
2013-09-19 12:30:42 +02:00
|
|
|
#include <string>
|
2022-10-19 19:02:00 +02:00
|
|
|
#include <utility>
|
2013-09-19 12:30:42 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2013-04-10 22:49:22 +02:00
|
|
|
#include <components/compiler/context.hpp>
|
2014-02-14 12:46:54 +01:00
|
|
|
#include <components/compiler/locals.hpp>
|
2022-11-16 00:07:33 +01:00
|
|
|
#include <components/misc/algorithm.hpp>
|
2013-04-10 22:49:22 +02:00
|
|
|
|
|
|
|
namespace CSMWorld
|
|
|
|
{
|
2013-09-19 12:30:42 +02:00
|
|
|
class Data;
|
|
|
|
|
2013-04-10 22:49:22 +02:00
|
|
|
class ScriptContext : public Compiler::Context
|
|
|
|
{
|
2013-09-19 12:30:42 +02:00
|
|
|
const Data& mData;
|
2022-10-06 19:39:46 +02:00
|
|
|
mutable std::vector<ESM::RefId> mIds;
|
2013-09-19 12:30:42 +02:00
|
|
|
mutable bool mIdsUpdated;
|
2023-03-03 13:34:40 +01:00
|
|
|
mutable std::map<ESM::RefId, Compiler::Locals, std::less<>> mLocals;
|
2013-04-10 22:49:22 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
public:
|
2013-09-19 12:30:42 +02:00
|
|
|
ScriptContext(const Data& data);
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
bool canDeclareLocals() const override;
|
2013-04-10 22:49:22 +02:00
|
|
|
///< Is the compiler allowed to declare local variables?
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
char getGlobalType(const std::string& name) const override;
|
2013-04-10 22:49:22 +02:00
|
|
|
///< 'l: long, 's': short, 'f': float, ' ': does not exist.
|
|
|
|
|
2022-10-06 19:39:46 +02:00
|
|
|
std::pair<char, bool> getMemberType(const std::string& name, const ESM::RefId& id) const override;
|
2014-02-10 14:45:55 +01:00
|
|
|
///< Return type of member variable \a name in script \a id or in script of reference of
|
|
|
|
/// \a id
|
|
|
|
/// \return first: 'l: long, 's': short, 'f': float, ' ': does not exist.
|
|
|
|
/// second: true: script of reference
|
2013-04-10 22:49:22 +02:00
|
|
|
|
2022-10-06 19:39:46 +02:00
|
|
|
bool isId(const ESM::RefId& name) const override;
|
2013-04-10 22:49:22 +02:00
|
|
|
///< Does \a name match an ID, that can be referenced?
|
2013-09-19 12:30:42 +02:00
|
|
|
|
|
|
|
void invalidateIds();
|
2014-02-14 13:38:30 +01:00
|
|
|
|
|
|
|
void clear();
|
|
|
|
///< Remove all cached data.
|
2015-09-22 15:36:00 +02:00
|
|
|
|
|
|
|
/// \return Were there any locals that needed clearing?
|
|
|
|
bool clearLocals(const std::string& script);
|
2013-04-10 22:49:22 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|