Attach tags to enum fields.
authorDavid Anderson <dvander@alliedmods.net>
Tue Jun 26 00:58:55 2012 -0700 (2012-06-26)
changeset 3f43e399ab622
parent 2 46fc53b8fd2f
child 4 633176823669
Attach tags to enum fields.
jitcraft/SemanticAnalysis.cpp
jitcraft/Types.cpp
     1.1 --- a/jitcraft/SemanticAnalysis.cpp	Tue Jun 26 00:35:15 2012 -0700
     1.2 +++ b/jitcraft/SemanticAnalysis.cpp	Tue Jun 26 00:58:55 2012 -0700
     1.3 @@ -259,7 +259,14 @@
     1.4  void
     1.5  SemanticAnalysis::visit(EnumStatement *node)
     1.6  {
     1.7 -    Type *type = Type::NewPrimitive(NULL);
     1.8 +    Tag *tag = NULL;
     1.9 +    if (node->name()) {
    1.10 +        tag = new Tag(node->name());
    1.11 +        if (!tag)
    1.12 +            return;
    1.13 +    }
    1.14 +
    1.15 +    Type *type = Type::NewPrimitive(tag);
    1.16      if (!type)
    1.17          return;
    1.18  
    1.19 @@ -271,7 +278,7 @@
    1.20          if (entry.expr) {
    1.21              entry.expr->accept(this);
    1.22              if (!EvaluateForConstant(entry.expr, &box))
    1.23 -                fprintf(stderr, "expected constant expression\n");
    1.24 +                fprintf(stderr, "expected constant integer expression\n");
    1.25  
    1.26              assert(box.type() == PrimitiveType_Int32);
    1.27              value = box.toInt();
     2.1 --- a/jitcraft/Types.cpp	Tue Jun 26 00:35:15 2012 -0700
     2.2 +++ b/jitcraft/Types.cpp	Tue Jun 26 00:58:55 2012 -0700
     2.3 @@ -19,6 +19,11 @@
     2.4  
     2.5  using namespace jc;
     2.6  
     2.7 +Tag::Tag(Name *name)
     2.8 +  : name_(name)
     2.9 +{
    2.10 +}
    2.11 +
    2.12  Type *
    2.13  Type::NewPrimitive(Tag *tag)
    2.14  {
    2.15 @@ -26,7 +31,6 @@
    2.16      type->kind_ = PRIMITIVE;
    2.17      type->tag_ = tag;
    2.18      
    2.19 -    assert(!tag);
    2.20      type->primitive_ = PrimitiveType_Int32;
    2.21      return type;
    2.22  }