Beispiel #1
0
 def check(self):
   try:
     env.getSuperClass(self.name)
   except SymbolError, e:
     if self.suppress_errors:
       e.ignore
     else:
       e.setToken(self.token)
       e.report()
Beispiel #2
0
  def subsetOf(self, t):
    "Checks compatibility between types"
    
    # "Nothing is compatible with anything - the function does not return"
    # "undefined" is a special, impossible value to prevent too many errors from being reported
    if self.name in ("Nothing", "undefined"):
      return True

    # Null can be any type except for a few specified, built-in types
    if self.isNull():
      if isinstance(t, Type):
        t = t.name
      return t not in NOT_NULLABLE_TYPES

    c = self.name
    # Check if this class or any of its ancestors match the provided type
    while c is not None:
      c = Type(c)
      if c.isType(t):
        return True
      try:
        c = env.getSuperClass(c.name)
      except SymbolError, e:
        if getattr(c, 'suppress_errors', False):
          e.ignore()
        else:
          e.report()
Beispiel #3
0
  def check(self):
    if isinstance(self.node.value, tree.Native):
      return

    args = tuple(f.name for f in self.node.formals.getType())
    try:
      super_method = env.getMethodType(env.getSuperClass(self.c), self.node.id.name)

      # If this is none, the superclass does not exist
      if super_method[0] == 'undefined':
        return
      if self.node.override:
        sargs = super_method[:-1]
        if len(args) != len(sargs):
            TypeCheckError("Overriding method does not have the same number of arguments as "
              + "overridden method", self.token).report()
        else: 
          for arg, sarg in zip(args, sargs):
            if arg != sarg:
              TypeCheckError("Overriding method argument types do not match overridden method "
                +"types", self.token).report()
              break
        
        method_type = self.getType()
        if not getattr(method_type, 'suppress_errors', False) and not method_type.subsetOf(super_method[-1]):
          TypeCheckError("Overriding method type is not compatible with overridden method type",
            self.node.type.token).report()
      else:
        TypeCheckError("Overriding method must use override keyword", self.token).report()
    except SymbolError, e:
      if self.node.override:
        TypeCheckError("Method is set to override, but does not exist in ancestor classes", 
          self.token).report()
      else:
        e.ignore()
Beispiel #4
0
 def parent(self):
   try:
     s = env.getSuperClass(self.name)
   except SymbolError, e:
     if self.suppress_errors:
       e.ignore()
     else:
       e.setToken(self.token)
       e.report()
     s = None