X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/6a9812501258df26b7c487e50744b91abe8ebe39..1504c9b837a7561d8ae2c81f1c4d57fe0f138781:/Parser.hpp diff --git a/Parser.hpp b/Parser.hpp index cdeff50..a994ead 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -50,6 +50,7 @@ #include #include +#include #include #include "location.hh" @@ -244,11 +245,13 @@ struct CYIdentifier : { CYIdentifier *replace_; size_t offset_; + size_t usage_; CYIdentifier(const char *word) : CYWord(word), replace_(NULL), - offset_(0) + offset_(0), + usage_(0) { } @@ -311,14 +314,19 @@ enum CYIdentifierFlags { typedef std::set CYCStringSet; typedef std::set CYIdentifierValueSet; -typedef std::set CYIdentifierAddressSet; -typedef std::vector CYIdentifierAddressVector; typedef std::map CYIdentifierAddressFlagsMap; +struct CYIdentifierUsage { + CYIdentifier *identifier_; + size_t usage_; +}; + +typedef std::vector CYIdentifierUsageVector; + struct CYScope { CYScope *parent_; - CYIdentifierAddressFlagsMap internal_; + CYIdentifierAddressFlagsMap internal_; CYIdentifierValueSet identifiers_; CYScope() : @@ -326,6 +334,9 @@ struct CYScope { { } + virtual ~CYScope() { + } + void Declare(CYContext &context, CYIdentifier *identifier, CYIdentifierFlags flags); virtual CYIdentifier *Lookup(CYContext &context, CYIdentifier *identifier); void Merge(CYContext &context, CYIdentifier *identifier); @@ -333,11 +344,9 @@ struct CYScope { }; struct CYProgram : - CYScope, CYThing { CYStatement *statements_; - CYIdentifierAddressVector rename_; CYProgram(CYStatement *statements) : statements_(statements) @@ -348,22 +357,22 @@ struct CYProgram : virtual void Output(CYOutput &out) const; }; -struct CYContext : - CYScope -{ +struct CYContext { apr_pool_t *pool_; CYOptions &options_; CYScope *scope_; - CYProgram *program_; + CYIdentifierUsageVector rename_; CYContext(apr_pool_t *pool, CYOptions &options) : pool_(pool), options_(options), - scope_(this), - program_(NULL) + scope_(NULL) { } + virtual ~CYContext() { + } + template void Replace(Type_ *&value) { for (;;) if (value == NULL) @@ -382,11 +391,9 @@ struct CYBlock : CYThing { CYStatement *statements_; - CYScope *scope_; - CYBlock(CYStatement *statements, CYScope *scope = NULL) : - statements_(statements), - scope_(scope) + CYBlock(CYStatement *statements) : + statements_(statements) { } @@ -446,12 +453,39 @@ class CYDriver { CYProgram *program_; Errors errors_; + bool auto_; + + struct Context { + CYExpression *context_; + + Context(CYExpression *context) : + context_(context) + { + } + + typedef std::vector Words; + Words words_; + }; + + typedef std::vector Contexts; + Contexts contexts_; + + CYExpression *context_; + + enum Mode { + AutoNone, + AutoPrimary, + AutoDirect, + AutoIndirect, + AutoMessage + } mode_; + private: void ScannerInit(); void ScannerDestroy(); public: - CYDriver(const std::string &filename); + CYDriver(apr_pool_t *pool = NULL, const std::string &filename = ""); ~CYDriver(); Condition GetCondition(); @@ -1359,9 +1393,7 @@ struct CYWhile : virtual void Output(CYOutput &out, CYFlags flags) const; }; -struct CYFunction : - CYScope -{ +struct CYFunction { CYIdentifier *name_; CYFunctionParameter *parameters_; CYBlock code_; @@ -1369,7 +1401,7 @@ struct CYFunction : CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) : name_(name), parameters_(parameters), - code_(statements, this) + code_(statements) { }