jitcraft/SemanticAnalysis.cpp
changeset 54 8e22792a3921
parent 47 050939c6181e
child 55 e073a9fe8e57
     1.1 --- a/jitcraft/SemanticAnalysis.cpp	Sat Jul 07 17:11:31 2012 -0700
     1.2 +++ b/jitcraft/SemanticAnalysis.cpp	Sat Jul 07 20:28:29 2012 -0700
     1.3 @@ -22,6 +22,7 @@
     1.4  #include "TypeManager.h"
     1.5  #include "Scopes.h"
     1.6  #include "Heap-inl.h"
     1.7 +#include "Strings.h"
     1.8  
     1.9  using namespace jc;
    1.10  
    1.11 @@ -158,6 +159,7 @@
    1.12      return expression->type();
    1.13  }
    1.14  
    1.15 +// :TODO: this leaks an interior pointer.
    1.16  static inline const char *
    1.17  GetTypeName(Type *type)
    1.18  {
    1.19 @@ -168,7 +170,7 @@
    1.20      if (type->isReference())
    1.21          type = type->contained();
    1.22      if (type->tag())
    1.23 -        return type->tag();
    1.24 +        return type->tag()->chars();
    1.25      return "int";
    1.26  }
    1.27  
    1.28 @@ -388,7 +390,8 @@
    1.29  void
    1.30  SemanticAnalysis::visit(VariableDeclaration *node)
    1.31  {
    1.32 -    Local<Type> type(zone_, zone_->types()->getPrimitiveForTag(node->tag()));
    1.33 +    Local<String> tag(zone_, node->tag());
    1.34 +    Local<Type> type(zone_, zone_->types()->getPrimitiveForTag(tag));
    1.35      if (!type)
    1.36          return;
    1.37  
    1.38 @@ -528,7 +531,8 @@
    1.39      for (size_t i = 0; i < node->parameters()->size(); i++) {
    1.40          Parameter *parameter = node->parameters()->at(i);
    1.41          
    1.42 -        Local<Type> type(zone_, zone_->types()->getPrimitiveForTag(parameter->tag()));
    1.43 +        Local<String> tag(zone_, parameter->tag());
    1.44 +        Local<Type> type(zone_, zone_->types()->getPrimitiveForTag(tag));
    1.45          if (!type)
    1.46              return false;
    1.47  
    1.48 @@ -617,8 +621,9 @@
    1.49      }
    1.50  
    1.51      if (given->primitive() != actual->primitive()) {
    1.52 -        const char *givenTag = given->tag() ? given->tag() : "_";
    1.53 -        const char *actualTag = given->tag() ? given->tag() : "_";
    1.54 +        // :TODO: leaks an interior pointer.
    1.55 +        const char *givenTag = given->tag() ? given->tag()->chars() : "_";
    1.56 +        const char *actualTag = given->tag() ? given->tag()->chars() : "_";
    1.57          cc_.reportError(node->pos(), Message_TagMismatch, actualTag, givenTag);
    1.58          return false;
    1.59      }
    1.60 @@ -652,8 +657,9 @@
    1.61      }
    1.62      
    1.63      if (given->primitive() != actual->primitive()) {
    1.64 -        const char *givenTag = given->tag() ? given->tag() : "_";
    1.65 -        const char *actualTag = given->tag() ? given->tag() : "_";
    1.66 +        // :TODO: leaks an interior pointer
    1.67 +        const char *givenTag = given->tag() ? given->tag()->chars() : "_";
    1.68 +        const char *actualTag = given->tag() ? given->tag()->chars() : "_";
    1.69          cc_.reportError(node->pos(), Message_TagMismatch, actualTag, givenTag);
    1.70          return false;
    1.71      }
    1.72 @@ -746,11 +752,11 @@
    1.73  SemanticAnalysis::visit(EnumStatement *node)
    1.74  {
    1.75      // Forbid the blessed types.
    1.76 -    Name *tag = node->name();
    1.77 -    if (!strcmp(tag, "Float") ||
    1.78 -        !strcmp(tag, "String") ||
    1.79 -        !strcmp(tag, "any") ||
    1.80 -        !strcmp(tag, "bool"))
    1.81 +    Local<String> tag(zone_, node->name());
    1.82 +    if (!strcmp(tag->chars(), "Float") ||
    1.83 +        !strcmp(tag->chars(), "String") ||
    1.84 +        !strcmp(tag->chars(), "any") ||
    1.85 +        !strcmp(tag->chars(), "bool"))
    1.86      {
    1.87          cc_.reportError(node->pos(), Message_InvalidEnumName);
    1.88          return;