Package wyvern.tools.types.extensions

Examples of wyvern.tools.types.extensions.ClassType


  protected void setInstanceMembersEnv(Environment newEnv) { instanceMembersEnv.set(newEnv); }

  private ClassType objType = new ClassType(instanceMembersEnv, new Reference<>(), new LinkedList<>(), "");

  public ClassType getOType() {
    return new ClassType(instanceMembersEnv, new Reference<>(), new LinkedList<>(), getName());
  }
View Full Code Here


      equivalentType = new TypeType(TypeDeclUtils.getTypeEquivalentEnvironment(getDecls(), false));
    return equivalentType;
  }

  protected Type getClassType() {
    return new ClassType(this);
  }
View Full Code Here

      if (nameImplements == null) {
        ToolError.reportError(ErrorMessage.TYPE_NOT_DECLARED, this, this.implementsName);
      }
     
      // since there is a valid implements, check that all methods are indeed present
      ClassType currentCT = (ClassType) this.nameBinding.getType();
            TypeType implementsTT = (TypeType)nameImplements.getType();
     
      if (!getEquivalentType().subtype(implementsTT)) {
        ToolError.reportError(ErrorMessage.NOT_SUBTYPE,
            this,
                        this.nameBinding.getName(),
                        nameImplements.getName());
      }
    }
   
    if (!this.implementsClassName.equals("")) {
      NameBinding nameImplementsClass = env.lookup(this.implementsClassName);
      if (nameImplementsClass == null) {
        ToolError.reportError(ErrorMessage.TYPE_NOT_DECLARED, this, this.implementsClassName);
      }

      // since there is a valid class implements, check that all methods are indeed present
      ClassType currentCT = (ClassType) this.nameBinding.getType();
            TypeType implementsCT = (TypeType) (
          ((ClassType)nameImplementsClass.getType())
              .getEnv()
              .lookupBinding("type", TypeDeclBinding.class)).get().getType();
     
View Full Code Here

  }

  private Type getObjectType() {
    Environment declEnv = getInstanceMembersEnv();
    Environment objTee = TypeDeclUtils.getTypeEquivalentEnvironment(declEnv);
    return new ClassType(instanceMembersEnv, new Reference<Environment>(objTee) {
      @Override
      public Environment get() {
        return TypeDeclUtils.getTypeEquivalentEnvironment(instanceMembersEnv.get());
      }
View Full Code Here

    }

  @Override
  public Type getType() {
        updateTee();
    return new ClassType(intEnv, new Reference<>(typeEquivEnv), new LinkedList<String>(), null);
  }
View Full Code Here

  public ModuleDeclaration(String name, EnvironmentExtender inner, FileLocation location) {
    this.name = name;
    this.inner = inner;
    this.location = location;
    selfType = new ClassType(dclEnv, new Reference<>(), new LinkedList<>(), name);
    subTypeType = new ClassType(typeEnv, new Reference<>(), new LinkedList<>(), name);
  }
View Full Code Here

    // System.out.println("classVarTypeBinding = " + classVarTypeBinding);

    if (classVarTypeBinding != null) { //In a class method
      Environment declEnv = classVarTypeBinding.getClassDecl().getInstanceMembersEnv();
      Environment innerEnv = seq.extendName(Environment.getEmptyEnvironment(), env).extend(declEnv);
      seq.typecheck(env.extend(new NameBindingImpl("this", new ClassType(new Reference<>(innerEnv), new Reference<>(innerEnv), new LinkedList<>(), classVarTypeBinding.getClassDecl().getName()))), Optional.empty());


      Environment environment = seq.extendType(declEnv, declEnv.extend(env));
      environment = seq.extendName(environment, environment.extend(env));
      Environment nnames = seq.extend(environment, environment);

      Environment objTee = TypeDeclUtils.getTypeEquivalentEnvironment(nnames.extend(declEnv));
      Type classVarType = new ClassType(new Reference<>(nnames.extend(declEnv)), new Reference<>(objTee), new LinkedList<>(), classVarTypeBinding.getClassDecl().getName());
      if (!(classVarType instanceof ClassType)) {
        // System.out.println("Type checking classVarType: " + classVarType + " and clsVar = " + clsVar);
        ToolError.reportError(ErrorMessage.MUST_BE_LITERAL_CLASS, this, classVarType.toString());
      }

      // TODO SMELL: do I really need to store this?  Can get it any time from the type
      cls = classVarTypeBinding.getClassDecl();
      ct = classVarType;

      return classVarType;
    } else { // Standalone
     
      isGeneric = true;
      Environment innerEnv = seq.extendType(Environment.getEmptyEnvironment(), env);
      Environment savedInner = env.extend(innerEnv);
      innerEnv = seq.extendName(innerEnv, savedInner);

      Environment declEnv = env.extend(new NameBindingImpl("this", new ClassType(new Reference<>(innerEnv), new Reference<>(innerEnv), new LinkedList<>(), null)));
      final Environment ideclEnv = StreamSupport.stream(seq.getDeclIterator().spliterator(), false).
          reduce(declEnv, (oenv,decl)->(decl instanceof ClassDeclaration)?decl.extend(oenv, savedInner):oenv,(a,b)->a.extend(b));
      seq.getDeclIterator().forEach(decl -> decl.typecheck(ideclEnv, Optional.<Type>empty()));


      Environment mockEnv = Environment.getEmptyEnvironment();

      LinkedList<Declaration> decls = new LinkedList<>();

      mockEnv = getGenericDecls(env, mockEnv, decls);
      Environment nnames = (seq.extendName(mockEnv,mockEnv.extend(env)));

      ClassDeclaration classDeclaration = new ClassDeclaration("generic" + generic_num++, "", "", new DeclSequence(decls), mockEnv, new LinkedList<String>(), getLocation());
      cls = classDeclaration;
      Environment tee = TypeDeclUtils.getTypeEquivalentEnvironment(nnames.extend(mockEnv));
     
      ct = new ClassType(new Reference<>(nnames.extend(mockEnv)), new Reference<>(tee), new LinkedList<String>(), null);
      return ct;
    }
  }
View Full Code Here

    nameBinding = new NameBindingImpl(name, null);
    typeBinding = new TypeBinding(name, null, metadata);
    Type objectType = new TypeType(this);
    attrEnv.set(attrEnv.get().extend(new TypeDeclBinding("type", this)));
   
    Type classType = new ClassType(attrEnv, attrEnv, new LinkedList<String>(), getName()); // TODO set this to a class type that has the class members
    nameBinding = new LateNameBinding(nameBinding.getName(), () -> metadata.get().getType());

    typeBinding = new TypeBinding(nameBinding.getName(), objectType, metadata);
   
    // System.out.println("TypeDeclaration: " + nameBinding.getName() + " is now bound to type: " + objectType);
View Full Code Here

      }
     
      Type t = binding.getType();
     
      if (t instanceof ClassType) {
        ClassType classType = (ClassType) t;
       
        String name = classType.getName();
       
        TagBinding tagBinding = TagBinding.get(name);
       
        if (tagBinding == null) {
          //not tagged
View Full Code Here

  }

 
  private String getTypeName(Type type) {
    if (type instanceof ClassType) {
      ClassType matchingOverClass = (ClassType) matchingOver.getType();
      return matchingOverClass.getName();
    } else if (type instanceof TypeType) {
      TypeType matchingOverClass = (TypeType) matchingOver.getType();
      return matchingOverClass.getName();
    }
   
    return null;
  }
View Full Code Here

TOP

Related Classes of wyvern.tools.types.extensions.ClassType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.