1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 /*
   5  * Licensed to the Apache Software Foundation (ASF) under one or more
   6  * contributor license agreements.  See the NOTICE file distributed with
   7  * this work for additional information regarding copyright ownership.
   8  * The ASF licenses this file to You under the Apache License, Version 2.0
   9  * (the "License"); you may not use this file except in compliance with
  10  * the License.  You may obtain a copy of the License at
  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 
  21 package com.sun.org.apache.xalan.internal.xsltc.compiler;
  22 
  23 import com.sun.org.apache.bcel.internal.generic.InstructionList;
  24 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
  25 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
  26 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
  27 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
  28 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
  29 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
  30 import java.util.ArrayList;
  31 import java.util.List;
  32 
  33 /**
  34  * @LastModified: Oct 2017
  35  */
  36 class TopLevelElement extends SyntaxTreeNode {
  37 
  38     /*
  39      * List of dependencies with other variables, parameters or
  40      * keys defined at the top level.
  41      */
  42     protected List<SyntaxTreeNode> _dependencies = null;
  43 
  44     /**
  45      * Type check all the children of this node.
  46      */
  47     public Type typeCheck(SymbolTable stable) throws TypeCheckError {
  48         return typeCheckContents(stable);
  49     }
  50 
  51     /**
  52      * Translate this node into JVM bytecodes.
  53      */
  54     public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  55         ErrorMsg msg = new ErrorMsg(ErrorMsg.NOT_IMPLEMENTED_ERR,
  56                                     getClass(), this);
  57         getParser().reportError(FATAL, msg);
  58     }
  59 
  60     /**
  61      * Translate this node into a fresh instruction list.
  62      * The original instruction list is saved and restored.
  63      */
  64     public InstructionList compile(ClassGenerator classGen,
  65                                    MethodGenerator methodGen) {
  66         final InstructionList result, save = methodGen.getInstructionList();
  67         methodGen.setInstructionList(result = new InstructionList());
  68         translate(classGen, methodGen);
  69         methodGen.setInstructionList(save);
  70         return result;
  71     }
  72 
  73     public void display(int indent) {
  74         indent(indent);
  75         Util.println("TopLevelElement");
  76         displayContents(indent + IndentIncrement);
  77     }
  78 
  79     /**
  80      * Add a dependency with other top-level elements like
  81      * variables, parameters or keys.
  82      */
  83     public void addDependency(TopLevelElement other) {
  84         if (_dependencies == null) {
  85             _dependencies = new ArrayList<>();
  86         }
  87         if (!_dependencies.contains(other)) {
  88             _dependencies.add(other);
  89         }
  90     }
  91 
  92     /**
  93      * Get the list of dependencies with other top-level elements
  94      * like variables, parameteres or keys.
  95      */
  96     public List<SyntaxTreeNode> getDependencies() {
  97         return _dependencies;
  98     }
  99 
 100 }