Exemple #1
0
 private void checkRecord(Type eltType, Record record, IEvaluatorContext ctx) {
   // TODO: not all inconsistencies are detected yet
   // probably because absent values get type void
   // but are nevertheless initialized eventually
   // to 0, false, or "".
   if (record.getType().isSubtypeOf(eltType)) {
     return;
   }
   if (eltType.isTuple()) {
     int expectedArity = eltType.getArity();
     int actualArity = record.getType().getArity();
     if (expectedArity == actualArity) {
       return;
     }
     throw RuntimeExceptionFactory.illegalTypeArgument(
         "Arities of actual type and requested type are different ("
             + actualArity
             + " vs "
             + expectedArity
             + ")",
         ctx.getCurrentAST(),
         ctx.getStackTrace());
   }
   throw RuntimeExceptionFactory.illegalTypeArgument(
       "Invalid tuple " + record + " for requested field " + eltType,
       ctx.getCurrentAST(),
       ctx.getStackTrace());
 }
 /* (non-Javadoc)
  * @see org.rascalmpl.tasks.ITaskRegistry#registerProducer(org.rascalmpl.tasks.ITask)
  */
 @Override
 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);
       } else {
         producers.put(key, producer);
       }
     }
   } finally {
     lock.unlock();
   }
 }
 /* (non-Javadoc)
  * @see org.rascalmpl.tasks.ITaskRegistry#unregisterProducer(org.rascalmpl.tasks.ITask)
  */
 @Override
 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());
           }
           if (map.isEmpty()) keyedProducers.remove(key1);
           else keyedProducers.put(key1, map);
         }
       } else {
         if (producers.get(key) == producer) producers.remove(key);
       }
     }
   } finally {
     lock.unlock();
   }
 }