src/AST.h
author David Anderson <dvander@alliedmods.net>
Sat Aug 04 20:12:20 2012 -0700 (2012-08-04)
changeset 148 c0740249963c
parent 146 dc7d3b7a918c
child 168 4d0fff61d65e
permissions -rw-r--r--
All but interpreter support for getting and setting struct fields.
     1 /* vim: set ts=4 sw=4 tw=99 et:
     2  *
     3  * Copyright (C) 2012 David Anderson
     4  *
     5  * This file is part of SourcePawn.
     6  *
     7  * SourcePawn is free software: you can redistribute it and/or modify it under
     8  * the terms of the GNU General Public License as published by the Free
     9  * Software Foundation, either version 3 of the License, or (at your option)
    10  * any later version.
    11  * 
    12  * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
    13  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    15  *
    16  * You should have received a copy of the GNU General Public License along with
    17  * SourcePawn. If not, see http://www.gnu.org/licenses/.
    18  */
    19 #ifndef _include_jitcraft_ast_h_
    20 #define _include_jitcraft_ast_h_
    21 
    22 #include "PoolAllocator.h"
    23 #include "Token.h"
    24 #include "NameBinding.h"
    25 #include "Vector.h"
    26 
    27 namespace ke {
    28 
    29 #define ASTKINDS(_)             \
    30     _(VariableDeclaration)      \
    31     _(ForStatement)             \
    32     _(ReturnStatement)          \
    33     _(IntegerLiteral)           \
    34     _(FloatLiteral)             \
    35     _(StringLiteral)            \
    36     _(BinaryExpression)         \
    37     _(BlockStatement)           \
    38     _(Assignment)               \
    39     _(NameProxy)                \
    40     _(ExpressionStatement)      \
    41     _(FunctionStatement)        \
    42     _(CallExpression)           \
    43     _(IfStatement)              \
    44     _(IndexExpression)          \
    45     _(FieldExpression)          \
    46     _(EnumStatement)            \
    47     _(WhileStatement)           \
    48     _(BreakStatement)           \
    49     _(ContinueStatement)        \
    50     _(IncDecExpression)         \
    51     _(UnaryExpression)          \
    52     _(TernaryExpression)        \
    53     _(BooleanLiteral)           \
    54     _(StructureStatement)
    55 
    56 // Forward declarations.
    57 #define _(name) class name;
    58 ASTKINDS(_)
    59 #undef _
    60 
    61 class AstVisitor;
    62 
    63 // Interface for AST nodes.
    64 class AstNode : public PoolObject
    65 {
    66     SourcePosition pos_;
    67 
    68   public:
    69     enum Kind {
    70 #       define _(name) k##name,
    71         ASTKINDS(_)
    72 #       undef _
    73         AstKind_Invalid
    74     };
    75 
    76     AstNode(const SourcePosition &pos)
    77       : pos_(pos)
    78     {
    79     }
    80     
    81     virtual Kind kind() const = 0;
    82 
    83 #define _(name)     bool is##name() { return kind() == k##name; }                   \
    84                     name *to##name() { assert(is##name()); return (name *)this; }
    85     ASTKINDS(_)
    86 #undef _
    87 
    88     virtual void accept(AstVisitor *visitor) = 0;
    89 
    90     const SourcePosition &pos() const {
    91         return pos_;
    92     }
    93 };
    94 
    95 class AstVisitor
    96 {
    97   public:
    98 #define _(name) virtual void visit(name *node) = 0;
    99     ASTKINDS(_)
   100 #undef _
   101 };
   102 
   103 class Statement : public AstNode
   104 {
   105   public:
   106     Statement(const SourcePosition &pos)
   107       : AstNode(pos)
   108     {
   109     }
   110 };
   111 
   112 class Expression : public AstNode
   113 {
   114     ScopedRoot<Type> type_;
   115 
   116   public:
   117     Expression(const SourcePosition &pos)
   118       : AstNode(pos),
   119         type_(NULL)
   120     {
   121     }
   122 
   123     void setType(Type *type) {
   124         type_ = type;
   125     }
   126     Type *type() const {
   127         return type_;
   128     }
   129 };
   130 
   131 typedef PoolList<Statement *> StatementList;
   132 typedef PoolList<Expression *> ExpressionList;
   133 
   134 class VariableDeclaration : public Statement
   135 {
   136     Variable *variable_;
   137     Expression *initialization_;
   138     ExpressionList *postDimensions_;
   139     BoundName *type_;
   140     TokenKind declarator_;
   141 
   142   public:
   143     VariableDeclaration(const SourcePosition &pos, TokenKind declarator, Variable *var,
   144                         BoundName *type, ExpressionList *postDimensions,
   145                         Expression *initialization)
   146       : Statement(pos),
   147         variable_(var),
   148         initialization_(initialization),
   149         postDimensions_(postDimensions),
   150         type_(type),
   151         declarator_(declarator)
   152     {
   153     }
   154 
   155     BoundName *type() const {
   156         return type_;
   157     }
   158     Kind kind() const {
   159         return kVariableDeclaration;
   160     }
   161     Variable *variable() const {
   162         return variable_;
   163     }
   164     Expression *initialization() const {
   165         return initialization_;
   166     }
   167     ExpressionList *postDimensions() const {
   168         return postDimensions_;
   169     }
   170     void accept(AstVisitor *visitor) {
   171         visitor->visit(this);
   172     }
   173     TokenKind declarator() const {
   174         return declarator_;
   175     }
   176 };
   177 
   178 class Parameter : public PoolObject
   179 {
   180     Variable *variable_;
   181     BoundName *type_;
   182     bool reference_;
   183     bool const_;
   184     ExpressionList *dimensions_;
   185     Expression *initializer_;
   186 
   187   public:
   188     Parameter(Variable *var, BoundName *type, bool reference, bool isConst,
   189               ExpressionList *dimensions, Expression *initializer)
   190       : variable_(var),
   191         type_(type),
   192         reference_(reference),
   193         const_(isConst),
   194         dimensions_(dimensions),
   195         initializer_(initializer)
   196     {
   197     }
   198 
   199     BoundName *type() const {
   200         return type_;
   201     }
   202     Variable *variable() const {
   203         return variable_;
   204     }
   205     bool reference() const {
   206         return reference_;
   207     }
   208     ExpressionList *dimensions() const {
   209         return dimensions_;
   210     }
   211     bool isConst() const {
   212         return const_;
   213     }
   214     Expression *initializer() const {
   215         return initializer_;
   216     }
   217 };
   218 
   219 class NameProxy : public Expression
   220 {
   221     ScopedRoot<String> name_;
   222     BoundName *binding_;
   223 
   224   public:
   225     NameProxy(const SourcePosition &pos, Handle<String> name, BoundName *binding)
   226       : Expression(pos),
   227         name_(name),
   228         binding_(binding)
   229     {
   230     }
   231 
   232     Kind kind() const {
   233         return kNameProxy;
   234     }
   235     String *name() const {
   236         return name_;
   237     }
   238     void accept(AstVisitor *visitor) {
   239         visitor->visit(this);
   240     }
   241     BoundName *binding() const {
   242         return binding_;
   243     }
   244     void bind(BoundName *name) {
   245         assert(!binding());
   246         binding_ = name;
   247     }
   248 };
   249 
   250 class BooleanLiteral : public Expression
   251 {
   252     TokenKind token_;
   253 
   254   public:
   255     BooleanLiteral(const SourcePosition &pos, TokenKind token)
   256       : Expression(pos),
   257         token_(token)
   258     {
   259     }
   260 
   261     Kind kind() const {
   262         return kBooleanLiteral;
   263     }
   264     TokenKind token() const {
   265         return token_;
   266     }
   267     void accept(AstVisitor *visitor) {
   268         visitor->visit(this);
   269     }
   270 };
   271 
   272 class IntegerLiteral : public Expression
   273 {
   274     int value_;
   275 
   276   public:
   277     IntegerLiteral(const SourcePosition &pos, int value)
   278       : Expression(pos),
   279         value_(value)
   280     {
   281     }
   282 
   283     Kind kind() const {
   284         return kIntegerLiteral;
   285     }
   286     int value() const {
   287         return value_;
   288     }
   289     void accept(AstVisitor *visitor) {
   290         visitor->visit(this);
   291     }
   292 };
   293 
   294 class FloatLiteral : public Expression
   295 {
   296     double value_;
   297 
   298   public:
   299     FloatLiteral(const SourcePosition &pos, double value)
   300       : Expression(pos),
   301         value_(value)
   302     {
   303     }
   304 
   305     Kind kind() const {
   306         return kFloatLiteral;
   307     }
   308     double value() const {
   309         return value_;
   310     }
   311     void accept(AstVisitor *visitor) {
   312         visitor->visit(this);
   313     }
   314 };
   315 
   316 class StringLiteral : public Expression
   317 {
   318     ScopedRoot<ByteArray> string_;
   319 
   320   public:
   321     StringLiteral(const SourcePosition &pos, ByteArray *array)
   322       : Expression(pos),
   323         string_(array)
   324     {
   325     }
   326 
   327     Kind kind() const {
   328         return kStringLiteral;
   329     }
   330     ByteArray *string() const {
   331         return string_;
   332     }
   333     void accept(AstVisitor *visitor) {
   334         visitor->visit(this);
   335     }
   336 };
   337 
   338 class UnaryExpression : public Expression
   339 {
   340     Expression *expression_;
   341     TokenKind token_;
   342     BoundName *type_;
   343 
   344   public:
   345     UnaryExpression(const SourcePosition &pos, TokenKind token, Expression *expr)
   346       : Expression(pos),
   347         expression_(expr),
   348         token_(token)
   349     {
   350     }
   351 
   352     UnaryExpression(const SourcePosition &pos, TokenKind token, Expression *expr,
   353                     BoundName *type)
   354       : Expression(pos),
   355         expression_(expr),
   356         token_(token),
   357         type_(type)
   358     {
   359     }
   360 
   361     Kind kind() const {
   362         return kUnaryExpression;
   363     }
   364     Expression *expression() const {
   365         return expression_;
   366     }
   367     TokenKind token() const {
   368         return token_;
   369     }
   370     BoundName *type() const {
   371         return type_;
   372     }
   373     void accept(AstVisitor *visitor) {
   374         visitor->visit(this);
   375     }
   376 };
   377 
   378 class BinaryExpression : public Expression
   379 {
   380     Expression *left_;
   381     Expression *right_;
   382     TokenKind token_;
   383 
   384   public:
   385     BinaryExpression(const SourcePosition &pos, TokenKind token, Expression *left, Expression *right)
   386       : Expression(pos),
   387         left_(left),
   388         right_(right),
   389         token_(token)
   390     {
   391     }
   392 
   393     Kind kind() const {
   394         return kBinaryExpression;
   395     }
   396     Expression *left() const {
   397         return left_;
   398     }
   399     Expression *right() const {
   400         return right_;
   401     }
   402     TokenKind token() const {
   403         return token_;
   404     }
   405     void accept(AstVisitor *visitor) {
   406         visitor->visit(this);
   407     }
   408 };
   409 
   410 class TernaryExpression : public Expression
   411 {
   412     Expression *condition_;
   413     Expression *left_;
   414     Expression *right_;
   415 
   416   public:
   417     TernaryExpression(const SourcePosition &pos, Expression *condition, Expression *left, Expression *right)
   418       : Expression(pos),
   419         condition_(condition),
   420         left_(left),
   421         right_(right)
   422     {
   423     }
   424 
   425     Kind kind() const {
   426         return kTernaryExpression;
   427     }
   428     Expression *condition() const {
   429         return condition_;
   430     }
   431     Expression *left() const {
   432         return left_;
   433     }
   434     Expression *right() const {
   435         return right_;
   436     }
   437     void accept(AstVisitor *visitor) {
   438         visitor->visit(this);
   439     }
   440 };
   441 
   442 class IndexExpression : public Expression
   443 {
   444     Expression *left_;
   445     Expression *right_;
   446 
   447   public:
   448     IndexExpression(const SourcePosition &pos, Expression *left, Expression *right)
   449       : Expression(pos),
   450         left_(left),
   451         right_(right)
   452     {
   453     }
   454 
   455     Kind kind() const {
   456         return kIndexExpression;
   457     }
   458     Expression *left() const {
   459         return left_;
   460     }
   461     Expression *right() const {
   462         return right_;
   463     }
   464     void accept(AstVisitor *visitor) {
   465         visitor->visit(this);
   466     }
   467 };
   468 
   469 class FieldExpression : public Expression
   470 {
   471     Expression *left_;
   472     ScopedRoot<String> field_;
   473     unsigned fieldIndex_;
   474 
   475   public:
   476     FieldExpression(const SourcePosition &pos, Expression *left, Handle<String> field)
   477       : Expression(pos),
   478         left_(left),
   479         field_(field),
   480         fieldIndex_(unsigned(-1))
   481     {
   482     }
   483 
   484     Kind kind() const {
   485         return kFieldExpression;
   486     }
   487     Expression *left() const {
   488         return left_;
   489     }
   490     String *field() const {
   491         return field_;
   492     }
   493     void setFieldIndex(unsigned index) {
   494         assert(fieldIndex_ == unsigned(-1));
   495         fieldIndex_ = index;
   496     }
   497     unsigned fieldIndex() const {
   498         assert(fieldIndex_ != unsigned(-1));
   499         return fieldIndex_;
   500     }
   501     void accept(AstVisitor *visitor) {
   502         visitor->visit(this);
   503     }
   504 };
   505 
   506 class CallExpression : public Expression
   507 {
   508     Expression *callee_;
   509     ExpressionList *arguments_;
   510 
   511   public:
   512     CallExpression(const SourcePosition &pos, Expression *callee, ExpressionList *arguments)
   513       : Expression(pos),
   514         callee_(callee),
   515         arguments_(arguments)
   516     {
   517     }
   518 
   519     Kind kind() const {
   520         return kCallExpression;
   521     }
   522     Expression *callee() const {
   523         return callee_;
   524     }
   525     ExpressionList *arguments() const {
   526         return arguments_;
   527     }
   528     void accept(AstVisitor *visitor) {
   529         visitor->visit(this);
   530     }
   531 };
   532 
   533 class ForStatement : public Statement
   534 {
   535     Scope *scope_;
   536     Statement *initialization_;
   537     Expression *condition_;
   538     Statement *update_;
   539     Statement *body_;
   540 
   541   public:
   542     ForStatement(const SourcePosition &pos, Scope *scope, Statement *initialization,
   543                  Expression *condition, Statement *update, Statement *body)
   544       : Statement(pos),
   545         scope_(scope),
   546         initialization_(initialization),
   547         condition_(condition),
   548         update_(update),
   549         body_(body)
   550     {
   551     }
   552 
   553     Kind kind() const {
   554         return kForStatement;
   555     }
   556     Statement *initialization() const {
   557         return initialization_;
   558     }
   559     Scope *scope() const {
   560         return scope_;
   561     }
   562     Expression *condition() const {
   563         return condition_;
   564     }
   565     Statement *update() const {
   566         return update_;
   567     }
   568     Statement *body() const {
   569         return body_;
   570     }
   571     void accept(AstVisitor *visitor) {
   572         visitor->visit(this);
   573     }
   574 };
   575 
   576 class WhileStatement : public Statement
   577 {
   578     TokenKind token_;
   579     Expression *condition_;
   580     Statement *body_;
   581 
   582   public:
   583     WhileStatement(const SourcePosition &pos, TokenKind kind, Expression *condition, Statement *body)
   584       : Statement(pos),
   585         token_(kind),
   586         condition_(condition),
   587         body_(body)
   588     {
   589     }
   590     
   591     Kind kind() const {
   592         return kWhileStatement;
   593     }
   594     TokenKind token() const {
   595         return token_;
   596     }
   597     Expression *condition() const {
   598         return condition_;
   599     }
   600     Statement *body() const {
   601         return body_;
   602     }
   603     void accept(AstVisitor *visitor) {
   604         visitor->visit(this);
   605     }
   606 };
   607 
   608 class ReturnStatement : public Statement
   609 {
   610     Expression *expression_;
   611 
   612   public:
   613     ReturnStatement(const SourcePosition &pos, Expression *expression)
   614       : Statement(pos),
   615         expression_(expression)
   616     {
   617     }
   618 
   619     Kind kind() const {
   620         return kReturnStatement;
   621     }
   622     Expression *expression() const {
   623         return expression_;
   624     }
   625     void accept(AstVisitor *visitor) {
   626         visitor->visit(this);
   627     }
   628 };
   629 
   630 class BreakStatement : public Statement
   631 {
   632   public:
   633     BreakStatement(const SourcePosition &pos)
   634       : Statement(pos)
   635     {
   636     }
   637 
   638     Kind kind() const {
   639         return kBreakStatement;
   640     }
   641     void accept(AstVisitor *visitor) {
   642         visitor->visit(this);
   643     }
   644 };
   645 
   646 class ContinueStatement : public Statement
   647 {
   648   public:
   649     ContinueStatement(const SourcePosition &pos)
   650       : Statement(pos)
   651     {
   652     }
   653 
   654     Kind kind() const {
   655         return kContinueStatement;
   656     }
   657     void accept(AstVisitor *visitor) {
   658         visitor->visit(this);
   659     }
   660 };
   661 
   662 class Assignment : public Expression
   663 {
   664     TokenKind token_;
   665     Expression *lvalue_;
   666     Expression *expression_;
   667 
   668   public:
   669     Assignment(const SourcePosition &pos, TokenKind token, Expression *left, Expression *right)
   670       : Expression(pos),
   671         token_(token),
   672         lvalue_(left),
   673         expression_(right)
   674     {
   675     }
   676 
   677     Kind kind() const {
   678         return kAssignment;
   679     }
   680     TokenKind token() const {
   681         return token_;
   682     }
   683     Expression *lvalue() const {
   684         return lvalue_;
   685     }
   686     Expression *expression() const {
   687         return expression_;
   688     }
   689     void accept(AstVisitor *visitor) {
   690         visitor->visit(this);
   691     }
   692 };
   693 
   694 class ExpressionStatement : public Statement
   695 {
   696     Expression *expression_;
   697 
   698   public:
   699     ExpressionStatement(Expression *expression)
   700       : Statement(expression->pos()),
   701         expression_(expression)
   702     {
   703     }
   704 
   705     Kind kind() const {
   706         return kExpressionStatement;
   707     }
   708     Expression *expression() const {
   709         return expression_;
   710     }
   711     void accept(AstVisitor *visitor) {
   712         visitor->visit(this);
   713     }
   714 };
   715 
   716 class BlockStatement : public Statement
   717 {
   718     Scope *scope_;
   719     StatementList *statements_;
   720 
   721   public:
   722     BlockStatement(const SourcePosition &pos, Scope *scope, StatementList *statements)
   723       : Statement(pos),
   724         scope_(scope),
   725         statements_(statements)
   726     {
   727     }
   728 
   729     Kind kind() const {
   730         return kBlockStatement;
   731     }
   732     Scope *scope() const {
   733         return scope_;
   734     }
   735     StatementList *statements() const {
   736         return statements_;
   737     }
   738     void accept(AstVisitor *visitor) {
   739         visitor->visit(this);
   740     }
   741 };
   742 
   743 typedef PoolList<Parameter *> ParameterList;
   744 
   745 class FunctionStatement : public Statement
   746 {
   747     Scope *scope_;
   748     NamedFunction *fun_;
   749     Statement *body_;
   750     ParameterList *parameters_;
   751     bool explicitReturn_;
   752     BoundName *returnType_;
   753 
   754   public:
   755     FunctionStatement(const SourcePosition &pos, Scope *scope, NamedFunction *fun, Statement *body,
   756                       ParameterList *parameters, BoundName *returnType, bool explicitReturn)
   757       : Statement(pos),
   758         scope_(scope),
   759         fun_(fun),
   760         body_(body),
   761         parameters_(parameters),
   762         explicitReturn_(explicitReturn),
   763         returnType_(returnType)
   764     {
   765     }
   766 
   767     Kind kind() const {
   768         return kFunctionStatement;
   769     }
   770     Scope *scope() const {
   771         return scope_;
   772     }
   773     NamedFunction *fun() const {
   774         return fun_;
   775     }
   776     Statement *body() const {
   777         return body_;
   778     }
   779     ParameterList *parameters() const {
   780         return parameters_;
   781     }
   782     void accept(AstVisitor *visitor) {
   783         visitor->visit(this);
   784     }
   785     bool hasExplicitReturn() const {
   786         return explicitReturn_;
   787     }
   788     BoundName *returnType() const {
   789         return returnType_;
   790     }
   791 };
   792 
   793 class IfStatement : public Statement
   794 {
   795     Expression *condition_;
   796     Statement *ifTrue_;
   797     Statement *ifFalse_;
   798 
   799   public:
   800     IfStatement(const SourcePosition &pos, Expression *condition, Statement *ifTrue)
   801       : Statement(pos),
   802         condition_(condition),
   803         ifTrue_(ifTrue),
   804         ifFalse_(NULL)
   805     {
   806     }
   807 
   808     Kind kind() const {
   809         return kIfStatement;
   810     }
   811     Expression *condition() const {
   812         return condition_;
   813     }
   814     Statement *ifTrue() const {
   815         return ifTrue_;
   816     }
   817     Statement *ifFalse() const {
   818         return ifFalse_;
   819     }
   820     void setIfFalse(Statement *ifFalse) {
   821         ifFalse_ = ifFalse;
   822     }
   823     void accept(AstVisitor *visitor) {
   824         visitor->visit(this);
   825     }
   826 };
   827 
   828 class EnumStatement : public Statement
   829 {
   830     ScopedRoot<String> name_;
   831     NamedType *type_;
   832 
   833   public:
   834     struct Entry {
   835         NamedConstant *name;
   836         Expression *expr;
   837 
   838         Entry(NamedConstant *name, Expression *expr)
   839           : name(name),
   840             expr(expr)
   841         {
   842         }
   843     };
   844 
   845     typedef PoolList<Entry> EntryList;
   846 
   847   public:
   848     EnumStatement(const SourcePosition &pos, NamedType *type, Handle<String> name, EntryList *entries)
   849       : Statement(pos),
   850         name_(name),
   851         type_(type),
   852         entries_(entries)
   853     {
   854     }
   855 
   856     Kind kind() const {
   857         return kEnumStatement;
   858     }
   859     String *name() const {
   860         return name_;
   861     }
   862     EntryList *entries() const {
   863         return entries_;
   864     }
   865     NamedType *decl() const {
   866         return type_;
   867     }
   868     void accept(AstVisitor *visitor) {
   869         visitor->visit(this);
   870     }
   871 
   872   private:
   873     EntryList *entries_;
   874 };
   875 
   876 class IncDecExpression : public Expression
   877 {
   878     TokenKind token_;
   879     Expression *expression_;
   880     bool postfix_;
   881 
   882   public:
   883     IncDecExpression(const SourcePosition &pos, TokenKind token, Expression *expression, bool postfix)
   884       : Expression(pos),
   885         token_(token),
   886         expression_(expression),
   887         postfix_(postfix)
   888     {
   889     }
   890 
   891     Kind kind() const {
   892         return kIncDecExpression;
   893     }
   894     TokenKind token() const {
   895         return token_;
   896     }
   897     Expression *expression() const {
   898         return expression_;
   899     }
   900     bool postfix() const {
   901         return postfix_;
   902     }
   903     void accept(AstVisitor *visitor) {
   904         visitor->visit(this);
   905     }
   906 };
   907 
   908 class StructureStatement : public Statement
   909 {
   910   public:
   911     class Field : public PoolObject
   912     {
   913         SourcePosition pos_;
   914         BoundName *type_;
   915         ScopedRoot<String> name_;
   916         ExpressionList *dimensions_;
   917 
   918       public:
   919         Field(const SourcePosition &pos,
   920               BoundName *type,
   921               Handle<String> name,
   922               ExpressionList *dimensions)
   923           : pos_(pos),
   924             type_(type),
   925             name_(name),
   926             dimensions_(dimensions)
   927         {
   928         }
   929 
   930         const SourcePosition &pos() const {
   931             return pos_;
   932         }
   933         BoundName *type() const {
   934             return type_;
   935         }
   936         String *name() const {
   937             return name_;
   938         }
   939         ExpressionList *dimensions() const {
   940             return dimensions_;
   941         }
   942     };
   943 
   944     typedef PoolList<StructureStatement::Field *> FieldList;
   945 
   946   public:
   947     StructureStatement(const SourcePosition &pos, NamedType *decl, FieldList *fields)
   948       : Statement(pos),
   949         decl_(decl),
   950         fields_(fields)
   951     {
   952     }
   953 
   954     Kind kind() const {
   955         return kStructureStatement;
   956     }
   957     FieldList *fields() const {
   958         return fields_;
   959     }
   960     NamedType *decl() const {
   961         return decl_;
   962     }
   963     void accept(AstVisitor *visitor) {
   964         visitor->visit(this);
   965     }
   966 
   967   private:
   968     NamedType *decl_;
   969     FieldList *fields_;
   970 };
   971 
   972 typedef StructureStatement::FieldList FieldList;
   973 
   974 class Scope;
   975 
   976 typedef PoolList<NameProxy *> NameProxyList;
   977 
   978 class ParseTree : public PoolObject
   979 {
   980     StatementList *statements_;
   981     Scope *scope_;
   982     NameProxyList *unbound_;
   983 
   984   public:
   985     ParseTree(Scope *scope, StatementList *statements, NameProxyList *unbound)
   986       : statements_(statements),
   987         scope_(scope),
   988         unbound_(unbound)
   989     {
   990     }
   991 
   992     void dump(FILE *fp);
   993 
   994     StatementList *statements() const {
   995         return statements_;
   996     }
   997     Scope *scope() const {
   998         return scope_;
   999     }
  1000     NameProxyList *unbound() const {
  1001         return unbound_;
  1002     }
  1003 };
  1004 
  1005 }
  1006 
  1007 #endif // _include_jitcraft_ast_h_