Package anvil.script.statements

Source Code of anvil.script.statements.StaticVariableStatement

/*
* $Id: StaticVariableStatement.java,v 1.5 2002/09/16 08:05:06 jkl Exp $
*
* Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
*
* Use is subject to license terms, as defined in
* Anvil Sofware License, Version 1.1. See LICENSE
* file, or http://njet.org/license-1.1.txt
*/
package anvil.script.statements;

import anvil.Location;
import anvil.core.Any;
import anvil.codec.ClassRoom;
import anvil.codec.ConstantPool;
import anvil.codec.Code;
import anvil.doc.Doc;
import anvil.script.StaticVariableType;
import anvil.script.Scope;
import anvil.script.compiler.ByteCompiler;
import anvil.script.expression.Expression;
import anvil.script.expression.AssignmentNode;
import anvil.script.expression.ConstantNode;
import anvil.script.expression.ExpressionList;
import anvil.script.expression.StaticVariableNode;
import java.io.IOException;
import java.lang.reflect.Field;

/**
* class StaticVariableStatement
*
* @author: Jani Lehtim�ki
*/
public class StaticVariableStatement extends VariableStatement implements StaticVariableType
{

  protected Any _value;
 

  public StaticVariableStatement(Location location, DefinitionStatement parent, String name, Expression expr, String document)
  {
    super(location, parent, name, expr, document);
  }


  public StaticVariableStatement(Location location, DefinitionStatement parent, String name, Expression expr, Doc document)
  {
    super(location, parent, name, expr, document);
  }

  public int getType()
  {
    return STATIC_VARIABLE;
  }
 

  public Any getValue()
  {
    if (_value == null) {
      _value = Any.UNDEFINED;
      if (hasConstantInitializer()) {
        _value = _expression.eval();
      }
    }
    return _value;
  }


  public boolean isStaticRegion()
  {
    return true;
  }
 
 
  public Expression createStaticInitializer()
  {
    Location location = _expression.getLocation();
    AssignmentNode assignment = new AssignmentNode(location, 2);
    assignment.setChild(0, new StaticVariableNode(this));
    assignment.setChild(1, new ConstantNode(getValue()));
    return new Expression(assignment, location);
  }
 
 
  public Expression createInitializer()
  {
    Location location = _expression.getLocation();
    AssignmentNode assignment = new AssignmentNode(location, 2);
    assignment.setChild(0, new StaticVariableNode(this));
    assignment.setChild(1, _expression.getChild());
    return new Expression(assignment, location);
  }

 
  public int getTypeRef(ConstantPool pool)
  {
    return pool.addFieldRef(_parent.getTypeRef(pool), "s_"+_name, "Lanvil/core/Any;");
  }
 

  public void compile(ByteCompiler context)
  {
    ClassRoom room = context.getClassRoom();
    room.createField("s_"+_name, "Lanvil/core/Any;", context.ACC_PUBLIC|context.ACC_STATIC);
 
 
}
TOP

Related Classes of anvil.script.statements.StaticVariableStatement

TOP
Copyright © 2018 www.massapi.com. 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.