1.1 --- a/src/SemanticAnalysis.cpp Sat Aug 04 19:33:06 2012 -0700
1.2 +++ b/src/SemanticAnalysis.cpp Sat Aug 04 20:12:20 2012 -0700
1.3 @@ -275,6 +275,10 @@
1.4 }
1.5 }
1.6
1.7 + // Note that unlike IndexExpression, FieldExpression uses its actual
1.8 + // result type, rather than its parent array type, which can be recovered
1.9 + // from its left-hand side expression.
1.10 +
1.11 return expression->type();
1.12 }
1.13
1.14 @@ -300,7 +304,7 @@
1.15 case PrimitiveType_Int32:
1.16 return "int";
1.17 case PrimitiveType_Float:
1.18 - return "float";
1.19 + return "Float";
1.20 default:
1.21 return "<unknown>";
1.22 }
1.23 @@ -390,6 +394,19 @@
1.24 return type->contained();
1.25 }
1.26
1.27 + if (expression->isFieldExpression()) {
1.28 + Type *type = visitAndApplyType(expression);
1.29 + if (!type)
1.30 + return NULL;
1.31 +
1.32 + // if (expression->toFieldExpression()->left()->type()->isConst()) {
1.33 + // cc_.reportError(expression->pos(), Message_ReferenceIsConstant);
1.34 + // return NULL;
1.35 + // }
1.36 +
1.37 + return type;
1.38 + }
1.39 +
1.40 if (!expression->isNameProxy()) {
1.41 cc_.reportError(expression->pos(), Message_ExpectedLValue);
1.42 return NULL;
1.43 @@ -1105,6 +1122,7 @@
1.44 // a reference.
1.45 if (expression->isIndexExpression())
1.46 given = given->contained();
1.47 + assert(!expression->isFieldExpression());
1.48
1.49 bool mustComputeReference;
1.50 if (i >= type->parameters()->length()) {
1.51 @@ -1188,6 +1206,33 @@
1.52 }
1.53
1.54 void
1.55 +SemanticAnalysis::visit(FieldExpression *node)
1.56 +{
1.57 + Local<Type> left(zone_, visitForLoad(node->left()));
1.58 + if (!left)
1.59 + return;
1.60 +
1.61 + if (!left->isStruct()) {
1.62 + cc_.reportError(node->pos(), Message_PropertyNotFound, node->field()->chars(),
1.63 + GetTypeName(left));
1.64 + return;
1.65 + }
1.66 +
1.67 + Local<String> field(zone_, node->field());
1.68 +
1.69 + unsigned offset;
1.70 + Local<Descriptor> desc(zone_, left->lookupField(field, &offset));
1.71 + if (!desc) {
1.72 + cc_.reportError(node->pos(), Message_PropertyNotFound, node->field()->chars(),
1.73 + GetTypeName(left));
1.74 + return;
1.75 + }
1.76 +
1.77 + node->setFieldIndex(offset);
1.78 + node->setType(desc->type());
1.79 +}
1.80 +
1.81 +void
1.82 SemanticAnalysis::visit(EnumStatement *node)
1.83 {
1.84 Local<Type> type(zone_, node->decl()->type());