CYClassName,
CYThing
{
- virtual unsigned Precedence() const = 0;
+ virtual int Precedence() const = 0;
virtual bool RightHand() const {
return true;
virtual void Output(CYOutput &out) const;
virtual void Output(CYOutput &out, CYFlags flags) const = 0;
- void Output(CYOutput &out, unsigned precedence, CYFlags flags) const;
+ void Output(CYOutput &out, int precedence, CYFlags flags) const;
virtual CYExpression *ClassName(CYContext &context, bool object);
virtual void ClassName(CYOutput &out, bool object) const;
}
#define CYPrecedence(value) \
- static const unsigned Precedence_ = value; \
- virtual unsigned Precedence() const { \
+ static const int Precedence_ = value; \
+ virtual int Precedence() const { \
return Precedence_; \
}
{
}
+ CYComprehension *Modify(CYComprehension *next) {
+ next_ = next;
+ return this;
+ }
+
virtual const char *Name() const = 0;
virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
{
CYExpression *test_;
- CYIfComprehension(CYExpression *test) :
+ CYIfComprehension(CYExpression *test, CYComprehension *next = NULL) :
+ CYComprehension(next),
test_(test)
{
}
{
}
- virtual unsigned Precedence() const {
+ virtual int Precedence() const {
return arguments_ == NULL ? 2 : 1;
}
virtual void Output(CYOutput &out) const;
};
+struct CYTypeSpecifier :
+ CYThing
+{
+ virtual CYExpression *Replace(CYContext &context) = 0;
+};
+
+struct CYTypeError :
+ CYTypeSpecifier
+{
+ CYTypeError() {
+ }
+
+ virtual CYExpression *Replace(CYContext &context);
+ virtual void Output(CYOutput &out) const;
+};
+
+struct CYTypeVoid :
+ CYTypeSpecifier
+{
+ CYTypeVoid() {
+ }
+
+ virtual CYExpression *Replace(CYContext &context);
+ virtual void Output(CYOutput &out) const;
+};
+
+struct CYTypeVariable :
+ CYTypeSpecifier
+{
+ CYIdentifier *name_;
+
+ CYTypeVariable(CYIdentifier *name) :
+ name_(name)
+ {
+ }
+
+ CYTypeVariable(const char *name) :
+ name_(new($pool) CYIdentifier(name))
+ {
+ }
+
+ virtual CYExpression *Replace(CYContext &context);
+ virtual void Output(CYOutput &out) const;
+};
+
+struct CYTypeUnsigned :
+ CYTypeSpecifier
+{
+ CYTypeSpecifier *specifier_;
+
+ CYTypeUnsigned(CYTypeSpecifier *specifier) :
+ specifier_(specifier)
+ {
+ }
+
+ virtual CYExpression *Replace(CYContext &context);
+ virtual void Output(CYOutput &out) const;
+};
+
+struct CYTypeSigned :
+ CYTypeSpecifier
+{
+ CYTypeSpecifier *specifier_;
+
+ CYTypeSigned(CYTypeSpecifier *specifier) :
+ specifier_(specifier)
+ {
+ }
+
+ virtual CYExpression *Replace(CYContext &context);
+ virtual void Output(CYOutput &out) const;
+};
+
+struct CYTypeLong :
+ CYTypeSpecifier
+{
+ CYTypeSpecifier *specifier_;
+
+ CYTypeLong(CYTypeSpecifier *specifier) :
+ specifier_(specifier)
+ {
+ }
+
+ virtual CYExpression *Replace(CYContext &context);
+ virtual void Output(CYOutput &out) const;
+};
+
+struct CYTypeShort :
+ CYTypeSpecifier
+{
+ CYTypeSpecifier *specifier_;
+
+ CYTypeShort(CYTypeSpecifier *specifier) :
+ specifier_(specifier)
+ {
+ }
+
+ virtual CYExpression *Replace(CYContext &context);
+ virtual void Output(CYOutput &out) const;
+};
+
struct CYTypeModifier :
CYNext<CYTypeModifier>
{
{
}
- virtual CYExpression *Replace(CYContext &context) = 0;
+ virtual int Precedence() const = 0;
+
+ virtual CYExpression *Replace_(CYContext &context, CYExpression *type) = 0;
+ CYExpression *Replace(CYContext &context, CYExpression *type);
+
+ virtual void Output(CYOutput &out, CYIdentifier *identifier) const = 0;
+ void Output(CYOutput &out, int precedence, CYIdentifier *identifier) const;
};
struct CYTypeArrayOf :
{
}
- CYPrecedence(2)
+ CYPrecedence(1)
- virtual CYExpression *Replace(CYContext &context);
+ virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
+ virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
};
struct CYTypeConstant :
{
}
- CYPrecedence(3)
+ CYPrecedence(0)
- virtual CYExpression *Replace(CYContext &context);
+ virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
+ virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
};
struct CYTypePointerTo :
{
}
- CYPrecedence(3)
+ CYPrecedence(0)
- virtual CYExpression *Replace(CYContext &context);
+ virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
+ virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
};
-struct CYTypeVariable :
+struct CYTypeVolatile :
CYTypeModifier
{
- CYExpression *expression_;
-
- CYTypeVariable(CYExpression *expression) :
- CYTypeModifier(NULL),
- expression_(expression)
+ CYTypeVolatile(CYTypeModifier *next = NULL) :
+ CYTypeModifier(next)
{
}
- CYPrecedence(1)
+ CYPrecedence(0)
- virtual CYExpression *Replace(CYContext &context);
+ virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
+ virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
};
struct CYTypedIdentifier :
CYThing
{
CYIdentifier *identifier_;
- CYTypeModifier *type_;
+ CYTypeSpecifier *specifier_;
+ CYTypeModifier *modifier_;
- CYTypedIdentifier(CYIdentifier *identifier) :
+ CYTypedIdentifier(CYIdentifier *identifier = NULL) :
identifier_(identifier),
- type_(NULL)
+ specifier_(NULL),
+ modifier_(NULL)
+ {
+ }
+
+ CYTypedIdentifier(CYTypeSpecifier *specifier, CYTypeModifier *modifier = NULL) :
+ identifier_(NULL),
+ specifier_(specifier),
+ modifier_(modifier)
{
}
+ inline CYTypedIdentifier *Modify(CYTypeModifier *modifier) {
+ CYSetLast(modifier_) = modifier;
+ return this;
+ }
+
+ virtual CYExpression *Replace(CYContext &context);
virtual void Output(CYOutput &out) const;
};
+struct CYEncodedType :
+ CYExpression
+{
+ CYTypedIdentifier *typed_;
+
+ CYEncodedType(CYTypedIdentifier *typed) :
+ typed_(typed)
+ {
+ }
+
+ CYPrecedence(1)
+
+ virtual CYExpression *Replace(CYContext &context);
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
struct CYTypedParameter :
- CYNext<CYTypedParameter>
+ CYNext<CYTypedParameter>,
+ CYThing
{
CYTypedIdentifier *typed_;
CYArgument *Argument(CYContext &context);
CYFunctionParameter *Parameters(CYContext &context);
CYExpression *TypeSignature(CYContext &context, CYExpression *prefix);
+
+ virtual void Output(CYOutput &out) const;
};
struct CYLambda :
CYExpression
{
- CYTypeModifier *type_;
+ CYTypedIdentifier *typed_;
CYTypedParameter *parameters_;
CYStatement *statements_;
- CYLambda(CYTypeModifier *type, CYTypedParameter *parameters, CYStatement *statements) :
- type_(type),
+ CYLambda(CYTypedIdentifier *typed, CYTypedParameter *parameters, CYStatement *statements) :
+ typed_(typed),
parameters_(parameters),
statements_(statements)
{
virtual void Output(CYOutput &out, CYFlags flags) const;
};
+struct CYTypeBlockWith :
+ CYTypeModifier
+{
+ CYTypedParameter *parameters_;
+
+ CYTypeBlockWith(CYTypedParameter *parameters, CYTypeModifier *next = NULL) :
+ CYTypeModifier(next),
+ parameters_(parameters)
+ {
+ }
+
+ CYPrecedence(0)
+
+ virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
+ virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
+};
+
struct CYTypeFunctionWith :
CYTypeModifier
{
{
}
- CYPrecedence(2)
+ CYPrecedence(1)
- virtual CYExpression *Replace(CYContext &context);
+ virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
+ virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
};
namespace cy {
CYPrefix_(false, "~", BitwiseNot)
CYPrefix_(false, "!", LogicalNot)
-CYInfix_(false, 5, "*", Multiply)
+CYInfix_(false, 5, "*", Multiply, CYReplace)
CYInfix_(false, 5, "/", Divide)
CYInfix_(false, 5, "%", Modulus)
CYInfix_(false, 6, "+", Add, CYReplace)