Package org.eclipse.imp.pdb.facts.type

Examples of org.eclipse.imp.pdb.facts.type.Type


    return super.subtractListRelation(that);
  }

  @Override
  public <U extends IValue, V extends IValue> Result<U> setAnnotation(String annoName, Result<V> anno, Environment env) {
    Type annoType = env.getAnnotationType(getType(), annoName);

    if (getType() != getTypeFactory().nodeType()) {
      if (getType() != getTypeFactory().nodeType() && annoType == null) {
        throw new UndeclaredAnnotation(annoName, getType(), ctx.getCurrentAST());
      }
View Full Code Here


  public ITask<Type,IValue,IValue> getProducer(Type key, IValue name) {
    lock.lock();
    try {
      Map<Type, ITask<Type, IValue, IValue>> producerMap = keyedProducers.get(key);
      if(producerMap != null) {
        Type nameType = name.getType();
        if(producerMap.containsKey(nameType))
          return producerMap.get(nameType);
        for(Map.Entry<Type, ITask<Type, IValue, IValue>> t : producerMap.entrySet()) {
          if(nameType.isSubtypeOf(t.getKey()))
            return t.getValue();
        }
      }
      throw new ImplementationError("No suitable producer found for " + key + "(" + name + ")");
    }
View Full Code Here

  public void registerProducer(ITask<Type,IValue,IValue> producer) {
    lock.lock();
    try {
      for(Type key : producer.getKeys()) {
        if(key.isTuple()) {
          Type key1 = key.getFieldType(0);
          Type key2 = key.getFieldType(1);
          Map<Type, ITask<Type, IValue, IValue>> map = keyedProducers.get(key1);
          if(map == null)
            map = new HashMap<Type, ITask<Type, IValue, IValue>>();
          map.put(key2, producer);
          keyedProducers.put(key1, map);
View Full Code Here

  public void unregisterProducer(ITask<Type,IValue,IValue> producer) {
    lock.lock();
    try {
      for(Type key : producer.getKeys()) {
        if(key.isTuple()) {
          Type key1 = key.getFieldType(0);
          Map<Type, ITask<Type, IValue, IValue>> map = keyedProducers.get(key1);
          if(map != null) {
            for(Map.Entry<Type, ITask<Type,IValue,IValue>> entry : map.entrySet()) {
              if(entry.getValue().equals(producer))
                map.remove(entry.getKey());
View Full Code Here

          throw RuntimeExceptionFactory.io(vf.string("You can only access ls on a directory, or a container."), ctx.getCurrentAST(), ctx.getStackTrace());
        }
        Result<IValue> resRes = makeResult(getType(), resolved, ctx);

        IListWriter w = ctx.getValueFactory().listWriter();
        Type stringType = tf.stringType();

        for (String elem : ctx.getResolverRegistry().listEntries(resolved.getURI())) {
          w.append(resRes.add(makeResult(stringType, vf.string(elem), ctx)).getValue());
        }
View Full Code Here

    String path = loc.hasPath() ? loc.getPath() : null;
    String query = loc.hasQuery() ? loc.getQuery() : null;
    String fragment = loc.hasFragment() ? loc.getFragment() : null;
   

    Type replType = repl.getType();
    IValue replValue = repl.getValue();

    try {
      String newStringValue = null;
      if (replType.isString()) {
        newStringValue = ((IString)replValue).getValue();
      }
      if (name.equals("uri")) {
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        URI uri = URIUtil.createFromEncoded(newStringValue);
        // now destruct it again
        scheme = uri.getScheme();
        authority = uri.getAuthority();
        path = uri.getPath();
        query = uri.getQuery();
        fragment = uri.getFragment();
        uriPartChanged = true;
      }
      else if (name.equals("scheme")) {
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        scheme = newStringValue;
        uriPartChanged = true;
      }
      else if (name.equals("authority")) {
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        authority = newStringValue;
        uriPartChanged = true;
      }
      else if (name.equals("host")) {
        URI uri = value.getURI();
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        if (!ctx.getResolverRegistry().supportsHost(uri)) {
          throw new UndeclaredField(name, "The scheme " + uri.getScheme() + " does not support the host field, use authority instead.", getTypeFactory().sourceLocationType(), ctx.getCurrentAST());
        }
        uri = URIUtil.changeHost(uri, newStringValue);
        authority = uri.getAuthority();
        uriPartChanged = true;
      }
      else if (name.equals("path")) {
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        path = newStringValue;
        uriPartChanged = true;
      }
      else if (name.equals("file")) {
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        int i = path.lastIndexOf("/");
       
        if (i != -1) {
          path = path.substring(0, i) + "/" + newStringValue;
        }
        else {
          path = path + "/" + newStringValue; 
        }
        uriPartChanged = true;
      }
      else if (name.equals("parent")) {
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
       
        int i = path.lastIndexOf("/");
        String parent = newStringValue;
       
        if (!parent.startsWith("/")) {
          parent = "/" + parent;
        }
        if (i != -1) {
          path =parent + path.substring(i);
        }
        else {
          path = parent;
        }
        uriPartChanged = true;
      }
      else if (name.equals("ls")) {
        throw new UnsupportedOperation("can not update the children of a location", ctx.getCurrentAST());
      }
      else if (name.equals("extension")) {
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        String ext = newStringValue;
       
        if (path.length() > 1) {
          int index = path.lastIndexOf('.');

          if (index == -1 && !ext.isEmpty()) {
            path = path + (!ext.startsWith(".") ? "." : "") + ext;
          }
          else if (!ext.isEmpty()) {
            path = path.substring(0, index) + (!ext.startsWith(".") ? "." : "") + ext;
          }
          else {
            path = path.substring(0, index);
          }
        }
        uriPartChanged = true;
      }
      else if (name.equals("top")) {
        if (replType.isString()) {
          URI uri = URIUtil.assumeCorrect(newStringValue);
          scheme = uri.getScheme();
          authority = uri.getAuthority();
          path = uri.getPath();
          query = uri.getQuery();
          fragment = uri.getFragment();
        }
        else if (replType.isSourceLocation()) {
          ISourceLocation rep = ((ISourceLocation) repl.getValue());
          scheme = rep.getScheme();
          authority = rep.hasAuthority() ? rep.getAuthority() : null;
          path = rep.hasPath() ? rep.getPath() : null;
          query = rep.hasQuery() ? rep.getQuery() : null;
          fragment = rep.hasFragment() ? rep.getFragment() : null;
        }
        else {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        uriPartChanged = true;
      }
      else if (name.equals("fragment")) {
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        fragment = newStringValue;
        uriPartChanged = true;
      }
      else if (name.equals("query")) {
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        query= newStringValue;
        uriPartChanged = true;
      }
      else if (name.equals("user")) {
        if (!replType.isString()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
        URI uri = loc.getURI();
        if (!ctx.getResolverRegistry().supportsHost(uri)) {
          throw new UndeclaredField(name, "The scheme " + uri.getScheme() + " does not support the user field, use authority instead.", getTypeFactory().sourceLocationType(), ctx.getCurrentAST());
        }
        if (uri.getHost() != null) {
          uri = URIUtil.changeUserInformation(uri, newStringValue);
        }
        authority = uri.getAuthority();
        uriPartChanged = true;
      }
      else if (name.equals("port")) {
        if (!replType.isInteger()) {
          throw new UnexpectedType(getTypeFactory().stringType(), replType, ctx.getCurrentAST());
        }
       
        URI uri = loc.getURI();
        if (!ctx.getResolverRegistry().supportsHost(uri)) {
          throw new UndeclaredField(name, "The scheme " + uri.getScheme() + " does not support the port field, use authority instead.", getTypeFactory().sourceLocationType(), ctx.getCurrentAST());
        }
        if (uri.getHost() != null) {
          int port = Integer.parseInt(((IInteger) repl.getValue()).getStringRepresentation());
          uri = URIUtil.changePort(uri, port);
        }
        authority = uri.getAuthority();
        uriPartChanged = true;
      }
      else if (name.equals("length")){
        if (!replType.isInteger()) {
          throw new UnexpectedType(getTypeFactory().integerType(), replType, ctx.getCurrentAST());
        }
        iLength = ((IInteger) replValue).intValue();
       
        if (iLength < 0) {
          throw RuntimeExceptionFactory.illegalArgument(replValue, ctx.getCurrentAST(), ctx.getStackTrace());
        }
      }
      else if (name.equals("offset")){
        if (!replType.isInteger()) {
          throw new UnexpectedType(getTypeFactory().integerType(), replType, ctx.getCurrentAST());
        }
        iOffset = ((IInteger) replValue).intValue();
       
        if (iOffset < 0) {
          RuntimeExceptionFactory.illegalArgument(replValue, ctx.getCurrentAST(), ctx.getStackTrace());
        }
      }
      else if (name.equals("begin")) {
        if (!replType.isSubtypeOf(intTuple)) {
          throw new UnexpectedType(intTuple, replType, ctx.getCurrentAST());
        }
        iBeginLine = ((IInteger) ((ITuple) replValue).get(0)).intValue();
        iBeginColumn = ((IInteger) ((ITuple) replValue).get(1)).intValue();
       
        if (iBeginColumn < 0 || iBeginLine < 0) {
          throw RuntimeExceptionFactory.illegalArgument(replValue, ctx.getCurrentAST(), ctx.getStackTrace());
        }
      }
      else if (name.equals("end")) {
        if (!replType.isSubtypeOf(intTuple)) {
          throw new UnexpectedType(intTuple, replType, ctx.getCurrentAST());
        }
        iEndLine = ((IInteger) ((ITuple) replValue).get(0)).intValue();
        iEndColumn = ((IInteger) ((ITuple) replValue).get(1)).intValue();
       
View Full Code Here

      bindings.put(Factory.TypeParam, new TypeReifier(VF).symbolToType((IConstructor) symbol.getValue(), (IMap) declarations.getValue()));
     
      IValue val = VF.constructor(Factory.Type_Reified.instantiate(bindings), symbol.getValue(), declarations.getValue());
     
      bindings.put(Factory.TypeParam, TF.valueType());
      Type typ = Factory.Type.instantiate(bindings);
     
      return ResultFactory.makeResult(typ, val, __eval);
    }
View Full Code Here

    @Override
    public Result<IValue> interpret(IEvaluator<Result<IValue>> eval) {
      eval.setCurrentAST(this);
      eval.notifyAboutSuspension(this);     

      Type t = getType().typeOf(eval.getCurrentEnvt(), false, eval);
      return new TypeReifier(eval.__getVf()).typeToValue(t, eval);
    }
View Full Code Here

  public Type getType(Environment env, HashMap<String,IVarPattern> patternVars) {
    if(patternSize == 0){
      return tf.setType(tf.voidType());
    }
   
    Type elemType = tf.voidType();
    for(int i = 0; i < patternSize; i++){
      IMatchingResult child = patternChildren.get(i);
      Type childType = child.getType(env, patternVars);
      patternVars = merge(patternVars, patternChildren.get(i).getVariables());
      if(debug)System.err.println(" i = " + i + ": " + patternChildren.get(i) + ", type = " + childType);
      boolean isMultiVar = child instanceof MultiVariablePattern || child instanceof TypedMultiVariablePattern;
       
      if(childType.isSet() && isMultiVar){
        elemType = elemType.lub(childType.getElementType());
      } else {
        elemType = elemType.lub(childType);
      }
    }
    if(debug)System.err.println("SetPattern.getType: " + this + " returns " + tf.setType(elemType));
View Full Code Here

      IMatchingResult child = patternChildren.get(i);
      if(debug)System.err.println("child = " + child);
     
      if (child instanceof TypedMultiVariablePattern) {
        TypedMultiVariablePattern tmvVar = (TypedMultiVariablePattern) child;
        Type childType = child.getType(env, null);
        String name = tmvVar.getName();
       
        if (!tmvVar.isAnonymous() && allVars.containsKey(name)) {
          throw new RedeclaredVariable(name, getAST());
        }
       
        if(childType.comparable(staticSubjectElementType)
            || (tmvVar.bindingInstance() && childType.comparable(staticSetSubjectType))) {
          tmvVar.covertToSetType();
          if (!tmvVar.isAnonymous()) {
            patVars.add(name);
            allVars.put(name,  (IVarPattern)child);
          }
          varName[nVar] = name;
          varPat[nVar] = child;
          isSetVar[nVar] = true;
          isBinding[nVar] = true;
          isNested[nVar] = false;
          ++nVar;
        } else {
          hasNext = false;
          return;
        }
      } else if(child instanceof TypedVariablePattern){
        TypedVariablePattern patVar = (TypedVariablePattern) child;
        Type childType = child.getType(env, null);
        String name = ((TypedVariablePattern)child).getName();
        if(!patVar.isAnonymous() && allVars.containsKey(name)){
          throw new RedeclaredVariable(name, getAST());
        }
        if(childType.comparable(staticSubjectElementType)){
          /*
           * An explicitly declared set or element variable.
           */
          if(!patVar.isAnonymous()){
            patVars.add(name);
            allVars.put(name, (IVarPattern)child);
          }
          varName[nVar] = name;
          varPat[nVar] = child;
          isSetVar[nVar] = false;
          isBinding[nVar] = true;
          isNested[nVar] = false;
          nVar++;
        } else {
          hasNext = false;
          return;
          // We would like to throw new UnexpectedType(setSubject.getType(), childType, getAST());
          // but we can't do this in the context of a visit, because we might actually visit another set!
        }
       
      } else if(child instanceof MultiVariablePattern){
        /*
         * Explicitly declared set variable
         */
        MultiVariablePattern multiVar = (MultiVariablePattern) child;
        String name = multiVar.getName();

        varName[nVar] = name;
        varPat[nVar] = child;
        isSetVar[nVar] = true;
        isBinding[nVar] = true;
        isNested[nVar] = false;
        nVar++;
      } else if(child instanceof QualifiedNamePattern){
        /*
         * Use of a variable
         */
        QualifiedNamePattern qualName = (QualifiedNamePattern) child;
        String name = qualName.getName();
        if (!qualName.isAnonymous() && allVars.containsKey(name)) {
          /*
           * A set/element variable that was declared earlier in the pattern itself,
           * or in a preceding nested pattern element.
           */
          if(!patVars.contains(name)){
            /*
             * It occurred in an earlier nested subpattern.
             */
            varName[nVar] = name;
            varPat[nVar] = child;
            // If is was declared as set in the current pattern then we are sure it is a set variable,
            // otherwise we assume for now that it is not but we check this again later in matchVar.
            isSetVar[nVar] = declaredAsSetVar(name);
            isBinding[nVar] = false;
            isNested[nVar] = false;
            nVar++;
          } else {
            /*
             * Ignore it (we are dealing with sets, remember).
             */
          }
        } else if(qualName.isAnonymous()){
          varName[nVar] = name;
          varPat[nVar] = child;
          isSetVar[nVar] = false;
          isBinding[nVar] = false;
          isNested[nVar] = false;
          nVar++;
        } else  {
          /*
           * A non-anonymous variable, not seen before.
           */
          if(debug)System.err.println("Non-anonymous var, not seen before: " + name);
         
          Result<IValue> varRes = env.getVariable(name);
         
          if(varRes == null || qualName.bindingInstance()){
            // Completely new variable that was not yet declared in this pattern or its subpatterns
            varName[nVar] = name;
            varPat[nVar] = child;
            isSetVar[nVar] = false;
            isBinding[nVar] = true;
            isNested[nVar] = false;
            nVar++;
            // TODO: Why is this here? The pattern also declares the variable,
            // so this just causes errors when we use variables in set patterns.
            // env.declareVariable(staticSubjectElementType, name);
          } else {
              if(varRes.getValue() != null){
                  Type varType = varRes.getType();
                  if (varType.comparable(staticSetSubjectType)){
                    /*
                     * A set variable declared in the current scope: add its elements
                     */
                    fixedSetElements = fixedSetElements.union((ISet)varRes.getValue());
                  } else if(varType.comparable(staticSubjectElementType)){
                    /*
                     * An element variable in the current scope, add its value.
                     */
                    fixedSetElements = fixedSetElements.insert(varRes.getValue());
                  } else {
                    hasNext = false;
                    return;
                    // can't throw type error: throw new UnexpectedType(staticSetSubjectType,varType, getAST());
                  }
              }
              else {
                // Support pre-declared set variables
             
                if(varRes.getType().comparable(staticSetSubjectType) || varRes.getType().comparable(staticSubjectElementType)){
                /*
                 * An explicitly declared set or element variable.
                 */
                if(!name.equals("_")){
                  patVars.add(name);
                  allVars.put(name, (IVarPattern) child);
                }
                varName[nVar] = name;
                varPat[nVar] = child;
                isSetVar[nVar] = varRes.getType().isSet();
                isBinding[nVar] = false;
                isNested[nVar] = false;
                nVar++;
                }
              }
            }
        }
      } else if(child instanceof LiteralPattern){
        /*
         * A literal pattern: add it to the set of fixed element
         */
        IValue lit = ((LiteralPattern) child).toIValue(env);
        Type childType = child.getType(env, null);
        if(!childType.comparable(staticSubjectElementType)){
//          throw new UnexpectedType(setSubject.getType(), childType, getAST());
          hasNext = false;
          return;
        }
        fixedSetElements = fixedSetElements.insert(lit);
        if(debug)System.err.println("fixedSetElements => " + fixedSetElements);
      } else {
        /*
         * All other cases of a nested pattern that is not a variable or a literal.
         */
        Type childType = child.getType(env, null);
        if(!childType.comparable(staticSubjectElementType)){
          hasNext = false;
          return;
          // can't throw type error: throw new UnexpectedType(setSubject.getType(), childType, getAST());
        }
        java.util.List<IVarPattern> childVars = child.getVariables();
View Full Code Here

TOP

Related Classes of org.eclipse.imp.pdb.facts.type.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.