FileDocCategorySizeDatePackage
MethodGenerator.javaAPI DocJava SE 6 API9957Tue Jun 10 00:22:30 BST 2008com.sun.org.apache.xalan.internal.xsltc.compiler.util

MethodGenerator

public class MethodGenerator extends MethodGen implements Constants
author
Jacek Ambroziak
author
Santiago Pericas-Geertsen

Fields Summary
protected static final int
INVALID_INDEX
private static final String
START_ELEMENT_SIG
private static final String
END_ELEMENT_SIG
private InstructionList
_mapTypeSub
private static final int
DOM_INDEX
private static final int
ITERATOR_INDEX
private static final int
HANDLER_INDEX
private Instruction
_iloadCurrent
private Instruction
_istoreCurrent
private final Instruction
_astoreHandler
private final Instruction
_aloadHandler
private final Instruction
_astoreIterator
private final Instruction
_aloadIterator
private final Instruction
_aloadDom
private final Instruction
_astoreDom
private final Instruction
_startElement
private final Instruction
_endElement
private final Instruction
_startDocument
private final Instruction
_endDocument
private final Instruction
_attribute
private final Instruction
_uniqueAttribute
private final Instruction
_namespace
private final Instruction
_setStartNode
private final Instruction
_reset
private final Instruction
_nextNode
private SlotAllocator
_slotAllocator
private boolean
_allocatorInit
private Hashtable
_preCompiled
A mapping between patterns and instruction lists used by test sequences to avoid compiling the same pattern multiple times. Note that patterns whose kernels are "*", "node()" and "@*" can between shared by test sequences.
Constructors Summary
public MethodGenerator(int access_flags, Type return_type, Type[] arg_types, String[] arg_names, String method_name, String class_name, InstructionList il, ConstantPoolGen cpg)


    
        
			      
			      
			       
	super(access_flags, return_type, arg_types, arg_names, method_name, 
	      class_name, il, cpg);
	
	_astoreHandler  = new ASTORE(HANDLER_INDEX);
	_aloadHandler   = new ALOAD(HANDLER_INDEX);
	_astoreIterator = new ASTORE(ITERATOR_INDEX);
	_aloadIterator  = new ALOAD(ITERATOR_INDEX);
	_aloadDom       = new ALOAD(DOM_INDEX);
	_astoreDom      = new ASTORE(DOM_INDEX);
	
	final int startElement =
	    cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
				      "startElement",
				      START_ELEMENT_SIG);
	_startElement = new INVOKEINTERFACE(startElement, 2);
	
	final int endElement =
	    cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
				      "endElement",
				      END_ELEMENT_SIG);
	_endElement = new INVOKEINTERFACE(endElement, 2);

	final int attribute =
	    cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
				      "addAttribute", 
				      "("
				      + STRING_SIG
				      + STRING_SIG
				      + ")V");
	_attribute = new INVOKEINTERFACE(attribute, 3);

	final int uniqueAttribute =
	    cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
				      "addUniqueAttribute", 
				      "("
				      + STRING_SIG
				      + STRING_SIG
				      + "I)V");
	_uniqueAttribute = new INVOKEINTERFACE(uniqueAttribute, 4);

	final int namespace =
	    cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
				      "namespaceAfterStartElement", 
				      "("
				      + STRING_SIG
				      + STRING_SIG
				      + ")V");
	_namespace = new INVOKEINTERFACE(namespace, 3);
	
	int index = cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
					      "startDocument",
					      "()V");
	_startDocument = new INVOKEINTERFACE(index, 1);
	
	index = cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
					  "endDocument",
					  "()V");
	_endDocument = new INVOKEINTERFACE(index, 1);
	
	
	index = cpg.addInterfaceMethodref(NODE_ITERATOR,
					  SET_START_NODE,
					  SET_START_NODE_SIG);
	_setStartNode = new INVOKEINTERFACE(index, 2);

	index = cpg.addInterfaceMethodref(NODE_ITERATOR,
					  "reset", "()"+NODE_ITERATOR_SIG);
	_reset = new INVOKEINTERFACE(index, 1);
	
	index = cpg.addInterfaceMethodref(NODE_ITERATOR, NEXT, NEXT_SIG);
	_nextNode = new INVOKEINTERFACE(index, 1);
	
	_slotAllocator = new SlotAllocator();
	_slotAllocator.initialize(getLocalVariables());
	_allocatorInit = true;
    
Methods Summary
public voidaddInstructionList(com.sun.org.apache.xalan.internal.xsltc.compiler.Pattern pattern, com.sun.org.apache.bcel.internal.generic.InstructionList ilist)
Add a pre-compiled pattern to this mode.

	_preCompiled.put(pattern, ilist);
	
public com.sun.org.apache.bcel.internal.generic.LocalVariableGenaddLocalVariable(java.lang.String name, com.sun.org.apache.bcel.internal.generic.Type type, com.sun.org.apache.bcel.internal.generic.InstructionHandle start, com.sun.org.apache.bcel.internal.generic.InstructionHandle end)
Allocates a local variable. If the slot allocator has already been initialized, then call addLocalVariable2() so that the new variable is known to the allocator. Failing to do this may cause the allocator to return a slot that is already in use.

	return (_allocatorInit) ? addLocalVariable2(name, type, start) 
	    : super.addLocalVariable(name, type, start, end);
    
public com.sun.org.apache.bcel.internal.generic.LocalVariableGenaddLocalVariable2(java.lang.String name, com.sun.org.apache.bcel.internal.generic.Type type, com.sun.org.apache.bcel.internal.generic.InstructionHandle start)

	return super.addLocalVariable(name, type,
				      _slotAllocator.allocateSlot(type),
				      start, null);
    
public final com.sun.org.apache.bcel.internal.generic.Instructionattribute()

	return _attribute;
    
public final com.sun.org.apache.bcel.internal.generic.InstructionendDocument()

	return _endDocument;
    
public final com.sun.org.apache.bcel.internal.generic.InstructionendElement()

	return _endElement;
    
public com.sun.org.apache.bcel.internal.generic.InstructionListgetInstructionList(com.sun.org.apache.xalan.internal.xsltc.compiler.Pattern pattern)
Get the instruction list for a pre-compiled pattern. Used by test sequences to avoid compiling patterns more than once.

	return (InstructionList) _preCompiled.get(pattern);
	
public intgetLocalIndex(java.lang.String name)

	return getLocalVariable(name).getIndex();
    
public com.sun.org.apache.bcel.internal.generic.LocalVariableGengetLocalVariable(java.lang.String name)

	final LocalVariableGen[] vars = getLocalVariables();
	for (int i = 0; i < vars.length; i++)
	    if (vars[i].getName().equals(name))
		return vars[i];
	return null;	
    
public com.sun.org.apache.bcel.internal.generic.InstructionloadContextNode()
by default context node is the same as current node. MK437

	return loadCurrentNode();
    
public com.sun.org.apache.bcel.internal.generic.InstructionloadCurrentNode()

	if (_iloadCurrent == null) {
	    int idx = getLocalIndex("current");
	    if (idx > 0)
		_iloadCurrent = new ILOAD(idx);
	    else
		_iloadCurrent = new ICONST(0);
	}
	return _iloadCurrent;
    
public com.sun.org.apache.bcel.internal.generic.InstructionloadDOM()

	return _aloadDom;
    
public com.sun.org.apache.bcel.internal.generic.InstructionloadHandler()

	return _aloadHandler;
    
public com.sun.org.apache.bcel.internal.generic.InstructionloadIterator()

	return _aloadIterator;
    
public final com.sun.org.apache.bcel.internal.generic.Instructionnamespace()

	return _namespace;
    
public final com.sun.org.apache.bcel.internal.generic.InstructionnextNode()

	return _nextNode;
    
public voidremoveLocalVariable(com.sun.org.apache.bcel.internal.generic.LocalVariableGen lvg)

	_slotAllocator.releaseSlot(lvg);
	super.removeLocalVariable(lvg);
    
public final com.sun.org.apache.bcel.internal.generic.Instructionreset()

	return _reset;
    
public voidsetMaxLocals()

	
	// Get the current number of local variable slots
	int maxLocals = super.getMaxLocals();
	int prevLocals = maxLocals;

	// Get numer of actual variables
	final LocalVariableGen[] localVars = super.getLocalVariables();
	if (localVars != null) {
	    if (localVars.length > maxLocals)
		maxLocals = localVars.length;
	}

	// We want at least 5 local variable slots (for parameters)
	if (maxLocals < 5) maxLocals = 5;

	super.setMaxLocals(maxLocals);
    
public final com.sun.org.apache.bcel.internal.generic.InstructionsetStartNode()

	return _setStartNode;
    
public final com.sun.org.apache.bcel.internal.generic.InstructionstartDocument()

	return _startDocument;
    
public final com.sun.org.apache.bcel.internal.generic.InstructionstartElement()

	return _startElement;
    
public com.sun.org.apache.bcel.internal.generic.InstructionstoreContextNode()

	return storeCurrentNode();
    
public com.sun.org.apache.bcel.internal.generic.InstructionstoreCurrentNode()

	return _istoreCurrent != null
	    ? _istoreCurrent
	    : (_istoreCurrent = new ISTORE(getLocalIndex("current")));
    
public com.sun.org.apache.bcel.internal.generic.InstructionstoreDOM()

	return _astoreDom;
    
public com.sun.org.apache.bcel.internal.generic.InstructionstoreHandler()

	return _astoreHandler;
    
public com.sun.org.apache.bcel.internal.generic.InstructionstoreIterator()

	return _astoreIterator;
    
public final com.sun.org.apache.bcel.internal.generic.InstructionuniqueAttribute()

    	return _uniqueAttribute;