2014-10-07 18:15:46 +00:00
|
|
|
#ifndef RESOURCECOMPILER_H
|
|
|
|
#define RESOURCECOMPILER_H
|
|
|
|
|
|
|
|
#include "Expression.h"
|
2014-10-07 22:41:40 +00:00
|
|
|
#include "ResourceDefinitions.h"
|
2014-10-07 18:15:46 +00:00
|
|
|
|
2014-10-07 22:41:40 +00:00
|
|
|
class Field;
|
2014-10-30 01:56:49 +00:00
|
|
|
class RezWorld;
|
|
|
|
class Diagnostic;
|
2014-10-07 22:41:40 +00:00
|
|
|
|
|
|
|
class Subscripts
|
|
|
|
{
|
|
|
|
std::vector<int> subscripts;
|
|
|
|
public:
|
|
|
|
Subscripts();
|
|
|
|
~Subscripts();
|
|
|
|
|
|
|
|
void addSubscript(int x);
|
|
|
|
void popSubscript();
|
|
|
|
bool operator<(const Subscripts& other) const;
|
|
|
|
bool empty() const { return subscripts.empty(); }
|
|
|
|
};
|
|
|
|
|
2014-10-16 00:29:12 +00:00
|
|
|
class BinaryOutput
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
int currentOffset;
|
|
|
|
std::vector<unsigned char> data;
|
|
|
|
std::vector<unsigned char> prePassData;
|
|
|
|
bool verboseFlag;
|
|
|
|
bool prePass;
|
|
|
|
public:
|
|
|
|
BinaryOutput();
|
|
|
|
void reset(bool prePass);
|
|
|
|
|
|
|
|
std::string resourceData();
|
|
|
|
|
|
|
|
void reserve(int nBits) { write(nBits, 0); }
|
|
|
|
void write(int nBits, int value);
|
|
|
|
int tell() { return currentOffset; }
|
|
|
|
|
|
|
|
int peek(int bitPos, int size);
|
|
|
|
|
|
|
|
bool isPrePass() { return prePass; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class ResourceCompiler : public BinaryOutput
|
2014-10-07 18:15:46 +00:00
|
|
|
{
|
2014-10-30 01:56:49 +00:00
|
|
|
RezWorld& world;
|
2014-10-07 22:41:40 +00:00
|
|
|
TypeDefinitionPtr typeDefinition;
|
|
|
|
CompoundExprPtr body;
|
|
|
|
std::map<std::pair<std::string, Subscripts>, ExprPtr> labelValues;
|
|
|
|
std::map<std::pair<std::string, Subscripts>, int> arrayCounts;
|
|
|
|
std::map<std::string, int> curArrayIndices;
|
|
|
|
Field* currentField;
|
|
|
|
Subscripts currentSubscripts;
|
|
|
|
|
|
|
|
void beginArrayScope(std::string& arrayName, int index);
|
2014-10-07 18:15:46 +00:00
|
|
|
public:
|
2014-10-30 01:56:49 +00:00
|
|
|
ResourceCompiler(RezWorld& world, TypeDefinitionPtr type, CompoundExprPtr body, bool verboseFlag);
|
2014-10-13 22:11:21 +00:00
|
|
|
|
2014-10-07 22:41:40 +00:00
|
|
|
ExprPtr lookupIdentifier(std::string name, const Subscripts& sub = Subscripts());
|
|
|
|
|
|
|
|
void defineLabel(const std::string& name);
|
|
|
|
void compile();
|
|
|
|
|
|
|
|
int getArrayCount(const std::string& arrayName);
|
|
|
|
int getArrayIndex(const std::string& arrayName);
|
|
|
|
|
2014-10-13 22:11:21 +00:00
|
|
|
|
2014-10-07 22:41:40 +00:00
|
|
|
class FieldScope
|
|
|
|
{
|
|
|
|
ResourceCompiler *compiler;
|
|
|
|
public:
|
|
|
|
FieldScope(ResourceCompiler* compiler, Field *field)
|
|
|
|
: compiler(compiler) { compiler->currentField = field; }
|
|
|
|
~FieldScope() { compiler->currentField = nullptr; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class ArrayScope
|
|
|
|
{
|
|
|
|
ResourceCompiler *compiler;
|
|
|
|
public:
|
|
|
|
ArrayScope(ResourceCompiler* compiler, std::string& arrayName, int index)
|
|
|
|
: compiler(compiler) { compiler->beginArrayScope(arrayName, index); }
|
|
|
|
~ArrayScope() { compiler->currentSubscripts.popSubscript(); }
|
|
|
|
};
|
2014-10-30 01:56:49 +00:00
|
|
|
|
|
|
|
void problem(Diagnostic d);
|
2014-10-07 18:15:46 +00:00
|
|
|
};
|
|
|
|
|
2014-10-07 22:41:40 +00:00
|
|
|
|
|
|
|
|
2014-10-07 18:15:46 +00:00
|
|
|
#endif // RESOURCECOMPILER_H
|