#include "Pooling.hpp"
#include "Options.hpp"
-class CYContext;
+struct CYContext;
struct CYThing {
virtual ~CYThing() {
};
struct CYNonLocal;
+struct CYThisScope;
struct CYContext {
CYOptions &options_;
CYScope *scope_;
+ CYThisScope *this_;
+
CYIdentifierUsageVector rename_;
CYNonLocal *nonlocal_;
CYContext(CYOptions &options) :
options_(options),
scope_(NULL),
+ this_(NULL),
nonlocal_(NULL),
nextlocal_(NULL),
unique_(0)
}
};
+struct CYThisScope :
+ CYNext<CYThisScope>
+{
+ CYIdentifier *identifier_;
+
+ CYThisScope() :
+ identifier_(NULL)
+ {
+ }
+
+ CYIdentifier *Identifier(CYContext &context) {
+ if (next_ != NULL)
+ return next_->Identifier(context);
+ if (identifier_ == NULL)
+ identifier_ = context.Unique();
+ return identifier_;
+ }
+};
+
struct CYBlock :
CYStatement,
CYThing
}
void AddPrev(CYStatement *statement) {
- CYSetLast(statement, statements_);
+ CYSetLast(statement) = statements_;
statements_ = statement;
}
CYNewLine
};
+class CYStream :
+ public std::istream
+{
+ private:
+ class CYBuffer :
+ public std::streambuf
+ {
+ public:
+ CYBuffer(const char *start, const char *end) {
+ setg(const_cast<char *>(start), const_cast<char *>(start), const_cast<char *>(end));
+ }
+ } buffer_;
+
+ public:
+ CYStream(const char *start, const char *end) :
+ std::istream(&buffer_),
+ buffer_(start, end)
+ {
+ }
+};
+
class CYDriver {
public:
void *scanner_;
CYState state_;
- bool nobrace_;
std::stack<bool> in_;
- const char *data_;
- size_t size_;
- FILE *file_;
+ struct {
+ bool AtImplementation;
+ bool Function;
+ bool OpenBrace;
+ } no_;
+
+ std::istream &data_;
bool strict_;
+ bool commented_;
enum Condition {
RegExpCondition,
void ScannerDestroy();
public:
- CYDriver(const std::string &filename = "");
+ CYDriver(std::istream &data, const std::string &filename = "");
~CYDriver();
Condition GetCondition();
}
void AddPrev(CYExpression *expression) {
- CYSetLast(expression, expressions_);
+ CYSetLast(expression) = expressions_;
expressions_ = expression;
}
CYNext<CYComprehension>,
CYThing
{
+ CYComprehension(CYComprehension *next = NULL) :
+ CYNext<CYComprehension>(next)
+ {
+ }
+
virtual const char *Name() const = 0;
virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
CYIdentifier *name_;
CYExpression *set_;
- CYForInComprehension(CYIdentifier *name, CYExpression *set) :
+ CYForInComprehension(CYIdentifier *name, CYExpression *set, CYComprehension *next = NULL) :
+ CYComprehension(next),
name_(name),
set_(set)
{
CYIdentifier *name_;
CYExpression *set_;
- CYForOfComprehension(CYIdentifier *name, CYExpression *set) :
+ CYForOfComprehension(CYIdentifier *name, CYExpression *set, CYComprehension *next = NULL) :
+ CYComprehension(next),
name_(name),
set_(set)
{
CYIdentifier *name_;
CYFunctionParameter *parameters_;
CYBlock code_;
+
CYNonLocal *nonlocal_;
+ CYThisScope this_;
CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
name_(name),
virtual void Output(CYOutput &out, CYFlags flags) const;
};
+// XXX: this should derive from CYAnonymousFunction
+struct CYFatArrow :
+ CYFunction,
+ CYExpression
+{
+ CYFatArrow(CYFunctionParameter *parameters, CYStatement *statements) :
+ CYFunction(NULL, parameters, statements)
+ {
+ }
+
+ CYPrecedence(0)
+ CYRightHand(false)
+
+ virtual CYExpression *Replace(CYContext &context);
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
// XXX: this should derive from CYAnonymousFunctionExpression
struct CYRubyProc :
CYFunctionExpression