Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

283
mcs/ilasm/scanner/ChangeLog Normal file
View File

@@ -0,0 +1,283 @@
2009-04-15 Ankit Jain <jankit@novell.com>
* StringHelper.cs (startIdChars): New. Set of chars that can start an
identifier.
(Start): Use startIdChars instead of idchars.
2009-04-08 Ankit Jain <jankit@novell.com>
Fix bug #487155.
* StringHelper.cs: Handle octal values in strings.
Patch from Stephen Gennard (stephen@gennard.net)
2006-11-09 Ankit Jain <jankit@novell.com>
* ILTables.cs (keywords): Add 'retargetable'.
2006-05-26 Ankit Jain <jankit@novell.com>
* ILTables.cs (keywords): Move 'property' out of NET_2_0 .
2006-05-11 Ankit Jain <jankit@novell.com>
* ILTokenizingExpcetion.cs (Location): Remove. Already inherited from
ILAsmException.
2006-05-10 Ankit Jain <jankit@novell.com>
* ILTables.cs (keywords): Add 'property' for NET_2_0.
2006-02-20 Ankit Jain <jankit@novell.com>
* ILTable.cs (directives): Remove .constraint
2006-02-20 Ankit Jain <jankit@novell.com>
* ILTokenizingException.cs (ILTokenizingException): Derive from
ILAsmException.
2006-01-31 Ankit Jain <jankit@novell.com>
* ILTables.cs (keywords): Enable keyword 'type' only for NET_2_0 profile.
2006-01-28 Ankit Jain <jankit@novell.com>
* ILTables.cs (keywords): Fix typos in entry for 'charmaperror'.
2006-01-19 Ankit Jain <jankit@novell.com>
* ILTables.cs (keywords): Add 'type' keyword.
2006-01-16 Ankit Jain <jankit@novell.com>
* NumberHelper.cs (NumberHelper.Build): Try parsing numeric value as UInt64 or
double if Int64.Parse fails.
2006-01-16 Ankit Jain <jankit@novell.com>
* ILTables.cs (keywords): Add 'bestfit', 'charmaperror', 'on' & 'off'.
2006-01-16 Ankit Jain <jankit@novell.com>
* ILTables.cs (keywords): Add 'uint', this is a native UIntPtr type.
2006-01-03 Ankit Jain <jankit@novell.com>
* ILTokenizer.cs (ILTokenizer.idchars): Add ` to the list.
2005-12-14 Ankit Jain <jankit@novell.com>
* NumberHelper.cs (NumberHelper.Build): Set dec_found to false, if a '..' is
found after a number so that it is parsed as INT64 and not FLOAT64.
Fix #76977.
2005-12-14 Ankit Jain <jankit@novell.com>
* ILTables.cs (keywords): Add uint8, uint16, uint32 and uint64 keywords.
2005-11-28 Ankit Jain <jankit@novell.com>
* StringHelper.cs (idChars): Add ` to the list.
2005-08-29 Ankit Jain <jankit@novell.com>
* ILTables.cs (keywords): Comment out lcid keyword. Its not recognised as a
keyword by ilasm (ms.net) 1.1
2005-08-18 Ankit Jain <jankit@novell.com>
* ILTables.cs: Comment out publickey keyword.
2005-04-27 Raja R Harinath <rharinath@novell.com>
* ILTokenizer.cs (GetNextToken): Handle 'tail.' and 'unaligned.'
instructions.
2004-04-26 Ankit Jain <ankit@corewars.org>
* ILTokenizer.cs (ILTokenizer.GetNextToken): Advance reader to look at
char after a '.' .
(ILTokenizer.BuildId): Never end an id on a DOT.
Parts of the patch from Harinath & Jackson.
2004-12-02 Miguel de Icaza <miguel@ximian.com>
* ILTable.cs: Add new .stackreserve token.
2004-07-27 Martin Baulig <martin@ximian.com>
* ILTokenizer.cs (ILTokenizer.Location): New public property.
2004-07-16 Jackson Harper <jackson@ximian.com>
* ILTokenizer.cs: Handle slashes in multiline comments
properly. Make the multiline comment eater loop a little more
readable.
2004-07-06 Jackson Harper <jackson@ximian.com>
* NumberHelper.cs: Handle real numbers. Thanks to steve brown for
pointing this out. Also don't bother scanning the string again,
its allready been scanned.
2004-06-10 Jackson Harper <jackson@ximian.com>
* ILTables.cs: Remove opcodes, these are contained in codegen/IntrTable.cs
* ILTokenizer.cs: Dont refer to ILTables::Opcodes
2004-06-10 Jackson Harper <jackson@ximian.com>
* ILTokenizingExpcetion.cs: New exception thrown by the tokenizer
if any tokenizing errors occur.
* ILTokenizer.cs:
* NumberHelper.cs: Use the new exception.
2004-06-04 Jackson Harper <jackson@ximian.com>
* ILTokenizer.cs: Handle comments first, handle whitespace in hex
blocks properly.
2004-04-21 Jackson Harper <jackson@ximian.com>
* ILTokenizer.cs: Handle whitespace in hexbytes.
2004-04-01 Jackson Harper <jackson@ximian.com>
* ILTokenizer.cs: Add flag and special parsing routine for byte
arrays.
2003-12-10 Jackson Harper <jackson@ximian.com>
* ILTokenizer.cs: Handle dotted ids as a single token. This allows
keywords at the end of a dotted name.
2003-10-14 Jackson Harper <jackson@ximian.com>
* ILTokenizer.cs: Fix /* */ comment blocks.
2003-09-16 Jackson Harper <jackson@latitudegeo.com>
* ILTables.cs: compilercontrolled is lowercase. I am guessing this
was an emacs introduced bug ;-).
2003-08-10 Jackson Harper <jackson@latitudegeo.com>
* StringHelper.cs: If an escape is not valid just use the \
character. Fix bug where escape char was not getting set.
2003-08-03 Jackson Harper <jackson@latitudegeo.com>
* NumberHelper.cs: All numbers should allways be Int64
2003-07-30 Jackson Harper <jackson@latitudegeo.com>
* ILReader.cs: Incremint colums while reading
* Location.cs: Display column numbers
2003-07-29 Jackson Harper <jackson@latitudegeo.com>
* ILReader.cs: Incriment line numbers
* Location.cs: Do not reset line number when moving to a previous
column. Add ToString method.
2003-07-15 Jackson Harper <jackson@latitudegeo.com>
* ILTables.cs: Add tokens for generic constraints.
2003-06-14 Jackson Harper <jackson@latitudegeo.com>
* ILTables.cs: Add imagebase keyword.
2003-05-31 Jackson Harper <jackson@latitudegeo.com>
* ILTables.cs: Add refany keyword which is just an alias for typedref.
2003-05-22 Jackson Harper <jackson@latitudegeo.com>
* ILTokenizer.cs: When building instructions allow the '.' char so
complex instructions like conv.ovf.u.un can be created.
2003-05-22 Jackson Harper <jackson@latitudegeo.com>
* ILTables.cs: Comment out nan and inf keywords, these are not
referenced in the grammar. need to check if these keywords work on
MS ilasm.
* NumberHelper.cs: Parse numbers as Unsigned then cast to long
otherwise an overflow exception is thrown. (is this a classlib bug?)
2003-05-18 Jackson Harper <jackson@latitudegeo.com>
* ILTokenizer.cs: If token.token does not create a keyword return
the first token as an id, not a keyword ie (add.exe should return
"ID period ID" not "ADD period ID"
2003-04-28 Jackson Harper <jackson@latitudegeo.com>
* ILTokenizer.cs: Get instructions from table and check if they
are null instead of checking if they exist then getting them.
2003-04-03 Jackson Harper <jackson@latitudegeo.com>
* ILToken.cs: Add open angle bracket, and close angle bracket tokens.
2003-03-31 Jackson Harper <jackson@latitudegeo.com>
* NumberHelper.cs: handle situations like this 21452. properly
2003-03-31 Jackson Harper <jackson@latitudegeo.com>
* ILTokenizer.cs: Handle Ellipsis
* NUmberHelper.cs: Handle situations like this 0... properly
2003-03-31 Jackson Harper <jackson@latitudegeo.com>
* ILTokenizer.cs: Take some special cases into account.
2003-03-31 Jackson Harper <jackson@latitudegeo.com>
* ILTables.cs: Remove 'ptr' I can't find documentation for this
keyword and ildasm does not esacpe it.
2003-03-31 Jackson Harper <jackson@latitudegeo.com>
* NumberHelper.cs: handle sci, hex, and byte
do not handle all corner case
will optimize soon
2003-03-30 Jackson Harper <jackson@latitudegeo.com>
* ILReader.cs: Instead of mainting a buffer let the reader handle
that, and use a stack for putting chars back. This is probably
much slower and not nearly as cool but the old method was a little
buggy and I was having trouble tracking things down. This can be
optimized someday.
2003-03-19 Jackson Harper <jackson@latitudegeo.com>
* NumberHelper.cs: Handle strange number situations like 8:99:0
2003-03-16 Jackson Harper <jackson@latitudegeo.com>
* ILTokenizer.cs: Append tail to values so opcodes like ldarg.s
are resolved properly
2003-03-16 Jackson Harper <jackson@latitudegeo.com>
* ILTokenizer.cs: Fire an event when a new token is ready.
2003-03-14 Jackson Harper <jackson@latitudegeo.com>
* ILTokenizer.cs: Use the IsInstr method for checking if a string is an instruction
2003-03-13 Jackson Harper <jackson@latitudegeo.com>
* ILTokenizer.cs: Use InstrTable for looking up and getting Opcodes
2003-02-06 Jackson Harper <jackson@latitudegeo.com>
* IlToken.cs: Add Dash Token (this is used for assembly names)
* ILTokenizer.cs: Return Dash token
2003-02-02 Jackson Harper <jackson@latitudegeo.com>
* ChangeLog: Add ChangeLog

View File

@@ -0,0 +1,166 @@
// ILReader.cs
// Author: Sergey Chaban (serge@wildwestsoftware.com)
using System;
using System.IO;
using System.Text;
using System.Collections;
namespace Mono.ILASM {
/// <summary>
/// </summary>
public class ILReader {
private StreamReader reader;
private Stack putback_stack;
private Location location;
private Location markedLocation;
public ILReader (StreamReader reader)
{
this.reader = reader;
putback_stack = new Stack ();
location = new Location ();
markedLocation = Location.Unknown;
}
/// <summary>
/// </summary>
public Location Location {
get {
return location;
}
}
/// <summary>
/// Provides access to underlying StreamReader.
/// </summary>
public StreamReader BaseReader {
get {
return reader;
}
}
private int DoRead ()
{
if (putback_stack.Count > 0)
return (char) putback_stack.Pop ();
return reader.Read ();
}
private int DoPeek ()
{
if (putback_stack.Count > 0)
return (char) putback_stack.Peek ();
return reader.Peek ();
}
/// <summary>
/// </summary>
/// <returns></returns>
public int Read ()
{
int read = DoRead ();
if (read == '\n')
location.NewLine ();
else
location.NextColumn ();
return read;
}
/// <summary>
/// </summary>
/// <returns></returns>
public int Peek ()
{
return DoPeek ();
}
/// <summary>
/// </summary>
public void Unread (char c)
{
putback_stack.Push (c);
if ('\n' == c)
location.PreviousLine ();
location.PreviousColumn ();
}
/// <summary>
/// </summary>
/// <param name="chars"></param>
public void Unread (char [] chars)
{
for (int i=chars.Length-1; i>=0; i--)
Unread (chars[i]);
}
/// <summary>
/// </summary>
/// <param name="c"></param>
public void Unread (int c)
{
Unread ((char)c);
}
/// <summary>
/// </summary>
public void SkipWhitespace ()
{
int ch = Read ();
for (; ch != -1 && Char.IsWhiteSpace((char) ch); ch = Read ());
if (ch != -1) Unread (ch);
}
/// <summary>
/// </summary>
/// <returns></returns>
public string ReadToWhitespace ()
{
StringBuilder sb = new StringBuilder ();
int ch = Read ();
for (; ch != -1 && !Char.IsWhiteSpace((char) ch); sb.Append ((char) ch), ch = Read ());
if (ch != -1) Unread (ch);
return sb.ToString ();
}
/// <summary>
/// </summary>
public void MarkLocation ()
{
if (markedLocation == Location.Unknown) {
markedLocation = new Location (location);
} else {
markedLocation.CopyFrom (location);
}
}
/// <summary>
/// </summary>
public void RestoreLocation ()
{
if (markedLocation != Location.Unknown) {
location.CopyFrom (markedLocation);
}
}
}
}

View File

@@ -0,0 +1,335 @@
// ILTables.cs
// Mechanically generated - DO NOT EDIT!
//
// (C) Sergey Chaban (serge@wildwestsoftware.com)
using System;
using System.Collections;
using System.Reflection.Emit;
namespace Mono.ILASM {
public sealed class ILTables {
private static Hashtable keywords = null;
private static Hashtable directives = null;
private static readonly object mutex;
private ILTables ()
{
}
static ILTables ()
{
mutex = new object ();
}
private static void AllocTable (ref Hashtable tbl, int size)
{
lock (mutex) {
if (tbl == null)
tbl = new Hashtable (size);
}
}
public static Hashtable Directives
{
get {
if (directives != null) return directives;
AllocTable (ref directives, 300);
directives [".addon"] = new ILToken (Token.D_ADDON, ".addon");
directives [".algorithm"] = new ILToken (Token.D_ALGORITHM, ".algorithm");
directives [".assembly"] = new ILToken (Token.D_ASSEMBLY, ".assembly");
directives [".backing"] = new ILToken (Token.D_BACKING, ".backing");
directives [".blob"] = new ILToken (Token.D_BLOB, ".blob");
directives [".capability"] = new ILToken (Token.D_CAPABILITY, ".capability");
directives [".cctor"] = new ILToken (Token.D_CCTOR, ".cctor");
directives [".class"] = new ILToken (Token.D_CLASS, ".class");
directives [".comtype"] = new ILToken (Token.D_COMTYPE, ".comtype");
directives [".config"] = new ILToken (Token.D_CONFIG, ".config");
directives [".imagebase"] = new ILToken (Token.D_IMAGEBASE, ".imagebase");
directives [".corflags"] = new ILToken (Token.D_CORFLAGS, ".corflags");
directives [".ctor"] = new ILToken (Token.D_CTOR, ".ctor");
directives [".custom"] = new ILToken (Token.D_CUSTOM, ".custom");
directives [".data"] = new ILToken (Token.D_DATA, ".data");
directives [".emitbyte"] = new ILToken (Token.D_EMITBYTE, ".emitbyte");
directives [".entrypoint"] = new ILToken (Token.D_ENTRYPOINT, ".entrypoint");
directives [".event"] = new ILToken (Token.D_EVENT, ".event");
directives [".exeloc"] = new ILToken (Token.D_EXELOC, ".exeloc");
directives [".export"] = new ILToken (Token.D_EXPORT, ".export");
directives [".field"] = new ILToken (Token.D_FIELD, ".field");
directives [".file"] = new ILToken (Token.D_FILE, ".file");
directives [".fire"] = new ILToken (Token.D_FIRE, ".fire");
directives [".get"] = new ILToken (Token.D_GET, ".get");
directives [".hash"] = new ILToken (Token.D_HASH, ".hash");
directives [".implicitcom"] = new ILToken (Token.D_IMPLICITCOM, ".implicitcom");
directives [".language"] = new ILToken (Token.D_LANGUAGE, ".language");
directives [".line"] = new ILToken (Token.D_LINE, ".line");
directives ["#line"] = new ILToken (Token.D_XLINE, "#line");
directives [".locale"] = new ILToken (Token.D_LOCALE, ".locale");
directives [".locals"] = new ILToken (Token.D_LOCALS, ".locals");
directives [".manifestres"] = new ILToken (Token.D_MANIFESTRES, ".manifestres");
directives [".maxstack"] = new ILToken (Token.D_MAXSTACK, ".maxstack");
directives [".method"] = new ILToken (Token.D_METHOD, ".method");
directives [".mime"] = new ILToken (Token.D_MIME, ".mime");
directives [".module"] = new ILToken (Token.D_MODULE, ".module");
directives [".mresource"] = new ILToken (Token.D_MRESOURCE, ".mresource");
directives [".namespace"] = new ILToken (Token.D_NAMESPACE, ".namespace");
directives [".originator"] = new ILToken (Token.D_ORIGINATOR, ".originator");
directives [".os"] = new ILToken (Token.D_OS, ".os");
directives [".other"] = new ILToken (Token.D_OTHER, ".other");
directives [".override"] = new ILToken (Token.D_OVERRIDE, ".override");
directives [".pack"] = new ILToken (Token.D_PACK, ".pack");
directives [".param"] = new ILToken (Token.D_PARAM, ".param");
directives [".permission"] = new ILToken (Token.D_PERMISSION, ".permission");
directives [".permissionset"] = new ILToken (Token.D_PERMISSIONSET, ".permissionset");
directives [".processor"] = new ILToken (Token.D_PROCESSOR, ".processor");
directives [".property"] = new ILToken (Token.D_PROPERTY, ".property");
directives [".publickey"] = new ILToken (Token.D_PUBLICKEY, ".publickey");
directives [".publickeytoken"] = new ILToken (Token.D_PUBLICKEYTOKEN, ".publickeytoken");
directives [".removeon"] = new ILToken (Token.D_REMOVEON, ".removeon");
directives [".set"] = new ILToken (Token.D_SET, ".set");
directives [".size"] = new ILToken (Token.D_SIZE, ".size");
directives [".stackreserve"] = new ILToken (Token.D_STACKRESERVE, ".stackreserve");
directives [".subsystem"] = new ILToken (Token.D_SUBSYSTEM, ".subsystem");
directives [".title"] = new ILToken (Token.D_TITLE, ".title");
directives [".try"] = new ILToken (Token.D_TRY, ".try");
directives [".ver"] = new ILToken (Token.D_VER, ".ver");
directives [".vtable"] = new ILToken (Token.D_VTABLE, ".vtable");
directives [".vtentry"] = new ILToken (Token.D_VTENTRY, ".vtentry");
directives [".vtfixup"] = new ILToken (Token.D_VTFIXUP, ".vtfixup");
directives [".zeroinit"] = new ILToken (Token.D_ZEROINIT, ".zeroinit");
return directives;
}
}
public static Hashtable Keywords
{
get {
if (keywords != null) return keywords;
AllocTable (ref keywords, 300);
keywords ["at"] = new ILToken (Token.K_AT, "at");
keywords ["as"] = new ILToken (Token.K_AS, "as");
keywords ["implicitcom"] = new ILToken (Token.K_IMPLICITCOM, "implicitcom");
keywords ["implicitres"] = new ILToken (Token.K_IMPLICITRES, "implicitres");
keywords ["noappdomain"] = new ILToken (Token.K_NOAPPDOMAIN, "noappdomain");
keywords ["noprocess"] = new ILToken (Token.K_NOPROCESS, "noprocess");
keywords ["nomachine"] = new ILToken (Token.K_NOMACHINE, "nomachine");
keywords ["extern"] = new ILToken (Token.K_EXTERN, "extern");
keywords ["instance"] = new ILToken (Token.K_INSTANCE, "instance");
keywords ["explicit"] = new ILToken (Token.K_EXPLICIT, "explicit");
keywords ["default"] = new ILToken (Token.K_DEFAULT, "default");
keywords ["vararg"] = new ILToken (Token.K_VARARG, "vararg");
keywords ["unmanaged"] = new ILToken (Token.K_UNMANAGED, "unmanaged");
keywords ["cdecl"] = new ILToken (Token.K_CDECL, "cdecl");
keywords ["stdcall"] = new ILToken (Token.K_STDCALL, "stdcall");
keywords ["thiscall"] = new ILToken (Token.K_THISCALL, "thiscall");
keywords ["fastcall"] = new ILToken (Token.K_FASTCALL, "fastcall");
keywords ["marshal"] = new ILToken (Token.K_MARSHAL, "marshal");
keywords ["in"] = new ILToken (Token.K_IN, "in");
keywords ["out"] = new ILToken (Token.K_OUT, "out");
keywords ["opt"] = new ILToken (Token.K_OPT, "opt");
// Not a keyword according to ilasm 1.1
// keywords ["lcid"] = new ILToken (Token.K_LCID, "lcid");
//keywords ["retval"] = new ILToken (Token.K_RETVAL, "retval");
keywords ["static"] = new ILToken (Token.K_STATIC, "static");
keywords ["public"] = new ILToken (Token.K_PUBLIC, "public");
keywords ["private"] = new ILToken (Token.K_PRIVATE, "private");
keywords ["family"] = new ILToken (Token.K_FAMILY, "family");
keywords ["initonly"] = new ILToken (Token.K_INITONLY, "initonly");
keywords ["rtspecialname"] = new ILToken (Token.K_RTSPECIALNAME, "rtspecialname");
keywords ["specialname"] = new ILToken (Token.K_SPECIALNAME, "specialname");
keywords ["assembly"] = new ILToken (Token.K_ASSEMBLY, "assembly");
keywords ["famandassem"] = new ILToken (Token.K_FAMANDASSEM, "famandassem");
keywords ["famorassem"] = new ILToken (Token.K_FAMORASSEM, "famorassem");
keywords ["privatescope"] = new ILToken (Token.K_PRIVATESCOPE, "privatescope");
keywords ["literal"] = new ILToken (Token.K_LITERAL, "literal");
keywords ["notserialized"] = new ILToken (Token.K_NOTSERIALIZED, "notserialized");
keywords ["value"] = new ILToken (Token.K_VALUE, "value");
keywords ["not_in_gc_heap"] = new ILToken (Token.K_NOT_IN_GC_HEAP, "not_in_gc_heap");
keywords ["interface"] = new ILToken (Token.K_INTERFACE, "interface");
keywords ["sealed"] = new ILToken (Token.K_SEALED, "sealed");
keywords ["abstract"] = new ILToken (Token.K_ABSTRACT, "abstract");
keywords ["auto"] = new ILToken (Token.K_AUTO, "auto");
keywords ["sequential"] = new ILToken (Token.K_SEQUENTIAL, "sequential");
keywords ["ansi"] = new ILToken (Token.K_ANSI, "ansi");
keywords ["unicode"] = new ILToken (Token.K_UNICODE, "unicode");
keywords ["autochar"] = new ILToken (Token.K_AUTOCHAR, "autochar");
keywords ["bestfit"] = new ILToken (Token.K_BESTFIT, "bestfit");
keywords ["charmaperror"] = new ILToken (Token.K_CHARMAPERROR, "charmaperror");
keywords ["import"] = new ILToken (Token.K_IMPORT, "import");
keywords ["serializable"] = new ILToken (Token.K_SERIALIZABLE, "serializable");
keywords ["nested"] = new ILToken (Token.K_NESTED, "nested");
keywords ["lateinit"] = new ILToken (Token.K_LATEINIT, "lateinit");
keywords ["extends"] = new ILToken (Token.K_EXTENDS, "extends");
keywords ["implements"] = new ILToken (Token.K_IMPLEMENTS, "implements");
keywords ["final"] = new ILToken (Token.K_FINAL, "final");
keywords ["virtual"] = new ILToken (Token.K_VIRTUAL, "virtual");
keywords ["hidebysig"] = new ILToken (Token.K_HIDEBYSIG, "hidebysig");
keywords ["newslot"] = new ILToken (Token.K_NEWSLOT, "newslot");
keywords ["unmanagedexp"] = new ILToken (Token.K_UNMANAGEDEXP, "unmanagedexp");
keywords ["pinvokeimpl"] = new ILToken (Token.K_PINVOKEIMPL, "pinvokeimpl");
keywords ["nomangle"] = new ILToken (Token.K_NOMANGLE, "nomangle");
keywords ["ole"] = new ILToken (Token.K_OLE, "ole");
keywords ["lasterr"] = new ILToken (Token.K_LASTERR, "lasterr");
keywords ["winapi"] = new ILToken (Token.K_WINAPI, "winapi");
keywords ["native"] = new ILToken (Token.K_NATIVE, "native");
keywords ["il"] = new ILToken (Token.K_IL, "il");
keywords ["cil"] = new ILToken (Token.K_CIL, "cil");
keywords ["optil"] = new ILToken (Token.K_OPTIL, "optil");
keywords ["managed"] = new ILToken (Token.K_MANAGED, "managed");
keywords ["forwardref"] = new ILToken (Token.K_FORWARDREF, "forwardref");
keywords ["runtime"] = new ILToken (Token.K_RUNTIME, "runtime");
keywords ["internalcall"] = new ILToken (Token.K_INTERNALCALL, "internalcall");
keywords ["synchronized"] = new ILToken (Token.K_SYNCHRONIZED, "synchronized");
keywords ["noinlining"] = new ILToken (Token.K_NOINLINING, "noinlining");
keywords ["custom"] = new ILToken (Token.K_CUSTOM, "custom");
keywords ["fixed"] = new ILToken (Token.K_FIXED, "fixed");
keywords ["sysstring"] = new ILToken (Token.K_SYSSTRING, "sysstring");
keywords ["array"] = new ILToken (Token.K_ARRAY, "array");
keywords ["variant"] = new ILToken (Token.K_VARIANT, "variant");
keywords ["currency"] = new ILToken (Token.K_CURRENCY, "currency");
keywords ["syschar"] = new ILToken (Token.K_SYSCHAR, "syschar");
keywords ["void"] = new ILToken (Token.K_VOID, "void");
keywords ["bool"] = new ILToken (Token.K_BOOL, "bool");
keywords ["int8"] = new ILToken (Token.K_INT8, "int8");
keywords ["int16"] = new ILToken (Token.K_INT16, "int16");
keywords ["int32"] = new ILToken (Token.K_INT32, "int32");
keywords ["int64"] = new ILToken (Token.K_INT64, "int64");
keywords ["float32"] = new ILToken (Token.K_FLOAT32, "float32");
keywords ["float64"] = new ILToken (Token.K_FLOAT64, "float64");
keywords ["error"] = new ILToken (Token.K_ERROR, "error");
keywords ["unsigned"] = new ILToken (Token.K_UNSIGNED, "unsigned");
keywords ["uint"] = new ILToken (Token.K_UINT, "uint");
keywords ["uint8"] = new ILToken (Token.K_UINT8, "uint8");
keywords ["uint16"] = new ILToken (Token.K_UINT16, "uint16");
keywords ["uint32"] = new ILToken (Token.K_UINT32, "uint32");
keywords ["uint64"] = new ILToken (Token.K_UINT64, "uint64");
keywords ["decimal"] = new ILToken (Token.K_DECIMAL, "decimal");
keywords ["date"] = new ILToken (Token.K_DATE, "date");
keywords ["bstr"] = new ILToken (Token.K_BSTR, "bstr");
keywords ["lpstr"] = new ILToken (Token.K_LPSTR, "lpstr");
keywords ["lpwstr"] = new ILToken (Token.K_LPWSTR, "lpwstr");
keywords ["lptstr"] = new ILToken (Token.K_LPTSTR, "lptstr");
keywords ["objectref"] = new ILToken (Token.K_OBJECTREF, "objectref");
keywords ["iunknown"] = new ILToken (Token.K_IUNKNOWN, "iunknown");
keywords ["idispatch"] = new ILToken (Token.K_IDISPATCH, "idispatch");
keywords ["struct"] = new ILToken (Token.K_STRUCT, "struct");
keywords ["safearray"] = new ILToken (Token.K_SAFEARRAY, "safearray");
keywords ["int"] = new ILToken (Token.K_INT, "int");
keywords ["byvalstr"] = new ILToken (Token.K_BYVALSTR, "byvalstr");
keywords ["tbstr"] = new ILToken (Token.K_TBSTR, "tbstr");
keywords ["lpvoid"] = new ILToken (Token.K_LPVOID, "lpvoid");
keywords ["any"] = new ILToken (Token.K_ANY, "any");
keywords ["float"] = new ILToken (Token.K_FLOAT, "float");
keywords ["lpstruct"] = new ILToken (Token.K_LPSTRUCT, "lpstruct");
keywords ["null"] = new ILToken (Token.K_NULL, "null");
// keywords ["ptr"] = new ILToken (Token.K_PTR, "ptr");
keywords ["vector"] = new ILToken (Token.K_VECTOR, "vector");
keywords ["hresult"] = new ILToken (Token.K_HRESULT, "hresult");
keywords ["carray"] = new ILToken (Token.K_CARRAY, "carray");
keywords ["userdefined"] = new ILToken (Token.K_USERDEFINED, "userdefined");
keywords ["record"] = new ILToken (Token.K_RECORD, "record");
keywords ["filetime"] = new ILToken (Token.K_FILETIME, "filetime");
keywords ["blob"] = new ILToken (Token.K_BLOB, "blob");
keywords ["stream"] = new ILToken (Token.K_STREAM, "stream");
keywords ["storage"] = new ILToken (Token.K_STORAGE, "storage");
keywords ["streamed_object"] = new ILToken (Token.K_STREAMED_OBJECT, "streamed_object");
keywords ["stored_object"] = new ILToken (Token.K_STORED_OBJECT, "stored_object");
keywords ["blob_object"] = new ILToken (Token.K_BLOB_OBJECT, "blob_object");
keywords ["cf"] = new ILToken (Token.K_CF, "cf");
keywords ["clsid"] = new ILToken (Token.K_CLSID, "clsid");
keywords ["method"] = new ILToken (Token.K_METHOD, "method");
keywords ["class"] = new ILToken (Token.K_CLASS, "class");
keywords ["pinned"] = new ILToken (Token.K_PINNED, "pinned");
keywords ["modreq"] = new ILToken (Token.K_MODREQ, "modreq");
keywords ["modopt"] = new ILToken (Token.K_MODOPT, "modopt");
keywords ["typedref"] = new ILToken (Token.K_TYPEDREF, "typedref");
keywords ["property"] = new ILToken (Token.K_PROPERTY, "property");
#if NET_2_0 || BOOTSTRAP_NET_2_0
keywords ["type"] = new ILToken (Token.K_TYPE, "type");
#endif
keywords ["refany"] = new ILToken (Token.K_TYPEDREF, "typedref");
keywords ["wchar"] = new ILToken (Token.K_WCHAR, "wchar");
keywords ["char"] = new ILToken (Token.K_CHAR, "char");
keywords ["fromunmanaged"] = new ILToken (Token.K_FROMUNMANAGED, "fromunmanaged");
keywords ["callmostderived"] = new ILToken (Token.K_CALLMOSTDERIVED, "callmostderived");
keywords ["bytearray"] = new ILToken (Token.K_BYTEARRAY, "bytearray");
keywords ["with"] = new ILToken (Token.K_WITH, "with");
keywords ["init"] = new ILToken (Token.K_INIT, "init");
keywords ["to"] = new ILToken (Token.K_TO, "to");
keywords ["catch"] = new ILToken (Token.K_CATCH, "catch");
keywords ["filter"] = new ILToken (Token.K_FILTER, "filter");
keywords ["finally"] = new ILToken (Token.K_FINALLY, "finally");
keywords ["fault"] = new ILToken (Token.K_FAULT, "fault");
keywords ["handler"] = new ILToken (Token.K_HANDLER, "handler");
keywords ["tls"] = new ILToken (Token.K_TLS, "tls");
keywords ["field"] = new ILToken (Token.K_FIELD, "field");
keywords ["request"] = new ILToken (Token.K_REQUEST, "request");
keywords ["demand"] = new ILToken (Token.K_DEMAND, "demand");
keywords ["assert"] = new ILToken (Token.K_ASSERT, "assert");
keywords ["deny"] = new ILToken (Token.K_DENY, "deny");
keywords ["permitonly"] = new ILToken (Token.K_PERMITONLY, "permitonly");
keywords ["linkcheck"] = new ILToken (Token.K_LINKCHECK, "linkcheck");
keywords ["inheritcheck"] = new ILToken (Token.K_INHERITCHECK, "inheritcheck");
keywords ["reqmin"] = new ILToken (Token.K_REQMIN, "reqmin");
keywords ["reqopt"] = new ILToken (Token.K_REQOPT, "reqopt");
keywords ["reqrefuse"] = new ILToken (Token.K_REQREFUSE, "reqrefuse");
keywords ["prejitgrant"] = new ILToken (Token.K_PREJITGRANT, "prejitgrant");
keywords ["prejitdeny"] = new ILToken (Token.K_PREJITDENY, "prejitdeny");
keywords ["noncasdemand"] = new ILToken (Token.K_NONCASDEMAND, "noncasdemand");
keywords ["noncaslinkdemand"] = new ILToken (Token.K_NONCASLINKDEMAND, "noncaslinkdemand");
keywords ["noncasinheritance"] = new ILToken (Token.K_NONCASINHERITANCE, "noncasinheritance");
keywords ["readonly"] = new ILToken (Token.K_READONLY, "readonly");
keywords ["nometadata"] = new ILToken (Token.K_NOMETADATA, "nometadata");
keywords ["algorithm"] = new ILToken (Token.K_ALGORITHM, "algorithm");
keywords ["fullorigin"] = new ILToken (Token.K_FULLORIGIN, "fullorigin");
// keywords ["nan"] = new ILToken (Token.K_NAN, "nan");
// keywords ["inf"] = new ILToken (Token.K_INF, "inf");
// keywords ["publickey"] = new ILToken (Token.K_PUBLICKEY, "publickey");
keywords ["enablejittracking"] = new ILToken (Token.K_ENABLEJITTRACKING, "enablejittracking");
keywords ["disablejitoptimizer"] = new ILToken (Token.K_DISABLEJITOPTIMIZER, "disablejitoptimizer");
keywords ["retargetable"] = new ILToken (Token.K_RETARGETABLE, "retargetable");
keywords ["preservesig"] = new ILToken (Token.K_PRESERVESIG, "preservesig");
keywords ["beforefieldinit"] = new ILToken (Token.K_BEFOREFIELDINIT, "beforefieldinit");
keywords ["alignment"] = new ILToken (Token.K_ALIGNMENT, "alignment");
keywords ["nullref"] = new ILToken (Token.K_NULLREF, "nullref");
keywords ["valuetype"] = new ILToken (Token.K_VALUETYPE, "valuetype");
keywords ["compilercontrolled"] = new ILToken (Token.K_COMPILERCONTROLLED, "compilercontrolled");
keywords ["reqsecobj"] = new ILToken (Token.K_REQSECOBJ, "reqsecobj");
keywords ["enum"] = new ILToken (Token.K_ENUM, "enum");
keywords ["object"] = new ILToken (Token.K_OBJECT, "object");
keywords ["string"] = new ILToken (Token.K_STRING, "string");
keywords ["true"] = new ILToken (Token.K_TRUE, "true");
keywords ["false"] = new ILToken (Token.K_FALSE, "false");
keywords ["is"] = new ILToken (Token.K_IS, "is");
keywords ["on"] = new ILToken (Token.K_ON, "on");
keywords ["off"] = new ILToken (Token.K_OFF, "off");
keywords ["strict"] = new ILToken (Token.K_STRICT, "strict");
keywords ["forwarder"] = new ILToken (Token.K_FORWARDER, "forwarder");
return keywords;
}
}
} // class ILTables
} // namespace Mono.ILASM

View File

@@ -0,0 +1,241 @@
// ILToken.cs
// Author: Sergey Chaban (serge@wildwestsoftware.com)
using System;
namespace Mono.ILASM {
public class ILToken : ICloneable {
internal int token;
internal object val;
public static readonly ILToken Invalid;
public static readonly ILToken EOF;
public static readonly ILToken Dot;
public static readonly ILToken OpenBrace;
public static readonly ILToken CloseBrace;
public static readonly ILToken OpenBracket;
public static readonly ILToken CloseBracket;
public static readonly ILToken OpenParens;
public static readonly ILToken CloseParens;
public static readonly ILToken Comma;
public static readonly ILToken Colon;
public static readonly ILToken DoubleColon;
public static readonly ILToken Semicolon;
public static readonly ILToken Assign;
public static readonly ILToken Star;
public static readonly ILToken Ampersand;
public static readonly ILToken Plus;
public static readonly ILToken Slash;
public static readonly ILToken Bang;
public static readonly ILToken Ellipsis;
public static readonly ILToken Dash;
public static readonly ILToken OpenAngleBracket;
public static readonly ILToken CloseAngleBracket;
private static readonly ILToken [] punctuations;
/// <summary>
/// </summary>
static ILToken ()
{
Invalid = new ILToken (-1, "invalid");
EOF = new ILToken (Token.EOF, "eof");
Dot = new ILToken (Token.DOT, ".");
OpenBrace = new ILToken (Token.OPEN_BRACE, "{");
CloseBrace = new ILToken (Token.CLOSE_BRACE, "}");
OpenBracket = new ILToken (Token.OPEN_BRACKET, "[");
CloseBracket = new ILToken (Token.CLOSE_BRACKET, "]");
OpenParens = new ILToken (Token.OPEN_PARENS, "(");
CloseParens = new ILToken (Token.CLOSE_PARENS, ")");
Comma = new ILToken (Token.COMMA, ",");
Colon = new ILToken (Token.COLON, ":");
DoubleColon = new ILToken (Token.DOUBLE_COLON, "::");
Semicolon = new ILToken (Token.SEMICOLON, ";");
Assign = new ILToken (Token.ASSIGN, "=");
Star = new ILToken (Token.STAR, "*");
Ampersand = new ILToken (Token.AMPERSAND, "&");
Plus = new ILToken (Token.PLUS, "+");
Slash = new ILToken (Token.SLASH, "/");
Bang = new ILToken (Token.BANG, "!");
Ellipsis = new ILToken (Token.ELLIPSIS, "...");
Dash = new ILToken (Token.DASH, "-");
OpenAngleBracket = new ILToken (Token.OPEN_ANGLE_BRACKET, "<");
CloseAngleBracket = new ILToken (Token.CLOSE_ANGLE_BRACKET, ">");
punctuations = new ILToken [] {
OpenBrace, CloseBrace,
OpenBracket, CloseBracket,
OpenParens, CloseParens,
Comma, Colon, Semicolon,
Assign, Star, Ampersand,
Plus, Slash, Bang,
OpenAngleBracket, CloseAngleBracket
};
}
/// <summary>
/// </summary>
public ILToken ()
{
}
/// <summary>
/// </summary>
/// <param name="token"></param>
/// <param name="val"></param>
public ILToken (int token, object val)
{
this.token = token;
this.val = val;
}
/// <summary>
/// </summary>
/// <param name="that"></param>
public ILToken (ILToken that)
{
this.token = that.token;
this.val = that.val;
}
/// <summary>
/// </summary>
public int TokenId {
get {
return token;
}
}
/// <summary>
/// </summary>
public object Value {
get {
return val;
}
}
/// <summary>
/// </summary>
/// <param name="that"></param>
public virtual void CopyFrom (ILToken that)
{
this.token = that.token;
this.val = that.val;
}
/// <summary>
/// </summary>
/// <returns></returns>
public virtual object Clone ()
{
return new ILToken (this);
}
/// <summary>
/// </summary>
/// <returns></returns>
public override int GetHashCode ()
{
int h = token;
if (val != null) h ^= val.GetHashCode ();
return h;
}
/// <summary>
/// </summary>
/// <returns></returns>
public override string ToString ()
{
return (token.ToString() + " : " + (val != null ? val.ToString () : "<null>"));
}
/// <summary>
/// </summary>
/// <param name="o"></param>
/// <returns></returns>
public override bool Equals (object o)
{
bool res = (o != null);
if (res) {
res = Object.ReferenceEquals (this, o);
if (!res) {
res = o is ILToken;
if (res) {
ILToken that = o as ILToken;
res = (this.token == that.token) && (this.val.Equals (that.val));
}
}
}
return res;
}
private static bool EqImpl (ILToken t1, ILToken t2)
{
bool res = false;
if ((t1 as object) != null) {
res = t1.Equals (t2);
} else {
res = ((t2 as object) == null);
}
return res;
}
/// <summary>
/// </summary>
/// <param name="t1"></param>
/// <param name="t2"></param>
/// <returns></returns>
public static bool operator == (ILToken t1, ILToken t2)
{
return EqImpl (t1, t2);
}
/// <summary>
/// </summary>
/// <param name="t1"></param>
/// <param name="t2"></param>
/// <returns></returns>
public static bool operator != (ILToken t1, ILToken t2)
{
return !EqImpl (t1, t2);
}
/// <summary>
/// </summary>
/// <param name="ch"></param>
/// <returns></returns>
public static ILToken GetPunctuation (int ch)
{
int id = "{}[](),:;=*&+/!<>".IndexOf ((char) ch);
ILToken res = null;
if (id != -1) {
res = punctuations [id];
}
return res;
}
}
}

View File

@@ -0,0 +1,371 @@
// ILTokenizer.cs
// Author: Sergey Chaban (serge@wildwestsoftware.com)
using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Globalization;
namespace Mono.ILASM {
public delegate void NewTokenEvent (object sender, NewTokenEventArgs args);
public class NewTokenEventArgs : EventArgs {
public readonly ILToken Token;
public NewTokenEventArgs (ILToken token)
{
Token = token;
}
}
/// <summary>
/// </summary>
public class ILTokenizer : ITokenStream {
private static readonly string idchars = "_$@?.`";
private static Hashtable keywords;
private static Hashtable directives;
private ILToken lastToken;
private ILReader reader;
private StringHelper strBuilder;
private NumberHelper numBuilder;
private bool in_byte_array;
public event NewTokenEvent NewTokenEvent;
static ILTokenizer()
{
keywords = ILTables.Keywords;
directives = ILTables.Directives;
}
/// <summary>
/// </summary>
/// <param name="reader"></param>
public ILTokenizer (StreamReader reader)
{
this.reader = new ILReader (reader);
strBuilder = new StringHelper (this);
numBuilder = new NumberHelper (this);
lastToken = ILToken.Invalid.Clone () as ILToken;
}
public ILReader Reader {
get {
return reader;
}
}
public Location Location {
get {
return reader.Location;
}
}
public bool InByteArray {
get { return in_byte_array; }
set { in_byte_array = value; }
}
public ILToken GetNextToken ()
{
if (lastToken == ILToken.EOF) return ILToken.EOF;
int ch;
int next;
ILToken res = ILToken.EOF.Clone () as ILToken;
while ((ch = reader.Read ()) != -1) {
// Comments
if (ch == '/') {
next = reader.Peek ();
if (next == '/') {
// double-slash comment, skip to the end of the line.
for (reader.Read ();
next != -1 && next != '\n';
next = reader.Read ());
continue;
} else if (next == '*') {
reader.Read ();
for (next = reader.Read (); next != -1; next = reader.Read ()) {
if (next == '*' && reader.Peek () == '/') {
reader.Read ();
goto end;
}
}
end:
continue;
}
}
// HEXBYTES are flagged by the parser otherwise it is
// impossible to figure them out
if (in_byte_array) {
string hx = String.Empty;
if (Char.IsWhiteSpace ((char) ch))
continue;
if (ch == ')') {
res = ILToken.CloseParens;
break;
}
if (!is_hex (ch))
throw new ILTokenizingException (reader.Location, ((char) ch).ToString ());
hx += (char) ch;
if (is_hex (reader.Peek ()))
hx += (char) reader.Read ();
else if (!Char.IsWhiteSpace ((char) reader.Peek ()) && reader.Peek () != ')')
throw new ILTokenizingException (reader.Location,
((char) reader.Peek ()).ToString ());
res.token = Token.HEXBYTE;
res.val = Byte.Parse (hx, NumberStyles.HexNumber);
while (Char.IsWhiteSpace ((char) reader.Peek ()))
reader.Read ();
break;
}
// Ellipsis
if (ch == '.' && reader.Peek () == '.') {
reader.MarkLocation ();
int ch2 = reader.Read ();
if (reader.Peek () == '.') {
res = ILToken.Ellipsis;
reader.Read ();
break;
}
reader.Unread (ch2);
reader.RestoreLocation ();
}
if (ch == '.' || ch == '#') {
next = reader.Peek ();
if (ch == '.' && Char.IsDigit((char) next)) {
numBuilder.Start (ch);
reader.Unread (ch);
numBuilder.Build ();
if (numBuilder.ResultToken != ILToken.Invalid) {
res.CopyFrom (numBuilder.ResultToken);
break;
}
} else {
if (strBuilder.Start (next) && strBuilder.TokenId == Token.ID) {
reader.MarkLocation ();
string dirBody = strBuilder.Build ();
string dir = new string ((char) ch, 1) + dirBody;
if (IsDirective (dir)) {
res = ILTables.Directives [dir] as ILToken;
} else {
reader.Unread (dirBody.ToCharArray ());
reader.RestoreLocation ();
res = ILToken.Dot;
}
} else {
res = ILToken.Dot;
}
break;
}
}
// Numbers && Hexbytes
if (numBuilder.Start (ch)) {
if ((ch == '-') && !(Char.IsDigit ((char) reader.Peek ()))) {
res = ILToken.Dash;
break;
} else {
reader.Unread (ch);
numBuilder.Build ();
if (numBuilder.ResultToken != ILToken.Invalid) {
res.CopyFrom (numBuilder.ResultToken);
break;
}
}
}
// Punctuation
ILToken punct = ILToken.GetPunctuation (ch);
if (punct != null) {
if (punct == ILToken.Colon && reader.Peek () == ':') {
reader.Read ();
res = ILToken.DoubleColon;
} else {
res = punct;
}
break;
}
// ID | QSTRING | SQSTRING | INSTR_* | KEYWORD
if (strBuilder.Start (ch)) {
reader.Unread (ch);
string val = strBuilder.Build ();
if (strBuilder.TokenId == Token.ID) {
ILToken opcode;
next = reader.Peek ();
if (next == '.') {
reader.MarkLocation ();
reader.Read ();
next = reader.Peek ();
if (IsIdChar ((char) next)) {
string opTail = BuildId ();
string full_str = String.Format ("{0}.{1}", val, opTail);
opcode = InstrTable.GetToken (full_str);
if (opcode == null) {
if (strBuilder.TokenId != Token.ID) {
reader.Unread (opTail.ToCharArray ());
reader.Unread ('.');
reader.RestoreLocation ();
res.val = val;
} else {
res.token = Token.COMP_NAME;
res.val = full_str;
}
break;
} else {
res = opcode;
break;
}
} else if (Char.IsWhiteSpace ((char) next)) {
// Handle 'tail.' and 'unaligned.'
opcode = InstrTable.GetToken (val + ".");
if (opcode != null) {
res = opcode;
break;
}
// Let the parser handle the dot
reader.Unread ('.');
}
}
opcode = InstrTable.GetToken (val);
if (opcode != null) {
res = opcode;
break;
}
if (IsKeyword (val)) {
res = ILTables.Keywords [val] as ILToken;
break;
}
}
res.token = strBuilder.TokenId;
res.val = val;
break;
}
}
OnNewToken (res);
lastToken.CopyFrom (res);
return res;
}
/// <summary>
/// </summary>
public ILToken NextToken {
get {
return GetNextToken ();
}
}
/// <summary>
/// </summary>
public ILToken LastToken {
get {
return lastToken;
}
}
bool is_hex (int e)
{
return (e >= '0' && e <= '9') || (e >= 'A' && e <= 'F') || (e >= 'a' && e <= 'f');
}
private static bool IsIdStartChar (char ch)
{
return (Char.IsLetter (ch) || (idchars.IndexOf (ch) != -1));
}
private static bool IsIdChar (char ch)
{
return (Char.IsLetterOrDigit (ch) || (idchars.IndexOf (ch) != -1));
}
/// <summary>
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool IsOpcode (string name)
{
return InstrTable.IsInstr (name);
}
/// <summary>
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool IsDirective (string name)
{
char ch = name [0];
bool res = (ch == '.' || ch == '#');
if (res) {
res = directives.Contains (name);
}
return res;
}
private string BuildId ()
{
StringBuilder idsb = new StringBuilder ();
int ch, last;
last = -1;
while ((ch = reader.Read ()) != -1) {
if (IsIdChar ((char) ch) || ch == '.') {
idsb.Append ((char) ch);
} else {
reader.Unread (ch);
// Never end an id on a DOT
if (last == '.') {
reader.Unread (last);
idsb.Length -= 1;
}
break;
}
last = ch;
}
return idsb.ToString ();
}
/// <summary>
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool IsKeyword (string name)
{
return keywords.Contains (name);
}
private void OnNewToken (ILToken token)
{
if (NewTokenEvent != null)
NewTokenEvent (this, new NewTokenEventArgs (token));
}
}
}

View File

@@ -0,0 +1,28 @@
//
// Mono.ILASM.ILTokenizingException
//
// Author(s):
// Jackson Harper (jackson@ximian.com)
//
// Copyright 2004 Novell, Inc (http://www.novell.com)
//
using System;
namespace Mono.ILASM {
public class ILTokenizingException : ILAsmException {
public readonly string Token;
public ILTokenizingException (Location location, string token)
: base (location, token)
{
Token = token;
}
}
}

View File

@@ -0,0 +1,13 @@
// ITokenStream.cs
// (C) Sergey Chaban (serge@wildwestsoftware.com)
using System;
using System.Collections;
namespace Mono.ILASM {
public interface ITokenStream {
ILToken NextToken {get;}
ILToken LastToken {get;}
}
}

View File

@@ -0,0 +1,105 @@
// InstrToken.cs
// Author: Sergey Chaban (serge@wildwestsoftware.com)
using System;
using System.Reflection.Emit;
namespace Mono.ILASM {
public class InstrToken : ILToken {
/// <summary>
/// </summary>
public InstrToken (OpCode opcode)
{
this.val = opcode;
token = GetInstrType (opcode);
}
/// <summary>
/// </summary>
/// <param name="opcode"></param>
/// <returns></returns>
public static int GetInstrType (OpCode opcode)
{
OperandType t = opcode.OperandType;
int token = Token.UNKNOWN;
switch (t) {
case OperandType.InlineBrTarget:
case OperandType.ShortInlineBrTarget:
token = Token.INSTR_BRTARGET;
break;
case OperandType.InlineField:
token = Token.INSTR_FIELD;
break;
case OperandType.InlineI:
case OperandType.ShortInlineI:
token = Token.INSTR_I;
break;
case OperandType.InlineI8:
token = Token.INSTR_I8;
break;
case OperandType.InlineMethod:
token = Token.INSTR_METHOD;
break;
case OperandType.InlineNone:
token = Token.INSTR_NONE;
break;
case OperandType.InlinePhi:
token = Token.INSTR_PHI;
break;
case OperandType.InlineR:
case OperandType.ShortInlineR:
token = Token.INSTR_R;
break;
/*
case OperandType.InlineRVA:
token = Token.INSTR_RVA;
break;
*/
case OperandType.InlineSig:
token = Token.INSTR_SIG;
break;
case OperandType.InlineString:
token = Token.INSTR_STRING;
break;
case OperandType.InlineSwitch:
token = Token.INSTR_SWITCH;
break;
case OperandType.InlineTok:
token = Token.INSTR_TOK;
break;
case OperandType.InlineType:
token = Token.INSTR_TYPE;
break;
case OperandType.InlineVar:
case OperandType.ShortInlineVar:
token = Token.INSTR_VAR;
break;
}
return token;
}
}
}

View File

@@ -0,0 +1,103 @@
// Location.cs
// Author: Sergey Chaban (serge@wildwestsoftware.com)
using System;
namespace Mono.ILASM {
/// <summary>
/// </summary>
public class Location : ICloneable {
internal int line;
internal int column;
/// <summary>
/// </summary>
public static readonly Location Unknown = new Location (-1, -1);
/// <summary>
/// </summary>
public Location () {
line = 1;
column = 1;
}
/// <summary>
/// </summary>
/// <param name="line"></param>
/// <param name="column"></param>
public Location (int line, int column)
{
this.line = line;
this.column = column;
}
/// <summary>
/// </summary>
/// <param name="that"></param>
public Location (Location that)
{
this.line = that.line;
this.column = that.column;
}
/// <summary>
/// </summary>
public void NewLine ()
{
++line;
column = 1;
}
/// <summary>
/// </summary>
public void PreviousLine ()
{
--line;
column = 1;
}
/// <summary>
/// </summary>
public void NextColumn ()
{
++column;
}
/// <summary>
/// </summary>
public void PreviousColumn ()
{
--column;
}
/// <summary>
/// </summary>
/// <param name="other"></param>
public void CopyFrom (Location other)
{
this.line = other.line;
this.column = other.column;
}
/// <summary>
/// </summary>
/// <returns></returns>
public virtual object Clone () {
return new Location (this);
}
public override string ToString ()
{
return "line (" + line + ") column (" + column + ")";
}
}
}

View File

@@ -0,0 +1,221 @@
// NumberHelper.cs
// Author: Sergey Chaban (serge@wildwestsoftware.com)
using System;
using System.Text;
using System.Globalization;
namespace Mono.ILASM {
/// <summary>
/// </summary>
internal class NumberHelper : StringHelperBase {
private ILToken result;
/// <summary>
/// </summary>
/// <param name="host"></param>
public NumberHelper (ILTokenizer host) : base (host)
{
Reset ();
}
private void Reset ()
{
result = ILToken.Invalid.Clone() as ILToken;
}
/// <summary>
/// </summary>
/// <returns></returns>
public override bool Start (char ch)
{
bool res = (Char.IsDigit (ch) || ch == '-' || (ch == '.' && Char.IsDigit ((char) host.Reader.Peek ())));
Reset ();
return res;
}
bool is_hex (int e)
{
return (e >= '0' && e <= '9') || (e >= 'A' && e <= 'F') || (e >= 'a' && e <= 'f');
}
bool is_sign (int ch)
{
return ((ch == '+') || (ch == '-'));
}
bool is_e (int ch)
{
return ((ch == 'e') || (ch == 'E'));
}
/// <summary>
/// </summary>
/// <returns></returns>
public override string Build ()
{
ILReader reader = host.Reader;
reader.MarkLocation ();
StringBuilder num_builder = new StringBuilder ();
string num;
int ch;
int peek;
bool is_real = false;
bool dec_found = false;
NumberStyles nstyles = NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint |
NumberStyles.AllowLeadingSign;
ch = reader.Read ();
peek = reader.Peek ();
reader.Unread (ch);
if (ch == '0' && (peek == 'x' || peek == 'X'))
return BuildHex ();
if (is_sign (reader.Peek ()))
num_builder.Append ((char) reader.Read ());
do {
ch = reader.Read ();
peek = reader.Peek ();
num_builder.Append ((char) ch);
if (is_e (ch)) {
if (is_real)
throw new ILTokenizingException (reader.Location, num_builder.ToString ());
is_real = true;
}
if (ch == '.')
dec_found = true;
if (!is_hex(peek) &&
!(peek == '.' && !dec_found) && !is_e (peek) &&
!(is_sign (peek) && is_real)) {
break;
}
} while (ch != -1);
num = num_builder.ToString ();
// Check for hexbytes
if (num.Length == 2) {
if (Char.IsLetter (num[0]) || Char.IsLetter (num[1])) {
result.token = Token.HEXBYTE;
result.val = Byte.Parse (num, NumberStyles.HexNumber);
return num;
}
}
if (ch == '.' && peek == '.') {
num = num.Substring (0, num.Length-1);
reader.Unread ('.');
dec_found = false;
} else if (ch == '.') {
num += '0';
}
if (!dec_found && !is_real) {
try {
long i = Int64.Parse (num, nstyles);
result.token = Token.INT64;
result.val = i;
return num;
} catch {
}
try {
long i = (long) UInt64.Parse (num, nstyles);
result.token = Token.INT64;
result.val = i;
return num;
} catch {
}
}
try {
double d = Double.Parse (num, nstyles, NumberFormatInfo.InvariantInfo);
result.token = Token.FLOAT64;
result.val = d;
} catch {
reader.Unread (num.ToCharArray ());
reader.RestoreLocation ();
num = String.Empty;
Reset ();
throw new ILTokenizingException (reader.Location, num_builder.ToString ());
}
return num;
}
public string BuildHex ()
{
ILReader reader = host.Reader;
reader.MarkLocation ();
StringBuilder num_builder = new StringBuilder ();
NumberStyles nstyles = NumberStyles.HexNumber;
string num;
int ch;
int peek;
ch = reader.Read ();
if (ch != '0')
throw new ILTokenizingException (reader.Location, ((char) ch).ToString ());
ch = reader.Read ();
if (ch != 'x' && ch != 'X')
throw new ILTokenizingException (reader.Location, "0" + (char) ch);
do {
ch = reader.Read ();
peek = reader.Peek ();
num_builder.Append ((char) ch);
if (!is_hex ((char) peek))
break;
if (num_builder.Length == 32)
throw new ILTokenizingException (reader.Location, num_builder.ToString ());
} while (ch != -1);
num = num_builder.ToString ();
try {
long i = (long) UInt64.Parse (num, nstyles);
//if (i < Int32.MinValue || i > Int32.MaxValue) {
result.token = Token.INT64;
result.val = i;
//} else {
// result.token = Token.INT32;
// result.val = (int) i;
//}
} catch {
string tnum = num;
reader.Unread (num.ToCharArray ());
reader.RestoreLocation ();
num = String.Empty;
Reset ();
throw new ILTokenizingException (reader.Location, tnum);
}
return num;
}
/// <summary>
/// </summary>
public ILToken ResultToken {
get {
return result;
}
}
}
}

View File

@@ -0,0 +1,142 @@
// StringHelper.cs
// Author: Sergey Chaban (serge@wildwestsoftware.com)
using System;
using System.Text;
namespace Mono.ILASM {
/// <summary>
/// </summary>
internal class StringHelper : StringHelperBase {
private static readonly string startIdChars = "#$@_";
private static readonly string idChars = "_$@?`";
/// <summary>
/// </summary>
/// <param name="host"></param>
public StringHelper (ILTokenizer host) : base (host)
{
}
/// <summary>
/// </summary>
/// <returns></returns>
public override bool Start (char ch)
{
mode = Token.UNKNOWN;
if (Char.IsLetter (ch) || startIdChars.IndexOf (ch) != -1) {
mode = Token.ID;
} else if (ch == '\'') {
mode = Token.SQSTRING;
} else if (ch == '"') {
mode = Token.QSTRING;
}
return (mode != Token.UNKNOWN);
}
private static bool IsIdChar (int c)
{
char ch = (char) c;
return (Char.IsLetterOrDigit(ch) || idChars.IndexOf (ch) != -1);
}
/// <summary>
/// </summary>
/// <returns></returns>
public override string Build ()
{
if (mode == Token.UNKNOWN) return String.Empty;
int ch = 0;
ILReader reader = host.Reader;
StringBuilder idsb = new StringBuilder ();
if (mode == Token.SQSTRING || mode == Token.QSTRING) {
int term = (mode == Token.SQSTRING) ? '\'' : '"';
reader.Read (); // skip quote
for (ch = reader.Read (); ch != -1; ch = reader.Read ()) {
if (ch == term) {
break;
}
if (ch == '\\') {
ch = reader.Read ();
/*
* Long string can be broken across multiple lines
* by using '\' as the last char in line.
* Any white space chars between '\' and the first
* char on the next line are ignored.
*/
if (ch == '\n') {
reader.SkipWhitespace ();
continue;
}
int escaped = Escape (reader, ch);
if (escaped == -1) {
reader.Unread (ch);
ch = '\\';
} else {
ch = escaped;
}
}
idsb.Append((char)ch);
}
} else { // ID
while ((ch = reader.Read ()) != -1) {
if (IsIdChar (ch)) {
idsb.Append ((char) ch);
} else {
reader.Unread (ch);
break;
}
}
}
return idsb.ToString ();
}
/// <summary>
/// </summary>
/// <param name="ch"></param>
/// <returns></returns>
public static int Escape (ILReader reader, int ch)
{
int res = -1;
if (ch >= '0' && ch <='7') {
StringBuilder octal = new StringBuilder ();
octal.Append ((char)ch);
int possibleOctalChar = reader.Peek ();
if (possibleOctalChar >= '0' && possibleOctalChar <='7') {
octal.Append ((char)reader.Read ());
possibleOctalChar = reader.Peek ();
if (possibleOctalChar >= '0' && possibleOctalChar <='7')
octal.Append ((char)reader.Read ());
}
res = Convert.ToInt32(octal.ToString (), 8);
} else {
int id = "abfnrtv\"'\\".IndexOf ((char)ch);
if (id != -1) {
res = "\a\b\f\n\r\t\v\"'\\" [id];
}
}
return res;
}
}
}

View File

@@ -0,0 +1,63 @@
// StringHelperBase.cs
// Author: Sergey Chaban (serge@wildwestsoftware.com)
using System;
using System.Text;
namespace Mono.ILASM {
/// <summary>
/// </summary>
internal abstract class StringHelperBase {
protected ILTokenizer host;
protected int mode;
/// <summary>
/// </summary>
/// <param name="host"></param>
public StringHelperBase (ILTokenizer host) {
this.host = host;
mode = Token.UNKNOWN;
}
/// <summary>
/// </summary>
/// <returns></returns>
public abstract bool Start (char ch);
/// <summary>
/// </summary>
/// <returns></returns>
public bool Start (int ch)
{
return Start ((char)ch);
}
/// <summary>
/// </summary>
/// <returns></returns>
public bool Start ()
{
return Start (host.Reader.Peek ());
}
/// <summary>
/// </summary>
/// <returns></returns>
public abstract string Build ();
/// <summary>
/// </summary>
public int TokenId {
get {
return mode;
}
}
}
}