1.1 --- a/src/Parser.cpp Wed Aug 01 22:32:59 2012 -0700
1.2 +++ b/src/Parser.cpp Sat Aug 04 17:51:43 2012 -0700
1.3 @@ -892,6 +892,11 @@
1.4 return NULL;
1.5 break;
1.6
1.7 + case TOK_STRUCT:
1.8 + if ((statement = struct_()) == NULL)
1.9 + return NULL;
1.10 + break;
1.11 +
1.12 case TOK_IF:
1.13 return if_();
1.14
1.15 @@ -914,6 +919,68 @@
1.16 }
1.17
1.18 Statement *
1.19 +Parser::struct_()
1.20 +{
1.21 + expect(TOK_STRUCT);
1.22 +
1.23 + Local<String> name(zone_, expectName());
1.24 + if (!name)
1.25 + return NULL;
1.26 +
1.27 + SourcePosition pos = scanner_.begin();
1.28 +
1.29 + if (BoundName *other = scope_->localLookup(name)) {
1.30 + redeclarationError(other);
1.31 + return NULL;
1.32 + }
1.33 +
1.34 + NamedType *type;
1.35 + if ((type = scope_->declareType(name, scanner_.begin())) == NULL)
1.36 + return NULL;
1.37 +
1.38 + if (!expect(TOK_LBRACE))
1.39 + return NULL;
1.40 +
1.41 + FieldList *fields = new (pool_) FieldList();
1.42 +
1.43 + while (!peek(TOK_RBRACE)) {
1.44 + if (matchName(name.ref(), TOK_LABEL) && !name)
1.45 + return NULL;
1.46 +
1.47 + BoundName *type = NULL;
1.48 + if (name) {
1.49 + if ((type = bindType(name)) == NULL)
1.50 + return NULL;
1.51 + }
1.52 +
1.53 + name = expectName();
1.54 + if (!name)
1.55 + return NULL;
1.56 +
1.57 + SourcePosition pos = scanner_.begin();
1.58 +
1.59 + ExpressionList *postDimensions = NULL;
1.60 + if (peek(TOK_LBRACKET)) {
1.61 + if ((postDimensions = dimensions()) == NULL)
1.62 + return NULL;
1.63 + }
1.64 +
1.65 + if (!matchSemicolon())
1.66 + return NULL;
1.67 +
1.68 + StructureStatement::Field *field =
1.69 + new (pool_) StructureStatement::Field(pos, type, name, postDimensions);
1.70 + if (!field || !fields->append(field))
1.71 + return NULL;
1.72 + }
1.73 +
1.74 + if (!expect(TOK_RBRACE))
1.75 + return NULL;
1.76 +
1.77 + return new (pool_) StructureStatement(pos, type, fields);
1.78 +}
1.79 +
1.80 +Statement *
1.81 Parser::enum_()
1.82 {
1.83 expect(TOK_ENUM);
1.84 @@ -1202,6 +1269,13 @@
1.85 return NULL;
1.86 break;
1.87
1.88 + case TOK_STRUCT:
1.89 + if ((statement = struct_()) == NULL)
1.90 + return NULL;
1.91 + if (!matchSemicolon())
1.92 + return NULL;
1.93 + break;
1.94 +
1.95 default:
1.96 cc_.reportError(scanner_.begin(), Message_ExpectedGlobal);
1.97 return NULL;
1.98 @@ -1417,6 +1491,10 @@
1.99 node->expression()->accept(this);
1.100 unindent();
1.101 }
1.102 + void visit(StructureStatement *node) {
1.103 + prefix();
1.104 + fprintf(fp_, "[ StructureStatement\n");
1.105 + }
1.106 };
1.107
1.108 void