this repo has no description
at fixPythonPipStalling 94 lines 2.4 kB view raw
1#ifndef RESOURCECOMPILER_H 2#define RESOURCECOMPILER_H 3 4#include "Expression.h" 5#include "ResourceDefinitions.h" 6 7class Field; 8class RezWorld; 9class Diagnostic; 10 11class Subscripts 12{ 13 std::vector<int> subscripts; 14public: 15 Subscripts(); 16 ~Subscripts(); 17 18 void addSubscript(int x); 19 void popSubscript(); 20 bool operator<(const Subscripts& other) const; 21 bool empty() const { return subscripts.empty(); } 22}; 23 24class BinaryOutput 25{ 26protected: 27 int currentOffset; 28 std::vector<unsigned char> data; 29 std::vector<unsigned char> prePassData; 30 bool verboseFlag; 31 bool prePass; 32public: 33 BinaryOutput(); 34 void reset(bool prePass); 35 36 std::string resourceData(); 37 38 void reserve(int nBits) { write(nBits, 0); } 39 void write(int nBits, int value); 40 int tell() { return currentOffset; } 41 42 int peek(int bitPos, int size); 43 44 bool isPrePass() { return prePass; } 45}; 46 47class ResourceCompiler : public BinaryOutput 48{ 49 RezWorld& world; 50 TypeDefinitionPtr typeDefinition; 51 CompoundExprPtr body; 52 std::map<std::pair<std::string, Subscripts>, ExprPtr> labelValues; 53 std::map<std::pair<std::string, Subscripts>, int> arrayCounts; 54 std::map<std::string, int> curArrayIndices; 55 Field* currentField; 56 Subscripts currentSubscripts; 57 58 void beginArrayScope(std::string& arrayName, int index); 59public: 60 ResourceCompiler(RezWorld& world, TypeDefinitionPtr type, CompoundExprPtr body, bool verboseFlag); 61 62 ExprPtr lookupIdentifier(std::string name, const Subscripts& sub = Subscripts()); 63 64 void defineLabel(const std::string& name); 65 void compile(); 66 67 int getArrayCount(const std::string& arrayName); 68 int getArrayIndex(const std::string& arrayName); 69 70 71 class FieldScope 72 { 73 ResourceCompiler *compiler; 74 public: 75 FieldScope(ResourceCompiler* compiler, Field *field) 76 : compiler(compiler) { compiler->currentField = field; } 77 ~FieldScope() { compiler->currentField = nullptr; } 78 }; 79 80 class ArrayScope 81 { 82 ResourceCompiler *compiler; 83 public: 84 ArrayScope(ResourceCompiler* compiler, std::string& arrayName, int index) 85 : compiler(compiler) { compiler->beginArrayScope(arrayName, index); } 86 ~ArrayScope() { compiler->currentSubscripts.popSubscript(); } 87 }; 88 89 void problem(Diagnostic d); 90}; 91 92 93 94#endif // RESOURCECOMPILER_H