1.1 --- a/src/AST.h Sun Aug 12 20:51:31 2012 -0700
1.2 +++ b/src/AST.h Sat Sep 01 16:36:20 2012 -0700
1.3 @@ -47,6 +47,7 @@
1.4 _(WhileStatement) \
1.5 _(BreakStatement) \
1.6 _(ContinueStatement) \
1.7 + _(FunctionTypeStatement) \
1.8 _(IncDecExpression) \
1.9 _(UnaryExpression) \
1.10 _(TernaryExpression) \
1.11 @@ -743,25 +744,72 @@
1.12
1.13 typedef PoolList<Parameter *> ParameterList;
1.14
1.15 +class FunctionSignature
1.16 +{
1.17 + public:
1.18 + FunctionSignature(BoundName *returnType, ParameterList *parameters)
1.19 + : returnType_(returnType),
1.20 + parameters_(parameters)
1.21 + {
1.22 + }
1.23 +
1.24 + BoundName *returnType() const {
1.25 + return returnType_;
1.26 + }
1.27 + ParameterList *parameters() const {
1.28 + return parameters_;
1.29 + }
1.30 +
1.31 + private:
1.32 + BoundName *returnType_;
1.33 + ParameterList *parameters_;
1.34 +};
1.35 +
1.36 +class FunctionTypeStatement : public Statement
1.37 +{
1.38 + public:
1.39 + FunctionTypeStatement(const SourcePosition &pos, NamedType *type, const FunctionSignature &signature)
1.40 + : Statement(pos),
1.41 + type_(type),
1.42 + signature_(signature)
1.43 + {
1.44 + }
1.45 +
1.46 + Kind kind() const {
1.47 + return kFunctionTypeStatement;
1.48 + }
1.49 + NamedType *decl() const {
1.50 + return type_;
1.51 + }
1.52 + const FunctionSignature &signature() const {
1.53 + return signature_;
1.54 + }
1.55 + void accept(AstVisitor *visitor) {
1.56 + visitor->visit(this);
1.57 + }
1.58 +
1.59 + private:
1.60 + NamedType *type_;
1.61 + FunctionSignature signature_;
1.62 +};
1.63 +
1.64 class FunctionStatement : public Statement
1.65 {
1.66 Scope *scope_;
1.67 NamedFunction *fun_;
1.68 Statement *body_;
1.69 - ParameterList *parameters_;
1.70 + FunctionSignature signature_;
1.71 bool explicitReturn_;
1.72 - BoundName *returnType_;
1.73
1.74 public:
1.75 FunctionStatement(const SourcePosition &pos, Scope *scope, NamedFunction *fun, Statement *body,
1.76 - ParameterList *parameters, BoundName *returnType, bool explicitReturn)
1.77 + const FunctionSignature &signature, bool explicitReturn)
1.78 : Statement(pos),
1.79 scope_(scope),
1.80 fun_(fun),
1.81 body_(body),
1.82 - parameters_(parameters),
1.83 - explicitReturn_(explicitReturn),
1.84 - returnType_(returnType)
1.85 + signature_(signature),
1.86 + explicitReturn_(explicitReturn)
1.87 {
1.88 }
1.89
1.90 @@ -777,8 +825,8 @@
1.91 Statement *body() const {
1.92 return body_;
1.93 }
1.94 - ParameterList *parameters() const {
1.95 - return parameters_;
1.96 + const FunctionSignature &signature() {
1.97 + return signature_;
1.98 }
1.99 void accept(AstVisitor *visitor) {
1.100 visitor->visit(this);
1.101 @@ -786,9 +834,6 @@
1.102 bool hasExplicitReturn() const {
1.103 return explicitReturn_;
1.104 }
1.105 - BoundName *returnType() const {
1.106 - return returnType_;
1.107 - }
1.108 };
1.109
1.110 class IfStatement : public Statement