001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 /* 019 * $Id: TopLevelElement.java 476471 2006-11-18 08:36:27Z minchau $ 020 */ 021 022 package org.apache.xalan.xsltc.compiler; 023 024 import java.util.Vector; 025 026 import org.apache.bcel.generic.InstructionList; 027 import org.apache.xalan.xsltc.compiler.util.ClassGenerator; 028 import org.apache.xalan.xsltc.compiler.util.ErrorMsg; 029 import org.apache.xalan.xsltc.compiler.util.MethodGenerator; 030 import org.apache.xalan.xsltc.compiler.util.Type; 031 import org.apache.xalan.xsltc.compiler.util.TypeCheckError; 032 import org.apache.xalan.xsltc.compiler.util.Util; 033 034 class TopLevelElement extends SyntaxTreeNode { 035 036 /* 037 * List of dependencies with other variables, parameters or 038 * keys defined at the top level. 039 */ 040 protected Vector _dependencies = null; 041 042 /** 043 * Type check all the children of this node. 044 */ 045 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 046 return typeCheckContents(stable); 047 } 048 049 /** 050 * Translate this node into JVM bytecodes. 051 */ 052 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 053 ErrorMsg msg = new ErrorMsg(ErrorMsg.NOT_IMPLEMENTED_ERR, 054 getClass(), this); 055 getParser().reportError(FATAL, msg); 056 } 057 058 /** 059 * Translate this node into a fresh instruction list. 060 * The original instruction list is saved and restored. 061 */ 062 public InstructionList compile(ClassGenerator classGen, 063 MethodGenerator methodGen) { 064 final InstructionList result, save = methodGen.getInstructionList(); 065 methodGen.setInstructionList(result = new InstructionList()); 066 translate(classGen, methodGen); 067 methodGen.setInstructionList(save); 068 return result; 069 } 070 071 public void display(int indent) { 072 indent(indent); 073 Util.println("TopLevelElement"); 074 displayContents(indent + IndentIncrement); 075 } 076 077 /** 078 * Add a dependency with other top-level elements like 079 * variables, parameters or keys. 080 */ 081 public void addDependency(TopLevelElement other) { 082 if (_dependencies == null) { 083 _dependencies = new Vector(); 084 } 085 if (!_dependencies.contains(other)) { 086 _dependencies.addElement(other); 087 } 088 } 089 090 /** 091 * Get the list of dependencies with other top-level elements 092 * like variables, parameteres or keys. 093 */ 094 public Vector getDependencies() { 095 return _dependencies; 096 } 097 098 }