本文整理汇总了C#中ITypeDefinition.Token方法的典型用法代码示例。如果您正苦于以下问题:C# ITypeDefinition.Token方法的具体用法?C# ITypeDefinition.Token怎么用?C# ITypeDefinition.Token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITypeDefinition
的用法示例。
在下文中一共展示了ITypeDefinition.Token方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateStructCopyConstructor
private void CreateStructCopyConstructor(ITypeDefinition typeDefinition) {
Contract.Requires(typeDefinition.IsStruct);
var proc = this.sink.FindOrCreateProcedureForStructCopy(typeDefinition);
var stmtBuilder = new Bpl.StmtListBuilder();
var tok = Bpl.Token.NoToken;
var o = Bpl.Expr.Ident(proc.OutParams[0]);
// other := Alloc();
stmtBuilder.Add(new Bpl.CallCmd(tok, this.sink.AllocationMethodName, new List<Bpl.Expr>(), new List<Bpl.IdentifierExpr>(new Bpl.IdentifierExpr[] {o})));
// assume DynamicType(other) == DynamicType(this);
stmtBuilder.Add(new Bpl.AssumeCmd(tok, Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Eq, this.sink.Heap.DynamicType(o), this.sink.Heap.DynamicType(Bpl.Expr.Ident(proc.InParams[0])))));
var localVars = new List<Bpl.Variable>();
foreach (var f in typeDefinition.Fields) {
if (f.IsStatic) continue;
var fExp = Bpl.Expr.Ident(this.sink.FindOrCreateFieldVariable(f));
var boogieType = sink.CciTypeToBoogie(f.Type);
if (TranslationHelper.IsStruct(f.Type)) {
// generate a call to the copy constructor to copy the contents of f
var proc2 = this.sink.FindOrCreateProcedureForStructCopy(f.Type);
var e = this.sink.Heap.ReadHeap(Bpl.Expr.Ident(proc.InParams[0]), fExp, AccessType.Struct, boogieType);
var bplLocal = this.sink.CreateFreshLocal(f.Type);
var localExpr = Bpl.Expr.Ident(bplLocal);
localVars.Add(bplLocal);
var cmd = new Bpl.CallCmd(tok, proc2.Name, new List<Bpl.Expr> { e, }, new List<Bpl.IdentifierExpr>{ localExpr, });
stmtBuilder.Add(cmd);
this.sink.Heap.WriteHeap(tok, o, fExp, localExpr, AccessType.Struct, boogieType, stmtBuilder);
} else {
// just generate a normal assignment to the field f
var e = this.sink.Heap.ReadHeap(Bpl.Expr.Ident(proc.InParams[0]), fExp, AccessType.Struct, boogieType);
this.sink.Heap.WriteHeap(tok, o, fExp, e, AccessType.Struct, boogieType, stmtBuilder);
}
}
var lit = Bpl.Expr.Literal(1);
lit.Type = Bpl.Type.Int;
var args = new List<object> { lit };
var attrib = new Bpl.QKeyValue(typeDefinition.Token(), "inline", args, null);
Bpl.Implementation impl =
new Bpl.Implementation(Bpl.Token.NoToken,
proc.Name,
new List<Bpl.TypeVariable>(),
proc.InParams,
proc.OutParams,
localVars,
stmtBuilder.Collect(Bpl.Token.NoToken),
attrib,
new Bpl.Errors()
);
impl.Proc = (Bpl.Procedure)proc; // TODO: get rid of cast
this.sink.TranslatedProgram.AddTopLevelDeclaration(impl);
}
示例2: translateAnonymousControlsForPage
/*
private void translateAnonymousControlsForPage(ITypeDefinition typeDef) {
if (PhoneCodeHelper.instance().PhonePlugin != null && typeDef.isPhoneApplicationPageClass(sink.host)) {
IEnumerable<ControlInfoStructure> pageCtrls= PhoneCodeHelper.instance().PhonePlugin.getControlsForPage(typeDef.ToString());
foreach (ControlInfoStructure ctrlInfo in pageCtrls) {
if (ctrlInfo.Name.Contains(PhoneControlsPlugin.BOOGIE_DUMMY_CONTROL) || ctrlInfo.Name == Dummy.Name.Value) {
string anonymousControlName = ctrlInfo.Name;
IFieldDefinition fieldDef = new FieldDefinition() {
ContainingTypeDefinition = typeDef,
Name = sink.host.NameTable.GetNameFor(anonymousControlName),
InternFactory = sink.host.InternFactory,
Visibility = TypeMemberVisibility.Public,
Type = sink.host.PlatformType.SystemObject,
IsStatic = false,
};
(typeDef as Microsoft.Cci.MutableCodeModel.NamespaceTypeDefinition).Fields.Add(fieldDef);
//sink.FindOrCreateFieldVariable(fieldDef);
}
}
}
}
*/
private void CreateDefaultStructConstructor(ITypeDefinition typeDefinition) {
Contract.Requires(typeDefinition.IsStruct);
var proc = this.sink.FindOrCreateProcedureForDefaultStructCtor(typeDefinition);
this.sink.BeginMethod(typeDefinition);
var stmtTranslator = this.Factory.MakeStatementTraverser(this.sink, this.PdbReader, false);
var stmts = new List<IStatement>();
foreach (var f in typeDefinition.Fields) {
if (f.IsStatic) continue;
var s = new ExpressionStatement() {
Expression = new Assignment() {
Source = new DefaultValue() { DefaultValueType = f.Type, Type = f.Type, },
Target = new TargetExpression() {
Definition = f,
Instance = new ThisReference() { Type = typeDefinition, },
Type = f.Type,
},
Type = f.Type,
},
};
stmts.Add(s);
}
stmtTranslator.Traverse(stmts);
var translatedStatements = stmtTranslator.StmtBuilder.Collect(Bpl.Token.NoToken);
var lit = Bpl.Expr.Literal(1);
lit.Type = Bpl.Type.Int;
var args = new List<object> { lit };
var attrib = new Bpl.QKeyValue(typeDefinition.Token(), "inline", args, null); // TODO: Need to have it be {:inine 1} (and not just {:inline})?
List<Bpl.Variable> vars = new List<Bpl.Variable>();
foreach (Bpl.Variable v in this.sink.LocalVarMap.Values) {
vars.Add(v);
}
List<Bpl.Variable> vseq = new List<Bpl.Variable>(vars.ToArray());
Bpl.Implementation impl =
new Bpl.Implementation(Bpl.Token.NoToken,
proc.Name,
new List<Bpl.TypeVariable>(),
proc.InParams,
proc.OutParams,
vseq,
translatedStatements,
attrib,
new Bpl.Errors()
);
impl.Proc = (Bpl.Procedure) proc; // TODO: get rid of cast
this.sink.TranslatedProgram.AddTopLevelDeclaration(impl);
}