All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type Maven / Gradle / Ivy

The newest version!
/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
 *
 * The contents of this file are subject to the terms of either the GNU
 * General Public License Version 2 only ("GPL") or the Common Development
 * and Distribution License("CDDL") (collectively, the "License").  You
 * may not use this file except in compliance with the License.  You can
 * obtain a copy of the License at
 * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
 * or packager/legal/LICENSE.txt.  See the License for the specific
 * language governing permissions and limitations under the License.
 *
 * When distributing the software, include this License Header Notice in each
 * file and include the License file at packager/legal/LICENSE.txt.
 *
 * GPL Classpath Exception:
 * Oracle designates this particular file as subject to the "Classpath"
 * exception as provided by Oracle in the GPL Version 2 section of the License
 * file that accompanied this code.
 *
 * Modifications:
 * If applicable, add the following below the License Header, with the fields
 * enclosed by brackets [] replaced by your own identifying information:
 * "Portions Copyright [year] [name of copyright owner]"
 *
 * Contributor(s):
 * If you wish your version of this file to be governed by only the CDDL or
 * only the GPL Version 2, indicate your decision by adding "[Contributor]
 * elects to include this software in this distribution under the [CDDL or GPL
 * Version 2] license."  If you don't indicate a single choice of license, a
 * recipient has the option to distribute your version of this file under
 * either the CDDL, the GPL Version 2 or to extend the choice of license to
 * its licensees as provided above.  However, if you add GPL Version 2 code
 * and therefore, elected the GPL Version 2 license, then the option applies
 * only if the new code is made subject to such option by the copyright
 * holder.
 *
 *
 * This file incorporates work covered by the following copyright and
 * permission notice:
 *
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * $Id: Type.java,v 1.11 2010-11-01 04:34:20 joehw Exp $
 */
package com.sun.org.apache.xalan.internal.xsltc.compiler.util;

import com.sun.org.apache.bcel.internal.generic.BranchInstruction;
import com.sun.org.apache.bcel.internal.generic.Instruction;
import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants;
import com.sun.org.apache.xalan.internal.xsltc.compiler.FlowList;
import com.sun.org.apache.xalan.internal.xsltc.compiler.NodeTest;

/**
 * @author Jacek Ambroziak
 * @author Santiago Pericas-Geertsen
 * @author Morten Jorgensen
 */
public abstract class Type implements Constants {
    public static final Type Int        = new IntType();
    public static final Type Real       = new RealType();
    public static final Type Boolean    = new BooleanType();
    public static final Type NodeSet    = new NodeSetType();
    public static final Type String     = new StringType();
    public static final Type ResultTree = new ResultTreeType();
    public static final Type Reference  = new ReferenceType();
    public static final Type Void       = new VoidType();    
    
    public static final Type Object       = new ObjectType(java.lang.Object.class);
    public static final Type ObjectString = new ObjectType(java.lang.String.class);

    public static final Type Node       = new NodeType(NodeTest.ANODE);
    public static final Type Root       = new NodeType(NodeTest.ROOT);
    public static final Type Element    = new NodeType(NodeTest.ELEMENT);
    public static final Type Attribute  = new NodeType(NodeTest.ATTRIBUTE);
    public static final Type Text       = new NodeType(NodeTest.TEXT);
    public static final Type Comment    = new NodeType(NodeTest.COMMENT);
    public static final Type Processing_Instruction = new NodeType(NodeTest.PI);

    /**
     * Factory method to instantiate object types. Returns a pre-defined
     * instance for "java.lang.Object" and "java.lang.String".
     */
    public static Type newObjectType(String javaClassName) {
        if (javaClassName == "java.lang.Object") {
            return Type.Object;
        }
        else if (javaClassName == "java.lang.String") {
            return Type.ObjectString;
        } 
        else {
            //
            java.security.AccessControlContext acc = java.security.AccessController.getContext();
            acc.checkPermission(new RuntimePermission("getContextClassLoader"));
            return new ObjectType(javaClassName);
        }
    }
    
   /**
     * Factory method to instantiate object types. Returns a pre-defined
     * instance for java.lang.Object.class and java.lang.String.class.
     */
    public static Type newObjectType(Class clazz) {
        if (clazz == java.lang.Object.class) {
            return Type.Object;
        }
        else if (clazz == java.lang.String.class) {
            return Type.ObjectString;
        }
        else {
            return new ObjectType(clazz);
        }
    }
    
    /**
     * Returns a string representation of this type.	
     */
    public abstract String toString();

    /**
     * Returns true if this and other are identical types.
     */
    public abstract boolean identicalTo(Type other);

    /**
     * Returns true if this type is a numeric type. Redefined in NumberType.
     */
    public boolean isNumber() {
	return false;
    }

    /**
     * Returns true if this type has no object representaion. Redefined in
     * ResultTreeType.
     */
    public boolean implementedAsMethod() {
	return false;
    }

    /**
     * Returns true if this type is a simple type. Redefined in NumberType,
     * BooleanType and StringType.
     */
    public boolean isSimple() {
	return false;
    }

    public abstract com.sun.org.apache.bcel.internal.generic.Type toJCType();

    /**
     * Returns the distance between two types. This measure is used to select
     * overloaded functions/operators. This method is typically redefined by
     * the subclasses.
     */
    public int distanceTo(Type type) {
	return type == this ? 0 : Integer.MAX_VALUE;
    }

    /**
     * Returns the signature of an internal type's external representation.
     */
    public abstract String toSignature();

    /**
     * Translates an object of this type to an object of type
     * type. 
     * Expects an object of the former type and pushes an object of the latter.
     */
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 
			    Type type) {
	ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
				    toString(), type.toString());
	classGen.getParser().reportError(Constants.FATAL, err);
    }

    /**
     * Translates object of this type to an object of type type. 
     * Expects an object of the former type and pushes an object of the latter
     * if not boolean. If type type is boolean then a branchhandle
     * list (to be appended to the false list) is returned.
     */
    public FlowList translateToDesynthesized(ClassGenerator classGen, 
					     MethodGenerator methodGen, 
					     Type type) {
	FlowList fl = null;
	if (type == Type.Boolean) {
	    fl = translateToDesynthesized(classGen, methodGen,
					  (BooleanType)type);
	}
	else {
	    translateTo(classGen, methodGen, type);
	}
	return fl;
    }

    /**
     * Translates an object of this type to an non-synthesized boolean. It
     * does not push a 0 or a 1 but instead returns branchhandle list to be
     * appended to the false list.
     */ 
    public FlowList translateToDesynthesized(ClassGenerator classGen, 
					     MethodGenerator methodGen, 
					     BooleanType type) {
	ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
				    toString(), type.toString());
	classGen.getParser().reportError(Constants.FATAL, err);
	return null;
    }

    /**
     * Translates an object of this type to the external (Java) type denoted
     * by clazz. This method is used to translate parameters 
     * when external functions are called.
     */ 
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 
			    Class clazz) {
	ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
				    toString(), clazz.getClass().toString());
	classGen.getParser().reportError(Constants.FATAL, err);
    }

    /**
     * Translates an external (Java) type denoted by clazz to 
     * an object of this type. This method is used to translate return values 
     * when external functions are called.
     */ 
    public void translateFrom(ClassGenerator classGen, MethodGenerator methodGen,
			      Class clazz) {
	ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
				    clazz.getClass().toString(), toString());
	classGen.getParser().reportError(Constants.FATAL, err);
    }

    /**
     * Translates an object of this type to its boxed representation.
     */ 
    public void translateBox(ClassGenerator classGen,
			     MethodGenerator methodGen) {
	ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
				    toString(), "["+toString()+"]");
	classGen.getParser().reportError(Constants.FATAL, err);
    }

    /**
     * Translates an object of this type to its unboxed representation.
     */ 
    public void translateUnBox(ClassGenerator classGen,
			       MethodGenerator methodGen) {
	ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
				    "["+toString()+"]", toString());
	classGen.getParser().reportError(Constants.FATAL, err);
    }

    /**
     * Returns the class name of an internal type's external representation.
     */
    public String getClassName() {
	return(EMPTYSTRING);
    }

    public Instruction ADD() {
	return null;		// should never be called
    }

    public Instruction SUB() {
	return null;		// should never be called
    }

    public Instruction MUL() {
	return null;		// should never be called
    }

    public Instruction DIV() {
	return null;		// should never be called
    }

    public Instruction REM() {
	return null;		// should never be called
    }

    public Instruction NEG() {
	return null;		// should never be called
    }

    public Instruction LOAD(int slot) {
	return null;		// should never be called
    }
	
    public Instruction STORE(int slot) {
	return null;		// should never be called
    }

    public Instruction POP() {
	return POP;
    }

    public BranchInstruction GT(boolean tozero) {
	return null;		// should never be called
    }

    public BranchInstruction GE(boolean tozero) {
	return null;		// should never be called
    }

    public BranchInstruction LT(boolean tozero) {
	return null;		// should never be called
    }

    public BranchInstruction LE(boolean tozero) {
	return null;		// should never be called
    }

    public Instruction CMP(boolean less) {
	return null;		// should never be called
    }
	
    public Instruction DUP() {
	return DUP;	// default
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy