All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.snapscript.tree.function.ScopeCalculator Maven / Gradle / Ivy

There is a newer version: 1.4.6
Show newest version
package org.snapscript.tree.function;

import java.util.ArrayList;
import java.util.List;

import org.snapscript.core.scope.Scope;
import org.snapscript.core.scope.index.Address;
import org.snapscript.core.scope.index.ScopeIndex;

public class ScopeCalculator {   

   private final List allocations;
   private final ScopeAllocationBuilder builder;
   
   public ScopeCalculator(){
      this.allocations = new ArrayList();
      this.builder = new ScopeAllocationBuilder();
   }

   public void define(Scope scope) throws Exception {
      ScopeIndex index = scope.getIndex();   
      
      for(Address address : index){
         ScopeAllocation allocation = builder.allocate(scope, address);
         
         if(allocation != null) {
            allocations.add(allocation);
         }
      }
   }
   
   public Scope compile(Scope scope) throws Exception {
      for(ScopeAllocation allocation : allocations) {
         allocation.compile(scope);
      }
      return scope;
   }
   
   public Scope calculate(Scope scope) throws Exception {
      for(ScopeAllocation allocation : allocations) {
         allocation.allocate(scope);
      }
      return scope;
   }  
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy