src/SemanticAnalysis.cpp
changeset 147 9c544823d090
parent 146 dc7d3b7a918c
child 148 c0740249963c
     1.1 --- a/src/SemanticAnalysis.cpp	Sat Aug 04 17:51:43 2012 -0700
     1.2 +++ b/src/SemanticAnalysis.cpp	Sat Aug 04 19:33:06 2012 -0700
     1.3 @@ -160,7 +160,10 @@
     1.4  
     1.5              enumstmt->decl()->setType(type);
     1.6          } else if (statement->isStructureStatement()) {
     1.7 -            statement->accept(this);
     1.8 +            StructureStatement *node = statement->toStructureStatement();
     1.9 +            node->accept(this);
    1.10 +            if (!node->decl()->type())
    1.11 +                return false;
    1.12          }
    1.13      }
    1.14  
    1.15 @@ -285,7 +288,7 @@
    1.16          return "function";
    1.17      if (type->isVoid())
    1.18          return "void";
    1.19 -    if (type->isEnum())
    1.20 +    if (type->isEnum() || type->isStruct())
    1.21          return type->name()->chars();
    1.22      if (type->isReference())
    1.23          type = type->contained();
    1.24 @@ -782,12 +785,6 @@
    1.25              if (check)
    1.26                  check = check->contained();
    1.27          }
    1.28 -
    1.29 -        // If this variable is stack allocated, we could use the LIFO heap
    1.30 -        // to allocate it. If that's the case, make sure to reserve a slot
    1.31 -        // so we can unwind the LIFO heap at the end of this scope.
    1.32 -        if (!node->variable()->needsHeapAllocation())
    1.33 -            scope_->setUsesLifoHeap();
    1.34      } else {
    1.35          if (node->initialization()) {
    1.36              Local<Type> right(zone_, visitForLoad(node->initialization()));
    1.37 @@ -796,12 +793,21 @@
    1.38              if (!typeCheckAssignment(node, type, right, true))
    1.39                  return;
    1.40          }
    1.41 -        if (type->primitive() == PrimitiveType_Char) {
    1.42 +
    1.43 +        if (type->isPrimitive() && type->primitive() == PrimitiveType_Char) {
    1.44              cc_.reportError(node->pos(), Message_CannotDeclareStringCell);
    1.45              return;
    1.46          }
    1.47      }
    1.48  
    1.49 +    // If this variable is stack allocated, we could use the LIFO heap
    1.50 +    // to allocate it. If that's the case, make sure to reserve a slot
    1.51 +    // so we can unwind the LIFO heap at the end of this scope.
    1.52 +    if (!node->variable()->needsHeapAllocation()) {
    1.53 +        if (type->isArray() || type->isStruct())
    1.54 +            scope_->setUsesLifoHeap();
    1.55 +    }
    1.56 +
    1.57      node->variable()->setType(type);
    1.58  }
    1.59  
    1.60 @@ -1245,11 +1251,16 @@
    1.61          desctable->set(zone_, i, desc);
    1.62      }
    1.63  
    1.64 +    Local<StructMap> map(zone_, StructMap::New(zone_, builder));
    1.65 +    if (!map)
    1.66 +        return;
    1.67 +
    1.68      name = node->decl()->name();
    1.69 -    type = zone_->types()->newStruct(name, desctable);
    1.70 +    type = zone_->types()->newStruct(name, desctable, map);
    1.71      if (!type)
    1.72          return;
    1.73  
    1.74 +    map->setType(type);
    1.75      node->decl()->setType(type);
    1.76  }
    1.77