using System;
using System.Collections.Generic;
using Microsoft.Boogie;
public class Trace
{
public static void Main(string[] args)
{
if (args.Length != 2){
return;
}
Program program = new Program();
List<string> defines = new List<string>();
Parser.Parse(args[0], defines, out program);
string[] lines = System.IO.File.ReadAllLines(args[1]);
Dictionary< Block, List<Block> > adj = new Dictionary< Block, List<Block> >();
foreach (Declaration D in program.TopLevelDeclarations){
Implementation I = D as Implementation;
if(I != null){
foreach (Block B in I.Blocks){
object cmd = B.TransferCmd;
if(cmd is GotoCmd){
List<Block> target = cmd.labelTargets;
adj.insert(B, target);
}
else if(cmd is ReturnCmd){
adj.insert(B, null);
}
}
}
}
}
}
I am new to C# and I am stuck on how to iterate over program.TopLevelDeclarations
.
Trying to iterate over a simple list works but when I try to include the Microsoft Boogie library, the compiler throws a few errors.
I am compiling my program using gmcs
on Ubuntu 13.04 using the command:
gmcs -r:../../boogie/Binaries/Boogie.exe -r:../../boogie/Binaries/Core.dll Trace.cs
Which gives the following errors:
Missing method .ctor in assembly /home/boogie/Binaries/Core.dll, type System.Diagnostics.Contracts.ContractClassAttribute
Can`t find custom attr constructor image: /home/boogie/Binaries/Core.dll mtoken: 0x0a000463
Trace.cs(19,52): error CS0584: Internal compiler error: Could not load type
System.Diagnostics.Contracts.ContractClassAttribute
from assemblyCore
.Trace.cs(19,36): error CS0266: Cannot implicitly convert type
object
toSystem.Collections.Generic.List<Microsoft.Boogie.Declaration>
. An explicit conversion exists (are you missing a cast?)Trace.cs(22,30): error CS0584: Internal compiler error: Could not import type
Microsoft.Boogie.Implementation
fromCore, Version=2.2.30705.1126, Culture=neutral, PublicKeyToken=736440c9b414ea16
Trace.cs(22,30): error CS0266: Cannot implicitly convert type
object
tobool
. An explicit conversion exists (are you missing a cast?)Trace.cs(23,55): error CS0584: Internal compiler error: Could not import type
Microsoft.Boogie.Implementation
fromCore, Version=2.2.30705.1126, Culture=neutral, PublicKeyToken=736440c9b414ea16
Trace.cs(23,33): error CS1579: foreach statement cannot operate on variables of type
object
because it does not contain a definition forGetEnumerator
or is inaccessibleCompilation failed: 6 error(s), 0 warnings
Does anyone know how to fix this? Am I including the libraries incorrectly?
I can't seem to find the source of Microsoft.Boogie.Declaration
, but given the error messages it has a [ContractClass]
attribute, which the compiler cannot find:
Trace.cs(19,52): error CS0584: Internal compiler error: Could not load type 'System.Diagnostics.Contracts.ContractClassAttribute' from assembly 'Core'.
Because of this the type Microsoft.Boogie.Declaration
cannot be loaded, causing the List<Declaration>
of program.TopLevelDeclarations
to apparently be "stubbed" of some sort as an object
. This in turn causes your code to fail, because you can't iterate over an object.
The ContractClassAttribute
was added to mscorlib
in .NET 4. You're using gmcs
, which according to mono's CSharp Compiler manual page compiles against .NET 2.0.
I think you better compile using mcs
, which is recommended there.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments