Package anvil.script.statements

Source Code of anvil.script.statements.NamespaceStatement

/*
* $Id: NamespaceStatement.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.codec.ConstantPool;
import anvil.codec.Code;
import anvil.codec.ClassRoom;
import anvil.codec.Field;
import anvil.codec.Method;
import anvil.doc.Doc;
import anvil.doc.DocParser;
import anvil.ErrorListener;
import anvil.parser.Tag;
import anvil.script.Type;
import anvil.script.Scope;
import anvil.script.Module;
import anvil.script.compiler.ByteCompiler;
import anvil.script.CompilableFunction;
import anvil.script.expression.Expression;
import anvil.script.parser.TemplateParser;
import anvil.java.util.Hashlist;
import java.io.IOException;
import java.util.Enumeration;

/**
* class NamespaceStatement
*
* @author: Jani Lehtim�ki
*/
public class NamespaceStatement extends DefinitionStatement implements Scope
{

  protected int _poplevel = 0;


  public NamespaceStatement(Location location, DefinitionStatement parent)
  {
    super(parent, location);
  }


  public NamespaceStatement(Location location, DefinitionStatement parent, String name, String document)
  {
    super(parent, location, name, DocParser.parseNamespace(name, document));
    setName(name);
  }
 

  public int typeOf()
  {
    return Statement.ST_NAMESPACE;
  }


  public String name()
  {
    return "namespace";
  }
 

  public void setName(String name)
  {
    _name = name;
    _descriptor = _parent.getDescriptor() + "$n_" + _name;
  }
 

  public void setPopLevel(int level)
  {
    _poplevel = level;
  }
 

  public int getType()
  {
    return NAMESPACE;
  }
 
 
  public VariableStatement declare(Location location, String name, Expression expr, String document, boolean statik)
  {
    VariableStatement var = new StaticVariableStatement(location, this, name, expr, document);
    declare(var);
    return var;
  }
 
  public Type lookupDeclaration(String name)
  {
    Type type = (Type)_types.get(name);
    if (type != null) {
      return type;
    }
    return super.lookupDeclaration(name);
  }


  public void parse(TemplateParser parser, Tag tag)
  {
    super.parse(parser, tag);
  }
 

  public void onCharacters(TemplateParser parser, String cdata)
  {
  }

 
  public boolean onTag(TemplateParser parser, int type, Tag tag)
  {
    switch(type) {
    case ST_TAG:
      break;
     
    case ST_IMPORT:
      onImport(parser, tag);
      break;
     
    case ST_VAR:
      onVar(parser, tag);
      break;
   
    case ST_CONST:
      onConst(parser, tag);
      break;

    case ST_FUNCTION:
      onFunction(parser, type, tag);
      break;
     
    case ST_CLASS:
      onClass(parser, type, tag);
      break;
     
    case ST_NAMESPACE:
      onNamespace(parser, type, tag);
      break;

    case ST_ENDNAMESPACE:
      while(_poplevel-- > 0) {
        parser.pop();
      }
      break;
     
    default:
      return false;
     
    }
    return true;
  }


  public void check(ErrorListener context)
  {
    super.check(context);
  }



  public void compile(ByteCompiler context)
  {
    ClassRoom clazz = context.getClassRoom().createClass(getDescriptor(), "n_"+_name);
    clazz.setAccessFlags(context.ACC_PUBLIC);
    ConstantPool pool = clazz.getPool();
    context.pushClass(clazz);
    Field typefield1 = clazz.createField("_class", "Lanvil/script/compiler/CompiledNamespace;", Code.ACC_PUBLIC|Code.ACC_STATIC);
    Field typefield2 = clazz.createField("_type", "Lanvil/core/Any;", Code.ACC_PUBLIC|Code.ACC_STATIC);
    clazz.setSuperClassname(context.TYPE_OBJECT);
    clazz.setAccessFlags(Code.ACC_SUPER|Code.ACC_PUBLIC);

    compileMembers(context, _types.size(), _types.elements());

    Code code = clazz.getStatic().getCode();
    context.pushCode(code);
    //code.println("INTERFACE-START:"+getDescriptor());
    code.getstatic(pool.addFieldRef(_parent.getDescriptor(), "_members", "[Ljava/lang/Object;"));
    code.pop();
    //code.println("INTERFACE-END:"+getDescriptor());
    code.vreturn();
    context.popCode();

    super.compile(context);
   
    context.popClass();
  }


}
TOP

Related Classes of anvil.script.statements.NamespaceStatement

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.