本文整理汇总了C#中StatementList.Add方法的典型用法代码示例。如果您正苦于以下问题:C# StatementList.Add方法的具体用法?C# StatementList.Add怎么用?C# StatementList.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StatementList
的用法示例。
在下文中一共展示了StatementList.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitReturnValue
public override Expression VisitReturnValue(ReturnValue returnValue)
{
// return a default value of the same type as the return value
TypeNode returnType = returnValue.Type;
ITypeParameter itp = returnType as ITypeParameter;
if (itp != null)
{
Local loc = new Local(returnType);
UnaryExpression loca = new UnaryExpression(loc, NodeType.AddressOf, loc.Type.GetReferenceType());
StatementList statements = new StatementList(2);
statements.Add(new AssignmentStatement(new AddressDereference(loca, returnType, false, 0),
new Literal(null, SystemTypes.Object)));
statements.Add(new ExpressionStatement(loc));
return new BlockExpression(new Block(statements), returnType);
}
if (returnType.IsValueType)
return new Literal(0, returnType);
return new Literal(null, returnType);
}
示例2: Parse
public GeneratedCode Parse(List<Token> _tokens)
{
Dictionary<string, Function> Functions = new Dictionary<string, Function>();
StatementList TopLevelStatements = new StatementList();
Tokens = _tokens;
Position = 0;
GetNextToken(); //Initialize first token
while (true)
{
if (CurToken.Type == TokenType.EOF)
break;
if (CurToken.IsCharacter(";"))
GetNextToken(); //eat ;
else if (CurToken.IsIdentifier("function"))
{
Function func = ParseFunction();
Functions[func.Name] = func;
}
else
TopLevelStatements.Add(ParseStatement());
}
Function TopLevel = new Function(TopLevelStatements);
return new GeneratedCode()
{
TopLevelStatements = TopLevel,
Functions = Functions
};
}
示例3: VisitBranch
public override Statement VisitBranch(Branch branch){
if (branch == null) return null;
if (branch.Target == null) return null;
branch.Condition = this.VisitExpression(branch.Condition);
int n = this.localsStack.top+1;
LocalsStack targetStack = (LocalsStack)this.StackLocalsAtEntry[branch.Target.UniqueKey];
if (targetStack == null){
this.StackLocalsAtEntry[branch.Target.UniqueKey] = this.localsStack.Clone();
return branch;
}
//Target block has an entry stack that is different from the current stack. Need to copy stack before branching.
if (n <= 0) return branch; //Empty stack, no need to copy
StatementList statements = new StatementList(n+1);
this.localsStack.Transfer(targetStack, statements);
statements.Add(branch);
return new Block(statements);
}
示例4: VisitReturn
//public override Block VisitBlock(Block block) {
// if(block.Statements != null && block.Statements.Count == 1) {
// Return r = block.Statements[0] as Return;
// if(r != null) {
// Statement s = this.VisitReturn(r);
// Block retBlock = s as Block;
// if(retBlock != null) {
// block.Statements = retBlock.Statements;
// return block;
// } else {
// return base.VisitBlock(block);
// }
// } else {
// return base.VisitBlock(block);
// }
// } else {
// return base.VisitBlock(block);
// }
//}
public override Statement VisitReturn(Return Return)
{
if (Return == null)
{
return null;
}
returnCount++;
this.lastReturnSourceContext = Return.SourceContext;
StatementList stmts = new StatementList();
Return.Expression = this.VisitExpression(Return.Expression);
if (Return.Expression != null)
{
MethodCall mc = Return.Expression as MethodCall;
if (mc != null && mc.IsTailCall)
{
mc.IsTailCall = false;
}
var assgnmt = new AssignmentStatement(result, Return.Expression);
assgnmt.SourceContext = Return.SourceContext;
stmts.Add(assgnmt);
}
// the branch is a "leave" out of the try block that the body will be
// in.
var branch = new Branch(null, newExit, false, false, this.leaveExceptionBody);
branch.SourceContext = Return.SourceContext;
stmts.Add(branch);
return new Block(stmts);
}
示例5: AddReadAllGroup
void AddReadAllGroup(Class serializer, Block block, TypeNode type, StatementList statements, Identifier reader,
Expression target, Expression required, Expression result, ArrayList members, Member mixedMember) {
// todo: keep track of which members have been read and report error on duplicates
MethodCall read = new MethodCall(new QualifiedIdentifier(reader, Identifier.For("Read")), new ExpressionList());
Local sb = new Local(SystemTypes.StringBuilder);
bool isMixed = mixedMember != null;
if (isMixed) {
statements.Add(new AssignmentStatement(sb,
new Construct(new MemberBinding(null, SystemTypes.StringBuilder), new ExpressionList(), SystemTypes.StringBuilder)));
}
Block whileBody = new Block(new StatementList());
BinaryExpression notEndTag = new BinaryExpression(
new QualifiedIdentifier(reader, Identifier.For("NodeType")) ,
new QualifiedIdentifier(Identifier.For("XmlNodeType"), Identifier.For("EndElement")), NodeType.Ne);
BinaryExpression notEOF = new BinaryExpression(
new QualifiedIdentifier(reader, Identifier.For("EOF")), Literal.True, NodeType.Ne);
While w = new While(new BinaryExpression(notEndTag, notEOF, NodeType.And), whileBody);
statements.Add(w);
Local nameLocal = new Local(Identifier.For("name"),SystemTypes.String,block);
Local nsLocal = new Local(Identifier.For("ns"),SystemTypes.String,block);
Local nodeType = new Local(Identifier.For("nodeType"),Runtime.XmlNodeType,block);
whileBody.Statements.Add(new AssignmentStatement(nameLocal, new QualifiedIdentifier(reader, Identifier.For("LocalName"))));
whileBody.Statements.Add(new AssignmentStatement(nsLocal, new QualifiedIdentifier(reader, Identifier.For("NamespaceURI"))));
whileBody.Statements.Add(new AssignmentStatement(nodeType, new QualifiedIdentifier(reader, Identifier.For("NodeType"))));
Block childBlock = whileBody;
if (isMixed) {
// Append the text node to the current StringBuilder contents.
childBlock = new Block(new StatementList());
If ifText = new If(IsTextNode(nodeType), new Block(new StatementList()), childBlock);
whileBody.Statements.Add(ifText);
ExpressionList args = new ExpressionList();
args.Add(new QualifiedIdentifier(reader, Identifier.For("Value")));
ifText.TrueBlock.Statements.Add(new ExpressionStatement(new MethodCall(
new QualifiedIdentifier(sb, Identifier.For("Append")), args)));
ifText.TrueBlock.Statements.Add(new ExpressionStatement(read)); // advance to next node
}
If ifElement = new If(new BinaryExpression(nodeType,
new QualifiedIdentifier(Identifier.For("XmlNodeType"), Identifier.For("Element")), NodeType.Eq),
new Block(new StatementList()), new Block(new StatementList()));
childBlock.Statements.Add(ifElement);
childBlock = ifElement.TrueBlock;
//AddConsoleWrite(statements, new Literal("name=",SystemTypes.String));
//AddConsoleWriteLine(statements, nameLocal);
//AddConsoleWrite(statements, new Literal("nodeType=",SystemTypes.String));
//AddConsoleWriteLine(statements, nodeType);
foreach (NamedNode childNode in members) {
if (!(childNode.Member is Field || childNode.Member is Property)) {
AddError(statements, reader, RuntimeError.SerializationOfTypeNotSupported,
new Literal(childNode.Member.GetType().FullName, SystemTypes.String));
} else {
Expression mb = GetMemberBinding(target, childNode.Member);
childBlock = AddReadChild(block, childBlock.Statements, childNode.Name, childNode.TypeNode, mb, reader, result, true, false).FalseBlock;
// todo: throw error if child is required. (e.g. NonEmptyIEnumerable...)
}
}
// if it isn't any of the expected elements then throw an error.
AddError(childBlock.Statements, reader, RuntimeError.NoSuchMember,
new Expression[2]{new Literal(tempChecker.GetTypeName(type),SystemTypes.String), nameLocal});
// If it's not an element then consume it anyway to keep the reader advancing.
// Probably a comment or PI or something.
ifElement.FalseBlock.Statements.Add(new ExpressionStatement(new MethodCall(
new QualifiedIdentifier(reader, Identifier.For("Skip")), new ExpressionList())));
if (isMixed) {
statements.Add(new AssignmentStatement(GetMemberBinding(target, mixedMember),
new MethodCall(new QualifiedIdentifier(sb, Identifier.For("ToString")), new ExpressionList())));
}
statements.Add(new AssignmentStatement(result, Literal.True));
}
示例6: AddReadContent
void AddReadContent(Class serializer, Block block, TypeNode type, StatementList statements, Identifier reader,
Expression target, Expression required, Expression result, SchemaValidator validator) {
// position us in the content.
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(reader, Identifier.For("MoveToContent")), new ExpressionList())));
Local elementName = new Local(Identifier.Empty,SystemTypes.String);
statements.Add(new AssignmentStatement(elementName, new QualifiedIdentifier(reader, Identifier.For("LocalName"))));
// make sure the element is not empty.
If isEmpty = AddEmptyElementCheck(statements, reader);
// Read the contents.
statements = isEmpty.FalseBlock.Statements;
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(reader, Identifier.For("Read")), new ExpressionList())));
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(reader, Identifier.For("MoveToContent")), new ExpressionList())));
ValidationState context = new ValidationState();
context.ErrorHandler = this.errorHandler;
validator.validator.InitValidation(context);
ArrayList members = null;
if (validator.validator is AllElementsContentValidator) {
members = validator.validator.ExpectedElements(context, false, false);
AddReadAllGroup(serializer, block, type, statements, reader, target, required, result, members, validator.validator.MixedMember);
} else {
// There should be one root level anonymous Item0 member.
SequenceNode seq = (SequenceNode)validator.RootNode; // this is a wrapper node.
if (seq == null) {
// perhaps it is ContentType.Empty or Mixed.
if (validator.validator.ContentType == XmlSchemaContentType.Mixed ||
validator.validator.ContentType == XmlSchemaContentType.TextOnly){
Debug.Assert(validator.validator.MixedMember != null);
statements.Add(new AssignmentStatement(GetMemberBinding(target, validator.validator.MixedMember),
new MethodCall(new QualifiedIdentifier(reader, Identifier.For("ReadStringElement")), new ExpressionList())));
}
return;
} else {
ContentNode n = seq.LeftChild;
AddReadContentNode(n, block, statements, reader, target, required, result, validator);
}
}
// consume final end tag
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(reader, Identifier.For("ReadEndTag")), new ExpressionList(elementName))));
}
示例7: AddWriteStream
void AddWriteStream(TypeNode type, StatementList statements, TypeNode referringType, Expression src, Identifier writer) {
// Generate the following code:
// XxxxSerializer s = new XxxxSerializer();
// foreach (Xxxx x in src) {
// s.Serialize(x,writer);
// }
// Where Xxxx is the element type for the given stream type.
if (type.Template == SystemTypes.GenericNonEmptyIEnumerable) {
type = Checker.GetIEnumerableTypeFromNonEmptyIEnumerableStruct(this.module, type);
} else {
statements = AddCheckForNull(statements, Duplicate(src, referringType), type);
}
TypeNode ceType = Checker.GetCollectionElementType(type);
//todo: should check that type has an IEnumerator.
Identifier loopVariable = Identifier.For("e");
loopVariable.Type = ceType;
Block body = new Block();
body.Statements = new StatementList();
Expression name, ns;
GetNameAndNamespace(ceType, out name, out ns);
// call the Serialize method on it, passing the member we're serializing.
if (!AddWriteSimpleType(ceType, body.Statements, referringType, writer, loopVariable, name, ns)) {
AddCallSerializer(ceType, body.Statements, loopVariable, writer, name, ns);
}
ForEach fe = new ForEach(ceType, loopVariable, src, body);
statements.Add(fe);
}
示例8: AddCallSerializer
void AddCallSerializer(TypeNode srcType, StatementList statements, Expression src, Identifier writer, Expression rootName, Expression rootNamespace ) {
TypeNode type = Unwrap(srcType);
Class memberSerializer = this.CreateSerializerFor(type);
// call the Serialize method on it, passing the member we're serializing.
ExpressionList args = new ExpressionList();
args.Add(src);
args.Add(writer);
args.Add(rootName);
args.Add(rootNamespace);
MethodCall call = new MethodCall();
Method serialize = memberSerializer.GetMethod(Identifier.For("Serialize"), new TypeNode[4] { type, Runtime.XmlSerializationWriter, SystemTypes.String, SystemTypes.String} );
call.Callee = new MemberBinding(new MemberBinding(null, memberSerializer), serialize);
call.Operands = args;
statements.Add( new ExpressionStatement( call ) );
}
示例9: AddCheckForNull
StatementList AddCheckForNull(StatementList statements, Expression src, TypeNode type) {
if (type.Template == SystemTypes.GenericBoxed) {
If checknull = new If(new BinaryExpression(
new MethodCall(new MemberBinding(src, type.GetMethod(Identifier.For("IsNull"),null)), new ExpressionList()),
Literal.True, NodeType.Ne),
new Block(new StatementList()), null);
statements.Add(checknull);
return checknull.TrueBlock.Statements;
}
else if (type is TypeAlias) {
// cast to underlying type and check that for null.
TypeNode atype = ((TypeAlias)type).AliasedType;
return AddCheckForNull(statements, CastTo(src, atype), atype);
}
else if (type is ConstrainedType) {
// cast to underlying type and check that for null.
TypeNode atype = ((ConstrainedType)type).UnderlyingType;
return AddCheckForNull(statements, CastTo(src, atype), atype);
}
else if (!IsStream(type) && !type.IsValueType) { //stream types are doing weird things to the null check?
if (type == SystemTypes.String || IsStream(type))
src = CastTo(src, SystemTypes.Object);
If checknull = new If(new BinaryExpression(src, Literal.Null, NodeType.Ne),
new Block(new StatementList()), null);
statements.Add(checknull);
return checknull.TrueBlock.Statements;
}
return statements;
}
示例10: AddWriteSimpleAttribute
bool AddWriteSimpleAttribute(TypeNode type, Identifier name, StatementList statements, TypeNode referringType, Identifier writer, Expression src) {
ExpressionList args = new ExpressionList();
args.Add(GetXmlNameFromId(name));
args.Add(GetXmlNamespaceFromId(name));
args.Add(src);
if (type == SystemTypes.String) {
statements = AddCheckForNull(statements, Duplicate(src, referringType), type);
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(writer, Identifier.For("WriteAttributeString")), args)));
} else if( type == SystemTypes.Boolean) {
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(writer, Identifier.For("WriteAttributeBoolean")), args)));
} else if( type == SystemTypes.Int8) {
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(writer, Identifier.For("WriteAttributeSByte")), args)));
} else if( type == SystemTypes.Char) {
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(writer, Identifier.For("WriteAttributeChar")), args)));
} else if( type == SystemTypes.DateTime) {
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(writer, Identifier.For("WriteAttributeDateTime")), args)));
} else if( type == SystemTypes.Decimal) {
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(writer, Identifier.For("WriteAttributeDecimal")), args)));
} else if( type == SystemTypes.Double) {
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(writer, Identifier.For("WriteAttributeDouble")), args)));
} else if( type == SystemTypes.Guid) {
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(writer, Identifier.For("WriteAttributeGuid")), args)));
} else if( type == SystemTypes.Int16) {
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(writer, Identifier.For("WriteAttributeInt16")), args)));
} else if( type == SystemTypes.Int32) {
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(writer, Identifier.For("WriteAttributeInt32")), args)));
} else if( type == SystemTypes.Int64) {
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(writer, Identifier.For("WriteAttributeInt64")), args)));
} else if( type == SystemTypes.UInt8) {
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(writer, Identifier.For("WriteAttributeByte")), args)));
} else if( type == SystemTypes.Single) {
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(writer, Identifier.For("WriteAttributeSingle")), args)));
} else if( type == SystemTypes.TimeSpan) {
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(writer, Identifier.For("WriteAttributeTimeSpan")), args)));
} else if( type == SystemTypes.UInt16 ) {
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(writer, Identifier.For("WriteAttributeUInt16")), args)));
} else if( type == SystemTypes.UInt32) {
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(writer, Identifier.For("WriteAttributeUInt32")), args)));
} else if( type == SystemTypes.UInt64) {
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(writer, Identifier.For("WriteAttributeUInt64")), args)));
} else {
Expression conversion = GetConvertToString(type, src, true);
if (conversion != null) {
statements = AddCheckForNull(statements, Duplicate(src, referringType), type);
ExpressionList args2 = new ExpressionList();
args2.Add(args[0]);
args2.Add(args[1]);
args2.Add(conversion);
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(writer, Identifier.For("WriteAttributeString")), args2)));
} else {
return false;
}
}
return true;
}
示例11: AddReadOptional
void AddReadOptional(Block block, StatementList statements, Member mem, Expression target, Identifier reader, Expression result) {
TypeNode boxed = Checker.GetMemberType(mem);
TypeNode type = Checker.GetCollectionElementType(boxed);
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(reader, Identifier.For("MoveToContent")), new ExpressionList())));
Local nameLocal = new Local(Identifier.For("name"),SystemTypes.String, block);
Local nsLocal = new Local(Identifier.For("ns"),SystemTypes.String, block);
statements.Add(new AssignmentStatement(nameLocal, new QualifiedIdentifier(reader, Identifier.For("LocalName"))));
statements.Add(new AssignmentStatement(nsLocal, new QualifiedIdentifier(reader, Identifier.For("NamespaceURI"))));
StringBuilder expecting = new StringBuilder();
Expression isFound = null;
if (mem.IsAnonymous) {
isFound = IsStartOf(block, type, statements, nameLocal, nsLocal, expecting);
} else {
ExpressionList args = new ExpressionList();
args.Add(new Literal(mem.Name.Name, SystemTypes.String));
isFound = new MethodCall(new QualifiedIdentifier(reader, Identifier.For("IsStartElement")), args);
}
StatementList trueStatements = new StatementList();
If ifIsFound = new If(isFound, new Block(trueStatements), null);
statements.Add(ifIsFound);
if (!AddReadSimpleType(type, trueStatements, reader, target, result, false)) {
Local localRequired = new Local(Identifier.Empty,SystemTypes.Boolean,block);
statements.Add(new AssignmentStatement(localRequired, Literal.True));
AddCallDeserializer(type, trueStatements, reader, target, localRequired, result);
}
}
示例12: InjectDefaultConstructor
public override InstanceInitializer InjectDefaultConstructor(TypeNode typeNode) {
if (this.DontInjectDefaultConstructors || typeNode.IsNormalized) return null;
Class Class = typeNode as Class;
if (Class != null && Class.Name != null && !(Class is ClassParameter) && ClassHasNoExplicitConstructors(typeNode)) {
if (Class.IsAbstractSealedContainerForStatics) return null;
if (Class.PartiallyDefines != null){
this.InjectDefaultConstructor(Class.PartiallyDefines);
InstanceInitializer defCons = Class.PartiallyDefines.GetConstructor();
if (defCons != null && !defCons.HasCompilerGeneratedSignature)
defCons = null; //Not an orphan
if (defCons != null){
//This is an injected default constructor that is an orphan, adopt it
defCons.HasCompilerGeneratedSignature = false; //abuse this flag to stop other partial types from adopting it
Class.Members.Add(defCons);
Class.BaseClass = ((Class)Class.PartiallyDefines).BaseClass;
}
return defCons; //Ok if defCons null, this type should not show up in inheritance chains
}else{
//Inject a default constructor
This thisParameter = new This(Class);
Class baseClass = Class.BaseClass;
StatementList statements = new StatementList(2);
statements.Add(new FieldInitializerBlock(typeNode, false));
if (baseClass != null) {
MethodCall mcall = new MethodCall(new QualifiedIdentifier(new Base(), StandardIds.Ctor, typeNode.Name.SourceContext), null);
mcall.SourceContext = typeNode.Name.SourceContext;
ExpressionStatement callSupCons = new ExpressionStatement(mcall);
callSupCons.SourceContext = typeNode.Name.SourceContext;
statements.Add(callSupCons);
}
InstanceInitializer defCons = new InstanceInitializer(typeNode, null, null, new Block(statements));
defCons.Name = new Identifier(".ctor", typeNode.Name.SourceContext);
defCons.SourceContext = typeNode.Name.SourceContext;
defCons.ThisParameter = thisParameter;
if (typeNode.IsAbstract)
defCons.Flags |= MethodFlags.Family|MethodFlags.HideBySig;
else
defCons.Flags |= MethodFlags.Public|MethodFlags.HideBySig;
defCons.CallingConvention = CallingConventionFlags.HasThis;
defCons.IsCompilerGenerated = true;
typeNode.Members.Add(defCons);
return defCons;
}
}
return null;
}
示例13: VisitStatementList
public virtual Differences VisitStatementList(StatementList list1, StatementList list2,
out StatementList changes, out StatementList deletions, out StatementList insertions){
changes = list1 == null ? null : list1.Clone();
deletions = list1 == null ? null : list1.Clone();
insertions = list1 == null ? new StatementList() : list1.Clone();
//^ assert insertions != null;
Differences differences = new Differences();
for (int j = 0, n = list2 == null ? 0 : list2.Count; j < n; j++){
//^ assert list2 != null;
Statement nd2 = list2[j];
if (nd2 == null) continue;
insertions.Add(null);
}
TrivialHashtable savedDifferencesMapFor = this.differencesMapFor;
this.differencesMapFor = null;
TrivialHashtable matchedNodes = new TrivialHashtable();
for (int i = 0, k = 0, n = list1 == null ? 0 : list1.Count; i < n; i++){
//^ assert list1 != null && changes != null && deletions != null;
Statement nd1 = list1[i];
if (nd1 == null) continue;
Differences diff;
int j;
Statement nd2 = this.GetClosestMatch(nd1, list1, list2, i, ref k, matchedNodes, out diff, out j);
if (nd2 == null || diff == null){Debug.Assert(nd2 == null && diff == null); continue;}
matchedNodes[nd1.UniqueKey] = nd1;
matchedNodes[nd2.UniqueKey] = nd2;
changes[i] = diff.Changes as Statement;
deletions[i] = diff.Deletions as Statement;
insertions[i] = diff.Insertions as Statement;
insertions[n+j] = nd1; //Records the position of nd2 in list2 in case the change involved a permutation
Debug.Assert(diff.Changes == changes[i] && diff.Deletions == deletions[i] && diff.Insertions == insertions[i]);
differences.NumberOfDifferences += diff.NumberOfDifferences;
differences.NumberOfSimilarities += diff.NumberOfSimilarities;
}
//Find deletions
for (int i = 0, n = list1 == null ? 0 : list1.Count; i < n; i++){
//^ assert list1 != null && changes != null && deletions != null;
Statement nd1 = list1[i];
if (nd1 == null) continue;
if (matchedNodes[nd1.UniqueKey] != null) continue;
changes[i] = null;
deletions[i] = nd1;
insertions[i] = null;
differences.NumberOfDifferences += 1;
}
//Find insertions
for (int j = 0, n = list1 == null ? 0 : list1.Count, m = list2 == null ? 0 : list2.Count; j < m; j++){
//^ assert list2 != null;
Statement nd2 = list2[j];
if (nd2 == null) continue;
if (matchedNodes[nd2.UniqueKey] != null) continue;
insertions[n+j] = nd2; //Records nd2 as an insertion into list1, along with its position in list2
differences.NumberOfDifferences += 1; //REVIEW: put the size of the tree here?
}
if (differences.NumberOfDifferences == 0){
changes = null;
deletions = null;
insertions = null;
}
this.differencesMapFor = savedDifferencesMapFor;
return differences;
}
示例14: ExtractClump
internal static StatementList ExtractClump(StatementList blocks, int firstBlockIndex, int firstStmtIndex,
int lastBlockIndex, int lastStmtIndex, AssumeBlock assumeBlock = null)
{
Contract.Requires(blocks != null);
Contract.Requires(firstBlockIndex >= 0);
Contract.Requires(firstStmtIndex >= 0);
Contract.Ensures(Contract.Result<StatementList>().Count == lastBlockIndex - firstBlockIndex + 1);
Contract.Ensures(blocks[firstBlockIndex] == Contract.OldValue(blocks[firstBlockIndex]));
StatementList clump = new StatementList();
// first extract the tail of the first block into a new block.
Block oldFirstBlock = (Block) blocks[firstBlockIndex];
Block newFirstBlock = new Block(new StatementList());
if (oldFirstBlock != null)
{
var count = firstBlockIndex == lastBlockIndex ? lastStmtIndex + 1 : oldFirstBlock.Statements.Count;
for (int stmtIndex = firstStmtIndex; stmtIndex < count; stmtIndex++)
{
var stmt = oldFirstBlock.Statements[stmtIndex];
newFirstBlock.Statements.Add(stmt);
if (stmt == null) continue;
oldFirstBlock.Statements[stmtIndex] = assumeBlock;
assumeBlock = null;
}
}
clump.Add(newFirstBlock);
var currentBlockIndex = firstBlockIndex + 1;
if (currentBlockIndex > lastBlockIndex) return clump;
// setup info about forwarding branches to new last full block
Block newLastBlock = null;
var lastFullBlock = lastBlockIndex - 1;
var oldLastBlock = (Block) blocks[lastBlockIndex];
if (oldLastBlock != null && lastStmtIndex == oldLastBlock.Statements.Count - 1)
{
// last block is also fully used.
lastFullBlock = lastBlockIndex;
}
else
{
newLastBlock = new Block(new StatementList());
// check if first block had a branch
if (newFirstBlock != null && newFirstBlock.Statements != null && newFirstBlock.Statements.Count > 0)
{
// check if we need to adjust branch to last block
var branch = newFirstBlock.Statements[newFirstBlock.Statements.Count - 1] as Branch;
if (branch != null && branch.Target != null && branch.Target.UniqueKey == oldLastBlock.UniqueKey)
{
branch.Target = newLastBlock;
}
}
}
// Next extract full blocks between currentBlockIndex and including lastFullBlock
for (; currentBlockIndex <= lastFullBlock; currentBlockIndex++)
{
var block = (Block) blocks[currentBlockIndex];
// don't skip null blocks since context relies on number
clump.Add(block);
if (block == null) continue;
blocks[currentBlockIndex] = assumeBlock;
assumeBlock = null;
if (newLastBlock != null && block.Statements != null && block.Statements.Count > 0)
{
// check if we need to adjust branch to last block
var branch = block.Statements[block.Statements.Count - 1] as Branch;
if (branch != null && branch.Target != null && branch.Target.UniqueKey == oldLastBlock.UniqueKey)
{
branch.Target = newLastBlock;
}
}
}
// next, if last block wasn't full, we have a new last block, extract the prefix
if (newLastBlock != null)
{
for (int i = 0; i < lastStmtIndex + 1; i++)
{
newLastBlock.Statements.Add(oldLastBlock.Statements[i]);
oldLastBlock.Statements[i] = assumeBlock;
assumeBlock = null;
}
clump.Add(newLastBlock);
}
//.........这里部分代码省略.........
示例15: ExtractVB_ENCCallToPreamble
private static int ExtractVB_ENCCallToPreamble(Block firstBlock, int currentIndex, StatementList preamble)
{
if (firstBlock == null) return currentIndex;
while (currentIndex < firstBlock.Statements.Count)
{
Statement s = firstBlock.Statements[currentIndex];
if (s != null && s.NodeType != NodeType.Nop)
{
// check for VB literal assignments
if (!s.SourceContext.Hidden) break;
var es = s as ExpressionStatement;
if (es != null)
{
MethodCall call = es.Expression as MethodCall;
if (call != null)
{
var mb = call.Callee as MemberBinding;
if (mb == null) break;
var encMethod = mb.BoundMember as Method;
if (encMethod == null) break;
if (encMethod.Name.Name != "__ENCAddToList") break;
// okay, we are calling the VB memory leak, put it into the preamble
goto addToPreamble;
}
}
break; // don't skip other stuff
}
if (s == null) continue;
addToPreamble:
preamble.Add(s);
var oldCount = firstBlock.Statements.Count;
var oldStats = firstBlock.Statements;
firstBlock.Statements[currentIndex] = null;
Contract.Assert(oldStats == firstBlock.Statements);
Contract.Assert(oldCount == firstBlock.Statements.Count);
currentIndex++;
Contract.Assert(currentIndex <= firstBlock.Statements.Count);
}
return currentIndex;
}