Exemplo n.º 1
0
 public override Statement VisitAssignmentStatement(AssignmentStatement assignment)
 {
     if (assignment == null) return null;
     return base.VisitAssignmentStatement((AssignmentStatement)assignment.Clone());
 }
Exemplo n.º 2
0
		public override Statement VisitAssignmentStatement(AssignmentStatement assignment)
		{
      assignment = (AssignmentStatement)assignment.Clone();

			Expression target = assignment.Target;
			Expression source = assignment.Source;

      if (assignment.SourceContext.Document == null) {
        assignment.SourceContext = this.current_source_context;
      }

			if((target == null) || (source == null))
				throw new ApplicationException("Strange CCI format " + CodePrinter.StatementToString(assignment));

			switch(target.NodeType)
			{
				case NodeType.AddressDereference:
          assignment.Target = (Expression)this.Visit(target);
          if (source is Literal && ((Literal)source).Value == null && 
            ((assignment.Target.Type != null && assignment.Target.Type.IsValueType) || (assignment.Target.Type is TypeParameter) ||
              (assignment.Target.Type is ClassParameter)))
          {
              // initobj encoding.
              return assignment;
          }
          assignment.Source = simplify(source, true);
          return assignment;

				case NodeType.MemberBinding:
				case NodeType.Indexer:
					assignment.Target = (Expression)this.Visit(target);
					assignment.Source = simplify(source, true);
					return assignment;

				case NodeType.Local:
				case NodeType.Parameter:
					// target is a Variable; we can be more relaxed on the right side
					// Note: VS has a strange indentation for switch inside a switch ...
				switch(source.NodeType)
				{
						// (source is MethodCall) ||
					case NodeType.Call :
					case NodeType.Calli :
					case NodeType.Callvirt :
					case NodeType.Jmp :
					case NodeType.MethodCall :
						// (source is ArrayConstruct) ||
					case NodeType.ConstructArray:
						// (source is AddressDereference) ||
					case NodeType.AddressDereference:
						// (source is MemberBinding) ||
					case NodeType.MemberBinding:
						// (source is Indexer)
					case NodeType.Indexer:
						assignment.Source = (Expression)this.Visit(source);
						break;
					case NodeType.Literal:
						break;

					// (source is Construct)
					case NodeType.Construct:
					default:
						assignment.Source = simplify(source, true);
						break;
				}
					return assignment;

				default:
					throw new ApplicationException("Strange CCI format " + CodePrinter.StatementToString(assignment));
			}
		}