_assert(out_.sputc(value) != EOF);
recent_ = indent_;
if (value == '\n')
- position_.lines(1);
+ position_.Lines(1);
else
- position_.columns(1);
+ position_.Columns(1);
}
_finline void operator ()(const char *data, std::streamsize size) {
_assert(out_.sputn(data, size) == size);
recent_ = indent_;
- position_.columns(size);
+ position_.Columns(size);
}
_finline void operator ()(const char *data) {
}
};
+struct CYExpression;
+struct CYAssignment;
+
struct CYPropertyName {
+ virtual bool Computed() const {
+ return false;
+ }
+
+ virtual bool Constructor() const {
+ return false;
+ }
+
+ virtual CYExpression *PropertyName(CYContext &context) = 0;
virtual void PropertyName(CYOutput &out) const = 0;
};
-struct CYExpression;
-struct CYAssignment;
-
enum CYNeeded {
CYNever = -1,
CYSometimes = 0,
CYNoFlags = 0,
CYNoBrace = (1 << 0),
CYNoFunction = (1 << 1),
- CYNoIn = (1 << 2),
- CYNoCall = (1 << 3),
- CYNoRightHand = (1 << 4),
- CYNoDangle = (1 << 5),
- CYNoInteger = (1 << 6),
- CYNoBF = (CYNoBrace | CYNoFunction),
+ CYNoClass = (1 << 2),
+ CYNoIn = (1 << 3),
+ CYNoCall = (1 << 4),
+ CYNoRightHand = (1 << 5),
+ CYNoDangle = (1 << 6),
+ CYNoInteger = (1 << 7),
+ CYNoBFC = (CYNoBrace | CYNoFunction | CYNoClass),
};
_finline CYFlags operator ~(CYFlags rhs) {
}
_finline CYFlags CYRight(CYFlags flags) {
- return flags & ~CYNoBF;
+ return flags & ~CYNoBFC;
}
_finline CYFlags CYCenter(CYFlags flags) {
virtual void Output(CYOutput &out, CYFlags flags) const = 0;
};
-struct CYStatements {
- CYStatement *first_;
- CYStatement *last_;
-
- CYStatements() :
- first_(NULL),
- last_(NULL)
- {
- }
-
- operator CYStatement *() const {
- return first_;
- }
-
- CYStatements &operator ->*(CYStatement *next) {
- if (next != NULL)
- if (first_ == NULL) {
- first_ = next;
- last_ = next;
- } else for (;; last_ = last_->next_)
- if (last_->next_ == NULL) {
- last_->next_ = next;
- last_ = next;
- break;
- }
- return *this;
- }
-};
-
-struct CYClassName {
- virtual CYExpression *ClassName(CYContext &context, bool object) = 0;
- virtual void ClassName(CYOutput &out, bool object) const = 0;
-};
+typedef CYList<CYStatement> CYStatements;
struct CYWord :
CYThing,
- CYPropertyName,
- CYClassName
+ CYPropertyName
{
const char *word_;
word_ = value;
}
+ virtual bool Constructor() const {
+ return strcmp(word_, "constructor") == 0;
+ }
+
virtual const char *Word() const;
virtual void Output(CYOutput &out) const;
- virtual CYExpression *ClassName(CYContext &context, bool object);
- virtual void ClassName(CYOutput &out, bool object) const;
+ virtual CYExpression *PropertyName(CYContext &context);
virtual void PropertyName(CYOutput &out) const;
};
CYScope *scope_;
CYThisScope *this_;
+ CYIdentifier *super_;
CYIdentifierUsageVector rename_;
options_(options),
scope_(NULL),
this_(NULL),
+ super_(NULL),
nonlocal_(NULL),
nextlocal_(NULL),
unique_(0)
struct CYExpression :
CYForInitializer,
CYForInInitializer,
- CYClassName,
CYThing
{
virtual int Precedence() const = 0;
virtual void Output(CYOutput &out, CYFlags flags) const = 0;
void Output(CYOutput &out, int precedence, CYFlags flags) const;
- virtual CYExpression *ClassName(CYContext &context, bool object);
- virtual void ClassName(CYOutput &out, bool object) const;
-
virtual CYExpression *Replace(CYContext &context) = 0;
virtual CYAssignment *Assignment(CYContext &context);
return this;
}
- virtual const char *Name() const = 0;
-
virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
CYFunctionParameter *Parameters(CYContext &context) const;
virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
struct CYForInComprehension :
CYComprehension
{
- CYIdentifier *name_;
+ CYDeclaration *declaration_;
CYExpression *set_;
- CYForInComprehension(CYIdentifier *name, CYExpression *set, CYComprehension *next = NULL) :
+ CYForInComprehension(CYDeclaration *declaration, CYExpression *set, CYComprehension *next = NULL) :
CYComprehension(next),
- name_(name),
+ declaration_(declaration),
set_(set)
{
}
- virtual const char *Name() const {
- return name_->Word();
- }
-
virtual CYFunctionParameter *Parameter(CYContext &context) const;
virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
virtual void Output(CYOutput &out) const;
struct CYForOfComprehension :
CYComprehension
{
- CYIdentifier *name_;
+ CYDeclaration *declaration_;
CYExpression *set_;
- CYForOfComprehension(CYIdentifier *name, CYExpression *set, CYComprehension *next = NULL) :
+ CYForOfComprehension(CYDeclaration *declaration, CYExpression *set, CYComprehension *next = NULL) :
CYComprehension(next),
- name_(name),
+ declaration_(declaration),
set_(set)
{
}
- virtual const char *Name() const {
- return name_->Word();
- }
-
virtual CYFunctionParameter *Parameter(CYContext &context) const;
virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
virtual void Output(CYOutput &out) const;
{
}
- virtual const char *Name() const {
- return NULL;
- }
-
virtual CYFunctionParameter *Parameter(CYContext &context) const;
virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
virtual void Output(CYOutput &out) const;
CYString *Concat(CYContext &out, CYString *rhs) const;
virtual void Output(CYOutput &out, CYFlags flags) const;
+
+ virtual CYExpression *PropertyName(CYContext &context);
virtual void PropertyName(CYOutput &out) const;
};
virtual CYString *String(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
+
+ virtual CYExpression *PropertyName(CYContext &context);
+ virtual void PropertyName(CYOutput &out) const;
+};
+
+struct CYComputed :
+ CYPropertyName
+{
+ CYExpression *expression_;
+
+ CYComputed(CYExpression *expression) :
+ expression_(expression)
+ {
+ }
+
+ virtual bool Computed() const {
+ return true;
+ }
+
+ virtual CYExpression *PropertyName(CYContext &context);
virtual void PropertyName(CYOutput &out) const;
};
virtual void Output(CYOutput &out, CYFlags flags) const;
};
-struct CYProperty :
- CYNext<CYProperty>,
- CYThing
-{
- CYPropertyName *name_;
- CYExpression *value_;
-
- CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) :
- CYNext<CYProperty>(next),
- name_(name),
- value_(value)
- {
- }
-
- void Replace(CYContext &context);
- virtual void Output(CYOutput &out) const;
-};
-
struct CYDeclaration :
CYForInInitializer
{
void Replace(CYContext &context);
CYExpression *Expression(CYContext &context);
- CYProperty *Property(CYContext &context);
CYArgument *Argument(CYContext &context);
CYFunctionParameter *Parameter(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
-struct CYLetStatement :
+struct CYLet :
CYStatement
{
CYDeclarations *declarations_;
- CYStatement *code_;
- CYLetStatement(CYDeclarations *declarations, CYStatement *code) :
- declarations_(declarations),
- code_(code)
+ CYLet(CYDeclarations *declarations) :
+ declarations_(declarations)
{
}
- CYCompact(Long)
+ CYCompact(None)
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
+struct CYBuilder {
+ CYList<CYDeclarations> declarations_;
+ CYList<CYStatement> statements_;
+
+ operator bool() const {
+ return statements_ != NULL;
+ }
+};
+
+struct CYProperty :
+ CYNext<CYProperty>,
+ CYThing
+{
+ CYPropertyName *name_;
+
+ CYProperty(CYPropertyName *name, CYProperty *next = NULL) :
+ CYNext<CYProperty>(next),
+ name_(name)
+ {
+ }
+
+ CYProperty *ReplaceAll(CYContext &context, CYBuilder &builder, CYExpression *self, bool update);
+ void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, bool protect);
+
+ virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect) = 0;
+
+ virtual void Replace(CYContext &context) = 0;
+ virtual void Output(CYOutput &out) const;
+};
+
+struct CYPropertyValue :
+ CYProperty
+{
+ CYExpression *value_;
+
+ CYPropertyValue(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) :
+ CYProperty(name, next),
+ value_(value)
+ {
+ }
+
+ virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect);
+ virtual void Replace(CYContext &context);
+ virtual void Output(CYOutput &out) const;
+};
+
struct CYFor :
CYStatement
{
CYExpression *constructor_;
CYArgument *arguments_;
- New(CYExpression *constructor, CYArgument *arguments) :
+ New(CYExpression *constructor, CYArgument *arguments = NULL) :
constructor_(constructor),
arguments_(arguments)
{
virtual CYExpression *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
+
+ virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
};
struct CYIf :
virtual void Output(CYOutput &out, CYFlags flags) const;
};
-// XXX: this should be split up into CYAnonymousFunction and CYNamedFunction (subclass)
struct CYFunction {
- CYIdentifier *name_;
CYFunctionParameter *parameters_;
CYStatement *code_;
CYNonLocal *nonlocal_;
bool implicit_;
CYThisScope this_;
+ CYIdentifier *super_;
- CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *code) :
- name_(name),
+ CYFunction(CYFunctionParameter *parameters, CYStatement *code) :
parameters_(parameters),
code_(code),
nonlocal_(NULL),
- implicit_(false)
+ implicit_(false),
+ super_(NULL)
{
}
- void Inject(CYContext &context);
- virtual void Replace_(CYContext &context, bool outer);
- virtual void Output(CYOutput &out, CYFlags flags) const;
+ void Replace(CYContext &context);
+ void Output(CYOutput &out) const;
};
-// XXX: this should be split up into CYAnonymousFunctionExpression and CYNamedFunctionExpression
struct CYFunctionExpression :
CYFunction,
CYExpression
{
+ CYIdentifier *name_;
+
CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *code) :
- CYFunction(name, parameters, code)
+ CYFunction(parameters, code),
+ name_(name)
{
}
virtual void Output(CYOutput &out, CYFlags flags) const;
};
-// XXX: this should derive from CYAnonymousFunction
struct CYFatArrow :
CYFunction,
CYExpression
{
CYFatArrow(CYFunctionParameter *parameters, CYStatement *code) :
- CYFunction(NULL, parameters, code)
+ CYFunction(parameters, code)
{
}
virtual void Output(CYOutput &out, CYFlags flags) const;
};
-// XXX: this should derive from CYAnonymousFunctionExpression
struct CYRubyProc :
- CYFunctionExpression
+ CYFunction,
+ CYExpression
{
CYRubyProc(CYFunctionParameter *parameters, CYStatement *code) :
- CYFunctionExpression(NULL, parameters, code)
+ CYFunction(parameters, code)
{
}
+ CYPrecedence(0)
+ CYRightHand(false)
+
virtual CYExpression *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
-// XXX: this should derive from CYNamedFunction
struct CYFunctionStatement :
CYFunction,
CYStatement
{
+ CYIdentifier *name_;
+
CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *code) :
- CYFunction(name, parameters, code)
+ CYFunction(parameters, code),
+ name_(name)
{
}
virtual void Output(CYOutput &out, CYFlags flags) const;
};
+struct CYPropertyMethod;
+
+struct CYMethod :
+ CYFunction,
+ CYProperty
+{
+ CYMethod(CYPropertyName *name, CYFunctionParameter *parameters, CYStatement *code, CYProperty *next = NULL) :
+ CYFunction(parameters, code),
+ CYProperty(name, next)
+ {
+ }
+
+ virtual CYFunctionExpression *Constructor();
+
+ using CYProperty::Replace;
+ virtual void Replace(CYContext &context);
+};
+
+struct CYPropertyGetter :
+ CYMethod
+{
+ CYPropertyGetter(CYPropertyName *name, CYStatement *code, CYProperty *next = NULL) :
+ CYMethod(name, NULL, code, next)
+ {
+ }
+
+ virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect);
+ virtual void Output(CYOutput &out) const;
+};
+
+struct CYPropertySetter :
+ CYMethod
+{
+ CYPropertySetter(CYPropertyName *name, CYFunctionParameter *parameters, CYStatement *code, CYProperty *next = NULL) :
+ CYMethod(name, parameters, code, next)
+ {
+ }
+
+ virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect);
+ virtual void Output(CYOutput &out) const;
+};
+
+struct CYPropertyMethod :
+ CYMethod
+{
+ CYPropertyMethod(CYPropertyName *name, CYFunctionParameter *parameters, CYStatement *code, CYProperty *next = NULL) :
+ CYMethod(name, parameters, code, next)
+ {
+ }
+
+ virtual CYFunctionExpression *Constructor();
+
+ virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect);
+ virtual void Output(CYOutput &out) const;
+};
+
+struct CYClassTail :
+ CYThing
+{
+ CYExpression *extends_;
+
+ CYFunctionExpression *constructor_;
+ CYList<CYProperty> instance_;
+ CYList<CYProperty> static_;
+
+ CYClassTail(CYExpression *extends) :
+ extends_(extends),
+ constructor_(NULL)
+ {
+ }
+
+ void Output(CYOutput &out) const;
+};
+
+struct CYClassExpression :
+ CYExpression
+{
+ CYIdentifier *name_;
+ CYClassTail *tail_;
+
+ CYClassExpression(CYIdentifier *name, CYClassTail *tail) :
+ name_(name),
+ tail_(tail)
+ {
+ }
+
+ CYPrecedence(0)
+ CYRightHand(false)
+
+ virtual CYExpression *Replace(CYContext &context);
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
+struct CYClassStatement :
+ CYStatement
+{
+ CYIdentifier *name_;
+ CYClassTail *tail_;
+
+ CYClassStatement(CYIdentifier *name, CYClassTail *tail) :
+ name_(name),
+ tail_(tail)
+ {
+ }
+
+ CYCompact(Long)
+
+ virtual CYStatement *Replace(CYContext &context);
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
+struct CYSuperCall :
+ CYExpression
+{
+ CYArgument *arguments_;
+
+ CYSuperCall(CYArgument *arguments) :
+ arguments_(arguments)
+ {
+ }
+
+ CYPrecedence(2)
+ CYRightHand(false)
+
+ virtual CYExpression *Replace(CYContext &context);
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
+struct CYSuperAccess :
+ CYExpression
+{
+ CYExpression *property_;
+
+ CYSuperAccess(CYExpression *property) :
+ property_(property)
+ {
+ }
+
+ CYPrecedence(1)
+ CYRightHand(false)
+
+ virtual CYExpression *Replace(CYContext &context);
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
struct CYExpress :
CYStatement
{