Package wyvern.tools.types

Examples of wyvern.tools.types.Type


        if (((VarDeclaration) d).isClassMember() != useClassMembers)
          continue;

        VarDeclaration vd = (VarDeclaration) d;
        String propName = vd.getName();
        Type type = vd.getType();
        FileLocation line = vd.getLocation();


        newEnv = newEnv.extend(new NameBindingImpl(propName, type));
        newEnv = newEnv.extend(
            new NameBindingImpl(
                "set" + propName.substring(0,1).toUpperCase() + propName.substring(1),
                new Arrow(type, Unit.getInstance())));
      } else if (d instanceof ValDeclaration) {
        if (((ValDeclaration) d).isClassMember() != useClassMembers)
          continue;

        ValDeclaration vd = (ValDeclaration) d;
        String propName = vd.getName();
        Type type = vd.getType();
        FileLocation line = vd.getLocation();

        DefDeclaration getter = new DefDeclaration(propName, type,
            new LinkedList<NameBinding>(), null, false, line);
View Full Code Here


  public static Type javaToWyvType(Class jType) {
    if (classCache.containsKey(jType))
      return classCache.get(jType);

    Type newType = javaToWyvTypeInternal(jType);
    classCache.put(jType, newType);
    return newType;
  }
View Full Code Here

    }
    return nArgs;
  }

  private static Type[] getArgTypes(Arrow methType) {
    Type argType = methType.getArgument();
    if (argType instanceof Tuple)
      return ((Tuple) argType).getTypeArray();
    else if (argType instanceof Unit)
      return new Type[0];
    else
View Full Code Here

    }
    return null;
  }

  public static boolean checkCast(Obj ref, Class jClass) {
    Type javaType = javaToWyvType(jClass);
    Type wyvernType = ref.getType();
    return wyvernType.subtype(javaType);
  }
View Full Code Here

  }



  public static boolean checkTypeCast(Type type, Class arg) {
    Type javaType = javaToWyvType(arg);
    return type.subtype(javaType);
  }
View Full Code Here

          methName,
          getMethodDescriptor(methType, findCandidate(methName, methType, javaType)),
          null,
          null);

      Type returnType = methType.getResult();
      Type[] parameterTypes = getArgTypes(methType);

      mv.visitCode();
      mv.visitVarInsn(ALOAD, 0);
      mv.visitFieldInsn(GETFIELD, name, "objref$wyv", "Lwyvern/tools/typedAST/core/values/Obj;");
View Full Code Here

    JavaClassDecl terminalsDecl = StreamSupport.stream(jcd.getDecls().getDeclIterator().spliterator(), false)
        .filter(decl -> decl instanceof JavaClassDecl)
        .<JavaClassDecl>map(decl -> (JavaClassDecl) decl)
        .filter(decl -> decl.getName().equals("Terminals"))
        .findFirst().orElseThrow(() -> new RuntimeException("Cannot find terminals class"));
    Type terminalClassType = terminalsDecl
        .extend(Environment.getEmptyEnvironment(), Environment.getEmptyEnvironment())
        .lookup("Terminals").getType();
    Type terminalObjType = terminalsDecl
        .extend(Environment.getEmptyEnvironment(), Environment.getEmptyEnvironment())
        .lookupType("Terminals").getType();

    splicers.forEach(splicer -> splicer.accept(terminalClassType,terminalObjType));


    AtomicInteger cdIdx = new AtomicInteger();
    TypedAST[] classDecls = new TypedAST[toGen.size() + toGenDefs.size() + 1];
    toGen.entrySet().stream().forEach(entry->classDecls[cdIdx.getAndIncrement()]
        = new ValDeclaration(entry.getKey(), DefDeclaration.getMethodType(entry.getValue().second().getArgBindings(), entry.getValue().first()), entry.getValue().second(), unkLoc));

    toGenDefs.entrySet().stream().forEach(entry->classDecls[cdIdx.getAndIncrement()]
        = new DefDeclaration(entry.getKey(), new Arrow(Unit.getInstance(), Unit.getInstance()), new LinkedList<>(), entry.getValue(), false));

    classDecls[cdIdx.getAndIncrement()] = new DefDeclaration("create", new Arrow(Unit.getInstance(),
        new UnresolvedType(wyvClassName)),
        Arrays.asList(),
        new New(new DeclSequence(), unkLoc), true);


    ArrayList<TypedAST> pairedObjDecls = new ArrayList<>();
    pairedObjDecls.addAll(Arrays.asList(classDecls));
    TypedAST pairedObj = new ClassDeclaration(wyvClassName, "", "", new DeclSequence(pairedObjDecls), unkLoc);

    Type parseBufferType = Util.javaToWyvType(ParseBuffer.class);


    Type javaClassType = Util.javaToWyvType(javaClass);
    TypedAST bufGet = new Application(
        new Invocation(new Variable(new NameBindingImpl("buf", null), unkLoc), "getSrcString", null, unkLoc),
        UnitVal.getInstance(unkLoc),
        unkLoc);
    ClassType emptyType =
View Full Code Here

          argNames.stream().map(str -> (str.getType() instanceof Int) ? "new IntegerConstant(" + str.getName() + ")" : "new StringConstant(" + str.getName() + ")").reduce((a, b) -> a + ", " + b).get()));
    };
  }

  private Pair<String, Type> parseType(NonTerminal elem) {
    Type parsedType = null;
    try {
      parsedType = LangUtil.spliceType(new IParseBuffer(elem.getReturnType()));
      ((NonTerminal) elem).setReturnType("Value");
    } catch (Exception e) {
      throw new RuntimeException(e);
View Full Code Here

      throw new RuntimeException(e);
    }
    return new Pair<String, Type>(elem.getName().toString(), parsedType);
  }
  private Pair<String, Type> parseType(Terminal elem) {
    Type parsedType = null;
    try {
      parsedType = LangUtil.spliceType(new IParseBuffer(elem.getReturnType()));
      elem.setReturnType("Value");
    } catch (Exception e) {
      throw new RuntimeException(e);
View Full Code Here

      String oCode = term.getCode();

      CopperElementName termName = term.getName();
      String newName = getNextName(methNum, termName);

      Type resType = lhsEnv.lookup(term.getName().toString()).getType();

      splicers.add((termClassType,termObjType) -> {
            SpliceBindExn spliced = LangUtil.spliceBinding(new IParseBuffer(oCode), Arrays.asList(new NameBinding[]{
                new NameBindingImpl("lexeme", Str.getInstance()),
                new NameBindingImpl("pushToken", new Arrow(new Tuple(termObjType, Str.getInstance()), Unit.getInstance())),
View Full Code Here

TOP

Related Classes of wyvern.tools.types.Type

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.