/* ILEngineer - Crummy .NET Decompiler
 * Copyright (C) 2001-2002  Jay Freeman (saurik)
*/

/*
 *        Redistribution and use in source and binary
 * forms, with or without modification, are permitted
 * provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the
 *    above copyright notice, this list of conditions
 *    and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the
 *    above copyright notice, this list of conditions
 *    and the following disclaimer in the documentation
 *    and/or other materials provided with the
 *    distribution.
 * 3. The name of the author may not be used to endorse
 *    or promote products derived from this software
 *    without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include "ilengineer/Operation.h"
#include "ilengineer/Ops/MSIL/Or.h"
#include "ilengineer/Ops/MSIL/LoadLocal.h"
#include "ilengineer/Ops/MSIL/StoreLocal.h"
#include "ilengineer/Ops/MSIL/StoreStaticField.h"

namespace ILEngineer {
namespace Ops {
namespace ILE {

	/*class OpCall : public Operation {
	  private:

		size_t m_Which;

	  public:
		OpCall *getOpCall(Ops::MSIL::Call *call) {
			std::wstring name = call->getMember().getName();
			if (name.substr(0, 3) != L"op_")
				return NULL;
			name = name.substr(3);
			for (size_t i(0); i < sizeof(Operators) / sizeof(Operator); i++) {
			}
		}

		std::wstring					getOp()		{ return Operators[m_Which].op; }
		std::wstring					getName()	{ return Operators[m_Which].name; }
	};*/

	class OrEqualsField : public Operation {
	  protected:
		Metallurgy::Member *m_Member;

	  public:
		OrEqualsField(Blocks::Method *method, Ops::MSIL::Or *or, Ops::MSIL::StoreField *field) :
			Operation(method, or->getOffset()),
			m_Member(field->getMember())
		{
			Tack(field->getObj());
			field->toTrash();
			delete or->getValue1();
			Tack(or->getValue2());
			or->toTrash();
		}

		Metallurgy::Member &		getMember()	{ return *m_Member; }
		Operation *						getObj()	{ return m_Operations[0]; }
		Operation *						getValue()	{ return m_Operations[1]; }
	};

	class OrEqualsStaticField : public Operation {
	  protected:
		Metallurgy::Member *m_Member;

	  public:
		OrEqualsStaticField(Blocks::Method *method, Ops::MSIL::Or *or, Ops::MSIL::StoreStaticField *field) :
			Operation(method, or->getOffset()),
			m_Member(field->getMember())
		{
			delete or->getValue1();
			Tack(or->getValue2());
			or->toTrash();
		}

		Metallurgy::Member &		getMember()	{ return *m_Member; }
		Operation *						getValue()	{ return m_Operations[0]; }
	};

	class OrEqualsLocal : public Operation {
	  protected:
		ULONG m_Indx;

	  public:
		OrEqualsLocal(Blocks::Method *method, Ops::MSIL::Or *or, Ops::MSIL::StoreLocal *local) :
			Operation(method, or->getOffset()),
			m_Indx(local->getIndx())
		{
			delete or->getValue1();
			Tack(or->getValue2());
			or->toTrash();
		}

		ULONG		getIndx()	{ return m_Indx; }
		Operation *	getValue()	{ return m_Operations[0]; }
	};

	class PlusEqualsField : public Operation {
	  protected:
		Metallurgy::Member *m_Field;

	  public:
		PlusEqualsField(Blocks::Method *method, Ops::MSIL::Add *add, Ops::MSIL::StoreField *field) :
			Operation(method, add->getOffset()),
			m_Field(field->getMember())
		{
			Tack(field->getObj());
			field->toTrash();
			delete add->getValue1();
			Tack(add->getValue2());
			add->toTrash();
		}

		Metallurgy::Member *getField()	{ return m_Field; }
		Operation *	getObj()	{ return m_Operations[0]; }
		Operation *	getValue()	{ return m_Operations[1]; }
	};

	class PlusEqualsStaticField : public Operation {
	  protected:
		Metallurgy::Member *m_Field;

	  public:
		PlusEqualsStaticField(Blocks::Method *method, Ops::MSIL::Add *add, Ops::MSIL::StoreStaticField *field) :
			Operation(method, add->getOffset()),
			m_Field(field->getMember())
		{
			delete add->getValue1();
			Tack(add->getValue2());
			add->toTrash();
		}

		Metallurgy::Member *	getField()	{ return m_Field; }
		Operation *	getValue()	{ return m_Operations[0]; }
	};

	class PlusEqualsLocal : public Operation {
	  protected:
		ULONG m_Indx;

	  public:
		PlusEqualsLocal(Blocks::Method *method, Ops::MSIL::Add *add, Ops::MSIL::StoreLocal *local) :
			Operation(method, add->getOffset()),
			m_Indx(local->getIndx())
		{
			delete add->getValue1();
			Tack(add->getValue2());
			add->toTrash();
		}

		ULONG		getIndx()	{ return m_Indx; }
		Operation *	getValue()	{ return m_Operations[0]; }
	};

} } }