/*
* PERWAPI - An API for Reading and Writing PE Files
*
* Copyright (c) Diane Corney, Queensland University of Technology, 2004.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the PERWAPI Copyright as included with this
* distribution in the file PERWAPIcopyright.rtf.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY as is explained in the copyright notice.
*
* The author may be contacted at d.corney@qut.edu.au
*
* Version Date: 26/01/07
*/
using System;
using System.IO;
namespace QUT.PERWAPI
{
/**************************************************************************/
// Class to describe procedure locals
/**************************************************************************/
///
/// Descriptor for a local of a method
///
public class Local
{
private static readonly byte PINNED = 0x45;
string name;
public Type type;
bool pinned = false;
int index = 0;
/*-------------------- Constructors ---------------------------------*/
///
/// Create a new local variable
///
/// name of the local variable
/// type of the local variable
public Local(string lName, Type lType)
{
name = lName;
type = lType;
}
///
/// Create a new local variable that is byref and/or pinned
///
/// local name
/// local type
/// has pinned attribute
public Local(string lName, Type lType, bool isPinned)
{
name = lName;
type = lType;
pinned = isPinned;
}
public int GetIndex() { return index; }
///
/// The name of the local variable.
///
public string Name { get { return name; } }
public bool Pinned
{
get { return pinned; }
set { pinned = value; }
}
///
/// Gets the signature for this local variable.
///
/// A byte array of the signature.
public byte[] GetSig()
{
MemoryStream str = new MemoryStream();
type.TypeSig(str);
return str.ToArray();
}
internal void SetIndex(int ix)
{
index = ix;
}
internal void TypeSig(MemoryStream str)
{
if (pinned) str.WriteByte(PINNED);
type.TypeSig(str);
}
internal void BuildTables(MetaDataOut md)
{
if (!(type is ClassDef))
type.BuildMDTables(md);
}
internal void BuildCILInfo(CILWriter output)
{
if (!(type is ClassDef))
type.BuildCILInfo(output);
}
internal void Write(CILWriter output)
{
type.WriteType(output);
output.Write("\t" + name);
}
}
}