Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright The Sett Ltd, 2005 to 2014.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.thesett.aima.logic.fol.wam.debugger;
 
 import java.util.List;
 
InternalMemoryLayoutBean represents com.thesett.aima.logic.fol.wam.machine.WAMMemoryLayout as a Java bean, and adds the ability to attach a java.beans.PropertyChangeListener to it. The change listener will be notified when any registers or flags change value.

CRC Card
Responsibilities Collaborations
Provide change notification on registers and flags describing the memory layout.

Author(s):
Rupert Smith
 
 public class InternalMemoryLayoutBean extends WAMMemoryLayout implements RegisterModel
 {
    
Defines the names of the machine registers.
 
     public static final String[] REGISTER_NAMES =
         new String[]
         {
             "regBase""regSize""heapBase""heapSize""stackBase""stackSize""trailBase""trailSize""pdlBase",
             "pdlSize"
         };

    
Defines the names of the machine flags.
 
     public static final String[] FLAG_NAMES = new String[] {};

    
Holds any property change listener to notify of register value changes.
 
     private PropertyChangeListener listener;

    
Creates an instance of the WAM memory layout.

Parameters:
regBase The start of the register file within the machines data area.
regSize The size of the register file.
heapBase The start of the within the machines data area.
heapSize The size of the heap.
stackBase the start of the within the machines data area.
stackSize the size of the stack.
trailBase the start of the within the machines data area.
trailSize the size of the trail.
pdlBase The start of the within the machines data area.
pdlSize The size of the pdl.
 
     public InternalMemoryLayoutBean(int regBaseint regSizeint heapBaseint heapSizeint stackBaseint stackSize,
         int trailBaseint trailSizeint pdlBaseint pdlSize)
     {
         super(regBaseregSizeheapBaseheapSizestackBasestackSizetrailBasetrailSizepdlBasepdlSize);
     }

    
Establishes a PropertyChangeListener to notify of changes to the register file or flags.

Parameters:
listener A PropertyChangeListener to notify of changes to the register file or flags.
 
     public void setPropertyChangeListener(PropertyChangeListener listener)
     {
         this. = listener;
     }

    
Updates the layout register file, with a new set of layout registers.

Parameters:
layout The new layout register values.
 
     public void updateRegisters(WAMMemoryLayout layout)
     {
         List<PropertyChangeEventchanges = delta(thislayout);
 
          = layout.regBase;
          = layout.regSize;
          = layout.heapBase;
          = layout.heapSize;
          = layout.stackBase;
          = layout.stackSize;
          = layout.trailBase;
          = layout.trailSize;
          = layout.pdlBase;
         = layout.pdlSize;
        notifyChanges(changes);
    }

    
Provides the start of the register file within the machines data area.
    public int getRegBase()
    {
        return ;
    }

    
Provides the size of the register file.
    public int getRegSize()
    {
        return ;
    }

    
Provides the start of the within the machines data area.
    public int getHeapBase()
    {
        return ;
    }

    
Provides the size of the heap.
    public int getHeapSize()
    {
        return ;
    }

    
Provides the start of the within the machines data area.
    public int getStackBase()
    {
        return ;
    }

    
Provides the size of the stack.
    public int getStackSize()
    {
        return ;
    }

    
Provides the start of the within the machines data area.
    public int getTrailBase()
    {
        return ;
    }

    
Provides the size of the trail.
    public int getTrailSize()
    {
        return ;
    }

    
Provides the start of the within the machines data area.
    public int getPdlBase()
    {
        return ;
    }

    
Provides the size of the pdl.
    public int getPdlSize()
    {
        return ;
    }

    
    public String[] getRegisterNames()
    {
        return ;
    }

    
    public String[] getFlagNames()
    {
        return ;
    }

    
    public int getRegisterSizeBytes(String name)
    {
        return 4;
    }

    
    public byte[] getRegister(String name)
    {
        return new byte[0];
    }

    
    public boolean getFlag(String name)
    {
        return false;
    }

    
Compares the current register file, with a new set, and creates a list property change notifications for any that have changed value.

Parameters:
newRegisters The new register values.
    private List<PropertyChangeEventdelta(WAMMemoryLayout oldRegistersWAMMemoryLayout newRegisters)
    {
        List<PropertyChangeEventresult = new LinkedList<PropertyChangeEvent>();
        if (oldRegisters.regBase != newRegisters.regBase)
        {
            result.add(new PropertyChangeEvent(this"regBase"oldRegisters.regBasenewRegisters.regBase));
        }
        if (oldRegisters.regSize != newRegisters.regSize)
        {
            result.add(new PropertyChangeEvent(this"regSize"oldRegisters.regSizenewRegisters.regSize));
        }
        if (oldRegisters.heapBase != newRegisters.heapBase)
        {
            result.add(new PropertyChangeEvent(this"heapBase"oldRegisters.heapBasenewRegisters.heapBase));
        }
        if (oldRegisters.heapSize != newRegisters.heapSize)
        {
            result.add(new PropertyChangeEvent(this"heapSize"oldRegisters.heapSizenewRegisters.heapSize));
        }
        if (oldRegisters.stackBase != newRegisters.stackBase)
        {
            result.add(new PropertyChangeEvent(this"stackBase"oldRegisters.stackBasenewRegisters.stackBase));
        }
        if (oldRegisters.stackSize != newRegisters.stackSize)
        {
            result.add(new PropertyChangeEvent(this"stackSize"oldRegisters.stackSizenewRegisters.stackSize));
        }
        if (oldRegisters.trailBase != newRegisters.trailBase)
        {
            result.add(new PropertyChangeEvent(this"trailBase"oldRegisters.trailBasenewRegisters.trailBase));
        }
        if (oldRegisters.trailSize != newRegisters.trailSize)
        {
            result.add(new PropertyChangeEvent(this"trailSize"oldRegisters.trailSizenewRegisters.trailSize));
        }
        if (oldRegisters.pdlBase != newRegisters.pdlBase)
        {
            result.add(new PropertyChangeEvent(this"pdlBase"oldRegisters.pdlBasenewRegisters.pdlBase));
        }
        if (oldRegisters.pdlSize != newRegisters.pdlSize)
        {
            result.add(new PropertyChangeEvent(this"pdlSize"oldRegisters.pdlSizenewRegisters.pdlSize));
        }
        return result;
    }

    
Fires off a list of property change events to any interested listeners.

Parameters:
changes The list of property changes to fire off.
    private void notifyChanges(List<PropertyChangeEventchanges)
    {
        if ( != null)
        {
            for (PropertyChangeEvent event : changes)
            {
                .propertyChange(event);
            }
        }
    }
New to GrepCode? Check out our FAQ X