#include "Location.hpp"
#include "Options.hpp"
#include "Pooling.hpp"
+#include "String.hpp"
+
+double CYCastDouble(const char *value, size_t size);
+double CYCastDouble(const char *value);
+double CYCastDouble(CYUTF8String value);
+
+void CYNumerify(std::ostringstream &str, double value);
+void CYStringify(std::ostringstream &str, const char *data, size_t size, bool c = false);
+
+// XXX: this really should not be here ... :/
+void *CYPoolFile(CYPool &pool, const char *path, size_t *psize);
+CYUTF8String CYPoolFileUTF8String(CYPool &pool, const char *path);
struct CYContext;
CYNoRightHand = (1 << 5),
CYNoDangle = (1 << 6),
CYNoInteger = (1 << 7),
+ CYNoColon = (1 << 8),
CYNoBFC = (CYNoBrace | CYNoFunction | CYNoClass),
};
void Output(CYOutput &out, CYFlags flags) const;
};
-struct CYDeclaration;
+struct CYBinding;
struct CYFunctionParameter :
CYNext<CYFunctionParameter>,
CYThing
{
- CYDeclaration *initialiser_;
+ CYBinding *binding_;
- CYFunctionParameter(CYDeclaration *initialiser, CYFunctionParameter *next = NULL) :
+ CYFunctionParameter(CYBinding *binding, CYFunctionParameter *next = NULL) :
CYNext<CYFunctionParameter>(next),
- initialiser_(initialiser)
+ binding_(binding)
{
}
{
}
- CYComprehension *Modify(CYComprehension *next) {
- next_ = next;
- return this;
- }
-
virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
CYFunctionParameter *Parameters(CYContext &context) const;
virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
struct CYForInComprehension :
CYComprehension
{
- CYDeclaration *declaration_;
- CYExpression *set_;
+ CYBinding *binding_;
+ CYExpression *iterable_;
- CYForInComprehension(CYDeclaration *declaration, CYExpression *set, CYComprehension *next = NULL) :
+ CYForInComprehension(CYBinding *binding, CYExpression *iterable, CYComprehension *next = NULL) :
CYComprehension(next),
- declaration_(declaration),
- set_(set)
+ binding_(binding),
+ iterable_(iterable)
{
}
struct CYForOfComprehension :
CYComprehension
{
- CYDeclaration *declaration_;
- CYExpression *set_;
+ CYBinding *binding_;
+ CYExpression *iterable_;
- CYForOfComprehension(CYDeclaration *declaration, CYExpression *set, CYComprehension *next = NULL) :
+ CYForOfComprehension(CYBinding *binding, CYExpression *iterable, CYComprehension *next = NULL) :
CYComprehension(next),
- declaration_(declaration),
- set_(set)
+ binding_(binding),
+ iterable_(iterable)
{
}
struct CYBoolean :
CYTrivial
{
+ CYPrecedence(4)
+
+ virtual bool RightHand() const {
+ return true;
+ }
+
virtual bool Value() const = 0;
virtual void Output(CYOutput &out, CYFlags flags) const;
};
virtual CYFunctionParameter *Parameter() const;
};
+struct CYSymbol :
+ CYTarget
+{
+ const char *name_;
+
+ CYSymbol(const char *name) :
+ name_(name)
+ {
+ }
+
+ CYPrecedence(0)
+
+ virtual CYTarget *Replace(CYContext &context);
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
struct CYPrefix :
CYExpression
{
CYThing,
CYNext<CYClause>
{
- CYExpression *case_;
+ CYExpression *value_;
CYStatement *code_;
- CYClause(CYExpression *_case, CYStatement *code) :
- case_(_case),
+ CYClause(CYExpression *value, CYStatement *code) :
+ value_(value),
code_(code)
{
}
};
struct CYElement :
+ CYNext<CYElement>,
CYThing
{
+ CYElement(CYElement *next) :
+ CYNext<CYElement>(next)
+ {
+ }
+
virtual bool Elision() const = 0;
virtual void Replace(CYContext &context) = 0;
};
struct CYElementValue :
- CYNext<CYElement>,
CYElement
{
CYExpression *value_;
- CYElementValue(CYExpression *value, CYElement *next) :
- CYNext<CYElement>(next),
+ CYElementValue(CYExpression *value, CYElement *next = NULL) :
+ CYElement(next),
value_(value)
{
}
{
CYExpression *value_;
- CYElementSpread(CYExpression *value) :
+ CYElementSpread(CYExpression *value, CYElement *next = NULL) :
+ CYElement(next),
value_(value)
{
}
virtual void Output(CYOutput &out, CYFlags flags) const;
};
-struct CYDeclaration {
+struct CYBinding {
CYIdentifier *identifier_;
- CYExpression *initialiser_;
+ CYExpression *initializer_;
- CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser = NULL) :
+ CYBinding(CYIdentifier *identifier, CYExpression *initializer = NULL) :
identifier_(identifier),
- initialiser_(initialiser)
+ initializer_(initializer)
{
}
CYForInInitializer
{
bool constant_;
- CYDeclaration *declaration_;
+ CYBinding *binding_;
- CYForLexical(bool constant, CYDeclaration *declaration) :
+ CYForLexical(bool constant, CYBinding *binding) :
constant_(constant),
- declaration_(declaration)
+ binding_(binding)
{
}
struct CYForVariable :
CYForInInitializer
{
- CYDeclaration *declaration_;
+ CYBinding *binding_;
- CYForVariable(CYDeclaration *declaration) :
- declaration_(declaration)
+ CYForVariable(CYBinding *binding) :
+ binding_(binding)
{
}
virtual void Output(CYOutput &out, CYFlags flags) const;
};
-struct CYDeclarations :
- CYNext<CYDeclarations>,
+struct CYBindings :
+ CYNext<CYBindings>,
CYThing
{
- CYDeclaration *declaration_;
+ CYBinding *binding_;
- CYDeclarations(CYDeclaration *declaration, CYDeclarations *next = NULL) :
- CYNext<CYDeclarations>(next),
- declaration_(declaration)
+ CYBindings(CYBinding *binding, CYBindings *next = NULL) :
+ CYNext<CYBindings>(next),
+ binding_(binding)
{
}
struct CYVar :
CYForInitializer
{
- CYDeclarations *declarations_;
+ CYBindings *bindings_;
- CYVar(CYDeclarations *declarations) :
- declarations_(declarations)
+ CYVar(CYBindings *bindings) :
+ bindings_(bindings)
{
}
virtual void Output(CYOutput &out, CYFlags flags) const;
};
-struct CYLet :
+struct CYLexical :
CYForInitializer
{
bool constant_;
- CYDeclarations *declarations_;
+ CYBindings *bindings_;
- CYLet(bool constant, CYDeclarations *declarations) :
+ CYLexical(bool constant, CYBindings *bindings) :
constant_(constant),
- declarations_(declarations)
+ bindings_(bindings)
{
}
};
struct CYBuilder {
- CYList<CYDeclarations> declarations_;
+ CYList<CYBindings> bindings_;
CYList<CYStatement> statements_;
operator bool() const {
struct CYFor :
CYStatement
{
- CYForInitializer *initialiser_;
+ CYForInitializer *initializer_;
CYExpression *test_;
CYExpression *increment_;
CYStatement *code_;
- CYFor(CYForInitializer *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
- initialiser_(initialiser),
+ CYFor(CYForInitializer *initializer, CYExpression *test, CYExpression *increment, CYStatement *code) :
+ initializer_(initializer),
test_(test),
increment_(increment),
code_(code)
struct CYForIn :
CYStatement
{
- CYForInInitializer *initialiser_;
- CYExpression *set_;
+ CYForInInitializer *initializer_;
+ CYExpression *iterable_;
CYStatement *code_;
- CYForIn(CYForInInitializer *initialiser, CYExpression *set, CYStatement *code) :
- initialiser_(initialiser),
- set_(set),
+ CYForIn(CYForInInitializer *initializer, CYExpression *iterable, CYStatement *code) :
+ initializer_(initializer),
+ iterable_(iterable),
code_(code)
{
}
struct CYForInitialized :
CYStatement
{
- CYDeclaration *declaration_;
- CYExpression *set_;
+ CYBinding *binding_;
+ CYExpression *iterable_;
CYStatement *code_;
- CYForInitialized(CYDeclaration *declaration, CYExpression *set, CYStatement *code) :
- declaration_(declaration),
- set_(set),
+ CYForInitialized(CYBinding *binding, CYExpression *iterable, CYStatement *code) :
+ binding_(binding),
+ iterable_(iterable),
code_(code)
{
}
struct CYForOf :
CYStatement
{
- CYForInInitializer *initialiser_;
- CYExpression *set_;
+ CYForInInitializer *initializer_;
+ CYExpression *iterable_;
CYStatement *code_;
- CYForOf(CYForInInitializer *initialiser, CYExpression *set, CYStatement *code) :
- initialiser_(initialiser),
- set_(set),
+ CYForOf(CYForInInitializer *initializer, CYExpression *iterable, CYStatement *code) :
+ initializer_(initializer),
+ iterable_(iterable),
code_(code)
{
}
virtual void Output(CYOutput &out, CYFlags flags) const;
};
+struct CYResolveMember :
+ CYMember
+{
+ CYResolveMember(CYExpression *object, CYExpression *property) :
+ CYMember(object, property)
+ {
+ }
+
+ CYPrecedence(1)
+
+ virtual CYTarget *Replace(CYContext &context);
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
namespace cy {
namespace Syntax {
virtual void Output(CYOutput &out) const;
};
-struct CYTypeVoid :
+enum CYTypeSigning {
+ CYTypeNeutral,
+ CYTypeSigned,
+ CYTypeUnsigned,
+};
+
+struct CYTypeCharacter :
CYTypeSpecifier
{
- CYTypeVoid() {
+ CYTypeSigning signing_;
+
+ CYTypeCharacter(CYTypeSigning signing) :
+ signing_(signing)
+ {
}
virtual CYTarget *Replace(CYContext &context);
virtual void Output(CYOutput &out) const;
};
-struct CYTypeVariable :
+struct CYTypeIntegral :
CYTypeSpecifier
{
- CYIdentifier *name_;
+ CYTypeSigning signing_;
+ int length_;
- CYTypeVariable(CYIdentifier *name) :
- name_(name)
+ CYTypeIntegral(CYTypeSigning signing, int length = 1) :
+ signing_(signing),
+ length_(length)
{
}
- CYTypeVariable(const char *name) :
- name_(new($pool) CYIdentifier(name))
- {
+ CYTypeIntegral *Long() {
+ if (length_ != 1 && length_ != 2)
+ return NULL;
+ ++length_;
+ return this;
}
- virtual CYTarget *Replace(CYContext &context);
- virtual void Output(CYOutput &out) const;
-};
+ CYTypeIntegral *Short() {
+ if (length_ != 1)
+ return NULL;
+ --length_;
+ return this;
+ }
-struct CYTypeUnsigned :
- CYTypeSpecifier
-{
- CYTypeSpecifier *specifier_;
+ CYTypeIntegral *Signed() {
+ if (signing_ != CYTypeNeutral)
+ return NULL;
+ signing_ = CYTypeSigned;
+ return this;
+ }
- CYTypeUnsigned(CYTypeSpecifier *specifier) :
- specifier_(specifier)
- {
+ CYTypeIntegral *Unsigned() {
+ if (signing_ != CYTypeNeutral)
+ return NULL;
+ signing_ = CYTypeUnsigned;
+ return this;
}
virtual CYTarget *Replace(CYContext &context);
virtual void Output(CYOutput &out) const;
};
-struct CYTypeSigned :
+struct CYTypeVoid :
CYTypeSpecifier
{
- CYTypeSpecifier *specifier_;
-
- CYTypeSigned(CYTypeSpecifier *specifier) :
- specifier_(specifier)
- {
+ CYTypeVoid() {
}
virtual CYTarget *Replace(CYContext &context);
virtual void Output(CYOutput &out) const;
};
-struct CYTypeLong :
+struct CYTypeReference :
CYTypeSpecifier
{
- CYTypeSpecifier *specifier_;
+ CYIdentifier *name_;
- CYTypeLong(CYTypeSpecifier *specifier) :
- specifier_(specifier)
+ CYTypeReference(CYIdentifier *name) :
+ name_(name)
{
}
virtual void Output(CYOutput &out) const;
};
-struct CYTypeShort :
+struct CYTypeVariable :
CYTypeSpecifier
{
- CYTypeSpecifier *specifier_;
+ CYIdentifier *name_;
- CYTypeShort(CYTypeSpecifier *specifier) :
- specifier_(specifier)
+ CYTypeVariable(CYIdentifier *name) :
+ name_(name)
+ {
+ }
+
+ CYTypeVariable(const char *name) :
+ name_(new($pool) CYIdentifier(name))
{
}
virtual void Output(CYOutput &out) const;
};
+struct CYTypedFormal {
+ bool variadic_;
+ CYTypedParameter *parameters_;
+
+ CYTypedFormal(bool variadic) :
+ variadic_(variadic),
+ parameters_(NULL)
+ {
+ }
+};
+
struct CYLambda :
CYTarget
{
virtual void Output(CYOutput &out, CYFlags flags) const;
};
+struct CYImportSpecifier :
+ CYNext<CYImportSpecifier>
+{
+ CYWord *name_;
+ CYIdentifier *binding_;
+
+ CYImportSpecifier(CYWord *name, CYIdentifier *binding) :
+ name_(name),
+ binding_(binding)
+ {
+ }
+
+ CYStatement *Replace(CYContext &context, CYIdentifier *module);
+};
+
+struct CYImportDeclaration :
+ CYStatement
+{
+ CYImportSpecifier *specifiers_;
+ CYString *module_;
+
+ CYImportDeclaration(CYImportSpecifier *specifiers, CYString *module) :
+ specifiers_(specifiers),
+ module_(module)
+ {
+ }
+
+ CYCompact(None)
+
+ virtual CYStatement *Replace(CYContext &context);
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
struct CYExternal :
CYStatement
{
virtual void Output(CYOutput &out, CYFlags flags) const;
};
+struct CYTypeExpression :
+ CYTarget
+{
+ CYTypedIdentifier *typed_;
+
+ CYTypeExpression(CYTypedIdentifier *typed) :
+ typed_(typed)
+ {
+ }
+
+ CYPrecedence(0)
+
+ virtual CYTarget *Replace(CYContext &context);
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
struct CYTypeDefinition :
CYStatement
{
struct CYTypeFunctionWith :
CYTypeModifier
{
+ bool variadic_;
CYTypedParameter *parameters_;
- CYTypeFunctionWith(CYTypedParameter *parameters, CYTypeModifier *next = NULL) :
+ CYTypeFunctionWith(bool variadic, CYTypedParameter *parameters, CYTypeModifier *next = NULL) :
CYTypeModifier(next),
+ variadic_(variadic),
parameters_(parameters)
{
}
virtual CYTypeFunctionWith *Function() { return this; }
};
+struct CYTypeStructField :
+ CYNext<CYTypeStructField>
+{
+ CYTypedIdentifier *typed_;
+
+ CYTypeStructField(CYTypedIdentifier *typed, CYTypeStructField *next = NULL) :
+ CYNext<CYTypeStructField>(next),
+ typed_(typed)
+ {
+ }
+};
+
+struct CYStructTail :
+ CYThing
+{
+ CYTypeStructField *fields_;
+
+ CYStructTail(CYTypeStructField *fields) :
+ fields_(fields)
+ {
+ }
+
+ CYTarget *Replace(CYContext &context);
+ virtual void Output(CYOutput &out) const;
+};
+
+struct CYTypeStruct :
+ CYTypeSpecifier
+{
+ CYIdentifier *name_;
+ CYStructTail *tail_;
+
+ CYTypeStruct(CYIdentifier *name, CYStructTail *tail) :
+ name_(name),
+ tail_(tail)
+ {
+ }
+
+ virtual CYTarget *Replace(CYContext &context);
+ virtual void Output(CYOutput &out) const;
+};
+
+struct CYStructDefinition :
+ CYStatement
+{
+ CYIdentifier *name_;
+ CYStructTail *tail_;
+
+ CYStructDefinition(CYIdentifier *name, CYStructTail *tail) :
+ name_(name),
+ tail_(tail)
+ {
+ }
+
+ CYCompact(None)
+
+ virtual CYStatement *Replace(CYContext &context);
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
namespace cy {
namespace Syntax {