本文整理汇总了C#中Program.Modules方法的典型用法代码示例。如果您正苦于以下问题:C# Program.Modules方法的具体用法?C# Program.Modules怎么用?C# Program.Modules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Program
的用法示例。
在下文中一共展示了Program.Modules方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HasMain
public bool HasMain(Program program)
{
Method mainMethod = null;
bool hasMain = false;
foreach (var module in program.Modules()) {
if (module.IsAbstract) {
// the purpose of an abstract module is to skip compilation
continue;
}
foreach (var decl in module.TopLevelDecls) {
var c = decl as ClassDecl;
if (c != null) {
foreach (var member in c.Members) {
var m = member as Method;
if (m != null && IsMain(m)) {
if (mainMethod == null) {
mainMethod = m;
hasMain = true;
} else {
// more than one main in the program
ErrorWriter.WriteLine("More than one method is declared as \"main\"");
errorCount++;
hasMain = false;
}
}
}
}
}
}
return hasMain;
}
示例2: Compile
public void Compile(Program program, TextWriter wr)
{
Contract.Requires(program != null);
// program.Name is the source filename without any path. Remove the extension
// and use it as the name of the default module. In C#, this would have been
// "_module". See WriteLident() for the renaming process.
DafnyDefaultModuleName = System.IO.Path.GetFileNameWithoutExtension(program.Name).Replace('.', '_');
// Kremlin's JSON input is all JSON arrays, not serialized objects in the usual way.
// [6, [
// ["FStar_Mul", []],
// ["FStar_UInt", [
// ["DFunction", [
// ["TUnit"], "FStar_UInt_lognot_lemma_2", [{
// "name": "n",
// "typ": ["TQualified", [
// ["Prims"], "pos"
// ]],
// "mut": false,
// "mark": 0
// }],
// ["EUnit"]
// ]]
// ]], ...
j = new JsonTextWriter(wr);
j.Formatting = Formatting.Indented;
j.Indentation = 1;
using (WriteArray()) { // Entire contents is an array - type binary_format
j.WriteRawValue(KremlinAst.Version); // binary_format = version * file list
using (WriteArray()) { // start of file list
// bugbug: generate builtins as needed
//CompileBuiltIns(program.BuiltIns);
// Compile modules in order by height (program.Modules is sorted this way but in
// reverse order). Compile SystemModule last, as it has height -1 and is not in
// the .Modules list.
List<ModuleDefinition> sortedModules = new List<ModuleDefinition>(program.Modules());
sortedModules.Reverse();
int previousHeight = sortedModules[0].Height+1;
foreach (ModuleDefinition m in sortedModules) {
Contract.Assert(m.Height < previousHeight); // .Modules is sorted
CompileModule(m, wr);
previousHeight = m.Height;
}
CompileModule(program.BuiltIns.SystemModule, wr);
} // End of file list
} // End of entire contents
j.Close();
}