/*
 * Bytecode Analysis Framework
 * Copyright (C) 2005, University of Maryland
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package edu.umd.cs.findbugs.ba.constant;

import org.apache.bcel.generic.ConstantPoolGen;
import org.apache.bcel.generic.LDC;
import org.apache.bcel.generic.LDC2_W;

import edu.umd.cs.findbugs.ba.AbstractFrameModelingVisitor;

/**
 * Visitor to model the effect of bytecode instructions
 * on ConstantFrames.
 * 
 * <p>For now, only String constants are modeled.
 * In the future we can add other kinds of constants.</p>
 * 
 * @see edu.umd.cs.findbugs.ba.constant.ConstantAnalysis
 * @author David Hovemeyer
 */
public class ConstantFrameModelingVisitor
		extends AbstractFrameModelingVisitor<Constant, ConstantFrame> {

	public ConstantFrameModelingVisitor(ConstantPoolGen cpg) {
		super(cpg);
	}
			
	//@Override
	public Constant getDefaultValue() {
		return Constant.NOT_CONSTANT;
	}
	
	//@Override
	public void visitLDC(LDC obj) {
		Object value = obj.getValue(getCPG());
		if (value instanceof String) {
			Constant c = new Constant(value);
			getFrame().pushValue(c);
		} else {
			// FIXME: other kinds of constants
			super.visitLDC(obj);
		}
	}
	
	//@Override
	public void visitLDC2_W(LDC2_W obj) {
		Object value = obj.getValue(getCPG());
		if (value instanceof String) {
			Constant c = new Constant(value);
			getFrame().pushValue(c);
		} else {
			// FIXME: other kinds of constants
			super.visitLDC2_W(obj);
		}
	}

}

@@ -1932,159 +1932,8 @@
 ) %7B%0A
-%09%09Object value = obj.getValue(getCPG());%0A%09%09if (value instanceof String) %7B%0A%09%09%09Constant c = new Constant(value);%0A%09%09%09getFrame().pushValue(c);%0A%09%09%7D else %7B%0A%09
 %09%09//
@@ -1959,33 +1959,32 @@
  of constants%0A%09%09
-%09
 super.visitLDC2_
@@ -1991,18 +1991,14 @@
 W(obj);%0A
-%09%09%7D%0A
 %09%7D%0A%0A%7D%0A

LDC2_W instructions only return Numbers as the constant value, never Strings.