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);
}
}
}
}
}
}
我是C#的新手,我被卡在如何遍歷program.TopLevelDeclarations
。如何在使用Mono編譯時引用Microsoft.Boogie?
試圖迭代一個簡單的列表,但當我嘗試包括Microsoft Boogie庫時,編譯器會拋出一些錯誤。
我編譯在Ubuntu 13.04使用gmcs
使用命令我的程序:
gmcs -r:../../boogie/Binaries/Boogie.exe -r:../../boogie/Binaries/Core.dll Trace.cs
其中給出了以下錯誤:
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
有誰知道如何解決這一問題?我是否錯誤地包括了圖書館?
機器上的庫是否存在?你在使用Mono框架嗎?另外,如果你在Ubuntu上,你可以使用[MonoDevelop](http://monodevelop.com/Download)而不是手動編譯,這將爲你解決大部分這些問題。 – valverij
是的,我正在使用MonoDevelop – anirudh