コード例 #1
0
ファイル: Unstacker.cs プロジェクト: Balamir/DotNetOpenAuth
 public override Statement VisitAssignmentStatement(AssignmentStatement assignment)
 {
     if (assignment == null) return null;
     assignment.Source = this.VisitExpression(assignment.Source);
     assignment.Target = this.VisitTargetExpression(assignment.Target);
     return assignment;
 }
 public override Statement VisitAssignmentStatement(AssignmentStatement assignment)
 {
   MemberBinding binding = assignment.Target as MemberBinding;
   if (binding != null) 
   {
     Expression target = VisitExpression(binding.TargetObject);
     Field boundMember = (Field) binding.BoundMember;
     Expression source = VisitExpression(assignment.Source);
     if (!boundMember.IsStatic && !boundMember.DeclaringType.IsValueType && boundMember.DeclaringType.Contract != null && boundMember.DeclaringType.Contract.FramePropertyGetter != null && boundMember != boundMember.DeclaringType.Contract.FrameField) 
     {
       Local targetLocal = new Local(boundMember.DeclaringType);
       Statement evaluateTarget = new AssignmentStatement(targetLocal, target, assignment.SourceContext);
       Local sourceLocal = new Local(boundMember.Type);
       Statement evaluateSource = new AssignmentStatement(sourceLocal, source, assignment.SourceContext);
       Expression guard = new MethodCall(new MemberBinding(targetLocal, boundMember.DeclaringType.Contract.FramePropertyGetter), null, NodeType.Call, SystemTypes.Guard);
       Statement check = new ExpressionStatement(new MethodCall(new MemberBinding(guard, SystemTypes.Guard.GetMethod(Identifier.For("CheckIsWriting"))), null, NodeType.Call, SystemTypes.Void));
       Statement stfld = new AssignmentStatement(new MemberBinding(targetLocal, boundMember), sourceLocal, assignment.SourceContext);
       return new Block(new StatementList(new Statement[] {evaluateTarget, evaluateSource, check, stfld}));
     } 
     else
     {
       binding.TargetObject = target;
       assignment.Source = source;
       return assignment;
     }
   }
   else
   {
     return base.VisitAssignmentStatement(assignment);
   }
 }
コード例 #3
0
 public object VisitAssignmentStatement(AssignmentStatement s, object context)
 {
     s.Target.AcceptVisitor(this, context);
     StringBuilder.Append(" = ");
     s.Value.AcceptVisitor(this, context);
     StringBuilder.Append(";");
     return(null);
 }
コード例 #4
0
        public void GetMemberNames()
        {
            string[]            expected  = new string[] { "a", "b" };
            string              code      = "a.b = 0";
            AssignmentStatement statement = PythonParserHelper.GetAssignmentStatement(code);

            Assert.AreEqual(expected, PythonControlFieldExpression.GetMemberNames(statement.Left[0] as MemberExpression));
        }
コード例 #5
0
 public override void VisitAssignmentStatement(AssignmentStatement node)
 {
     if (node.Target is Local && IsResultExpression(node.Source))
     {
         this.exempt_result_local = (Local)node.Target;
     }
     base.VisitAssignmentStatement(node);
 }
コード例 #6
0
        public void NoLeftHandSideExpressionsInAssignment()
        {
            List <Expression>     lhs    = new List <Expression>();
            AssignmentStatement   assign = new AssignmentStatement(lhs.ToArray(), null);
            PythonComponentWalker walker = new PythonComponentWalker(this);

            walker.Walk(assign);
        }
コード例 #7
0
ファイル: CodeGenerator.cs プロジェクト: Daouki/wire
 public void VisitAssignmentStatement(AssignmentStatement assignmentStatement)
 {
     _generatedCode
     .Append(ExpressionCodeGenerator.GenerateExpressionCode(assignmentStatement.Target))
     .Append(" = ")
     .Append(ExpressionCodeGenerator.GenerateExpressionCode(assignmentStatement.Value))
     .Append(";\n");
 }
コード例 #8
0
        //-----------------------------------------------------------
        private Type Visit(AssignmentStatement node, Table table)
        {
            Type leftExpressionType  = Visit((dynamic)node[0], table);
            Type rightExpressionType = Visit((dynamic)node[1], table);

            if (leftExpressionType != rightExpressionType)
            {
                if (!((leftExpressionType == Type.LIST_OF_BOOLEAN || leftExpressionType == Type.LIST_OF_INTEGER || leftExpressionType == Type.LIST_OF_STRING) && rightExpressionType == Type.LIST_OF_ANYTHING))
                {
                    throw new SemanticError("Expecting type " + leftExpressionType + " instead of " + rightExpressionType + " in assignment statement", node.AnchorToken);
                }
            }

            if (node[0] is Identifier)
            {
                GlobalSymbolTable gstable = table as GlobalSymbolTable;
                LocalSymbolTable  lstable = table as LocalSymbolTable;

                var symbolName = node[0].AnchorToken.Lexeme;
                if (table is GlobalSymbolTable)
                {
                    if (gstable[symbolName].IsConstant)
                    {
                        throw new SemanticError("Cannot perform assignment to constant " + symbolName, node[0].AnchorToken);
                    }
                }
                else if (table is LocalSymbolTable)
                {
                    if (lstable.Contains(symbolName))
                    {
                        if (lstable[symbolName].Kind == Clasification.CONST)
                        {
                            throw new SemanticError("Cannot perform assignment to constant " + symbolName, node[0].AnchorToken);
                        }
                    }
                    else
                    {
                        if (GSTable.Contains(symbolName) && GSTable[symbolName].IsConstant)
                        {
                            throw new SemanticError("Cannot perform assignment to constant " + symbolName, node[0].AnchorToken);
                        }
                    }
                }
                else
                {
                    throw new TypeAccessException("Expecting either a GlobalSymbolTable or a LocalSymboltable");
                }
            }
            else if (node[0] is ListIndexExpression)
            {
            }
            else
            {
                throw new TypeAccessException("Expecting either a Idenetifier or a ListIndexExpression " + node[0]);
            }

            return(Type.VOID);
        }
コード例 #9
0
        public void GetVariableName_Indexer_ReturnsNameOfDeclaringObject()
        {
            Method sampleMethod = TestHelper.GetSample <IntrospectionUtility_ClassSample> ("ArrayVariableAndIndexer");
            Block  sampleBlock  = (Block)sampleMethod.Body.Statements[0];
            AssignmentStatement sampleAssignment = (AssignmentStatement)sampleBlock.Statements[2];
            Expression          sample           = sampleAssignment.Target;

            Assert.That(IntrospectionUtility.GetVariableName(sample), Is.EqualTo("local$0"));
        }
コード例 #10
0
        public void InferSafeness_NullSymbolName_ToleratedAndNoExceptionThrown()
        {
            Method sample      = TestHelper.GetSample <InferSafenessSample>("Foo");
            Block  targetBlock = (Block)sample.Body.Statements[0];
            AssignmentStatement targetAssignment = (AssignmentStatement)targetBlock.Statements[1];
            Expression          targetExpression = targetAssignment.Target;

            _symbolTable.InferSafeness(null, targetExpression);
        }
コード例 #11
0
 public override bool Walk(AssignmentStatement node)
 {
     foreach (var lhs in node.Left)
     {
         DefineExpr(lhs);
     }
     node.Right.Walk(this);
     return(false);
 }
コード例 #12
0
        /// <inheritdoc />
        public override void VisitAssignmentStatement(AssignmentStatement assignment)
        {
            base.VisitAssignmentStatement(assignment);

            if (IsDefaultValue(assignment.Target.Type, assignment.Source))
            {
                Problems.Add(CreateProblem(assignment));
            }
        }
コード例 #13
0
 public override bool Walk(AssignmentStatement node)
 {
     UpdateChildRanges(node);
     foreach (var nameExpr in node.Left.OfType <NameExpression>())
     {
         _scope.AddVariable(nameExpr.Name, CreateVariableInDeclaredScope(nameExpr));
     }
     return(base.Walk(node));
 }
コード例 #14
0
        public void IsCompilerGenerated_CompilerGeneratedTypeNode_ReturnsTrue()
        {
            Method sampleMethod = TestHelper.GetSample <IntrospectionUtility_ClassSample> ("UsingClosure");
            Block  sampleBlock  = (Block)sampleMethod.Body.Statements[0];
            AssignmentStatement sampleAssignment          = (AssignmentStatement)sampleBlock.Statements[0];
            TypeNode            compilerGeneratedTypeNode = sampleAssignment.Source.Type;

            Assert.That(IntrospectionUtility.IsCompilerGenerated(compilerGeneratedTypeNode), Is.True);
        }
コード例 #15
0
 public override bool Walk(AssignmentStatement node)
 {
     if (node.Right is ErrorExpression)
     {
         return(false);
     }
     node.Right?.Walk(new ExpressionWalker(this));
     return(false);
 }
コード例 #16
0
        public void IsVariable_Indexer_ReturnsTrue()
        {
            Method sampleMethod = TestHelper.GetSample <IntrospectionUtility_ClassSample> ("ArrayVariableAndIndexer");
            Block  sampleBlock  = (Block)sampleMethod.Body.Statements[0];
            AssignmentStatement sampleAssignment = (AssignmentStatement)sampleBlock.Statements[2];
            Expression          sample           = sampleAssignment.Target;

            Assert.That(IntrospectionUtility.IsVariable(sample), Is.True);
        }
コード例 #17
0
        public void GetInvalidTwoLevelDeepButtonPropertyDescriptorForSelfReference()
        {
            using (Button button = new Button()) {
                AssignmentStatement          statement = PythonParserHelper.GetAssignmentStatement("self._button1.InvalidProperty.BorderSize = 3");
                PythonControlFieldExpression field     = PythonControlFieldExpression.Create(statement.Left[0] as MemberExpression);

                Assert.IsNull(field.GetObjectForMemberName(button));
            }
        }
コード例 #18
0
ファイル: Parser.cs プロジェクト: benstopics/compilers-6083
        public AssignmentStatement ParseAssignmentStatement(MemoryLocation destination)
        {
            AssignmentStatement result = new AssignmentStatement(destination);

            Scanner.ConsumeOperatorToken(Token.Types.ASSIGN);
            result.Expression = ParseExpression();

            return result;
        }
コード例 #19
0
ファイル: AstNodeWalkerBase.cs プロジェクト: mirec12590/Echo
        /// <inheritdoc />
        void IAstNodeVisitor <TInstruction, object> .Visit(AssignmentStatement <TInstruction> assignmentStatement,
                                                           object state)
        {
            EnterAssignmentStatement(assignmentStatement);

            assignmentStatement.Expression.Accept(this, state);

            ExitAssignmentStatement(assignmentStatement);
        }
コード例 #20
0
ファイル: AstPrinter.cs プロジェクト: PaddiM8/Caique
        public object Visit(AssignmentStatement assignmentStatement)
        {
            PrintStart("=", ConsoleColor.Green);
            Next(assignmentStatement.Assignee);
            Next(assignmentStatement.Value);
            _indentationLevel--;

            return(null !);
        }
コード例 #21
0
        public override void VisitAssignmentStatement(AssignmentStatement assignment)
        {
            if (assignment.Target is Local && IsResultExpression(assignment.Source))
            {
                exemptResultLocal = (Local)assignment.Target;
            }

            base.VisitAssignmentStatement(assignment);
        }
コード例 #22
0
ファイル: FlowChecker.cs プロジェクト: raajsurvade/PTVS
 // AssignStmt
 public override bool Walk(AssignmentStatement node)
 {
     node.Right.Walk(this);
     foreach (Expression e in node.Left)
     {
         e.Walk(_fdef);
     }
     return(false);
 }
コード例 #23
0
        public void LocalVariable()
        {
            AssignmentStatement          statement = PythonParserHelper.GetAssignmentStatement("listViewItem1.TooltipText = \"abc\"");
            PythonControlFieldExpression field     = PythonControlFieldExpression.Create(statement.Left[0] as MemberExpression);

            PythonControlFieldExpression expectedField = new PythonControlFieldExpression("TooltipText", "listViewItem1", String.Empty, "listViewItem1.TooltipText");

            Assert.AreEqual(expectedField, field);
        }
コード例 #24
0
        void AssignmentStatement(out Statement stat)
        {
            AssignmentStatement ass = new AssignmentStatement(GetPragma(la)); stat = ass;

            LValue(out ass.lval);
            Expect(11);
            Expression(out ass.rval);
            SetEndPragma(stat);
        }
コード例 #25
0
        public void GetButtonObject()
        {
            using (Button button = new Button()) {
                AssignmentStatement          statement = PythonParserHelper.GetAssignmentStatement("_button1.Size = System.Drawing.Size(10, 10)");
                PythonControlFieldExpression field     = PythonControlFieldExpression.Create(statement.Left[0] as MemberExpression);

                Assert.AreEqual(button, field.GetObjectForMemberName(button));
            }
        }
コード例 #26
0
 public virtual void VisitAssignmentStatement(AssignmentStatement node)
 {
     if (node == null)
     {
         return;
     }
     VisitTargetExpression(node.Target);
     VisitExpression(node.Source);
 }
コード例 #27
0
 public override bool Walk(AssignmentStatement node)
 {
     if (currentClass != null)
     {
         FindProperty(node);
         return(false);
     }
     return(base.Walk(node));
 }
コード例 #28
0
        public void GetButtonFlatAppearanceObject()
        {
            using (Button button = new Button()) {
                AssignmentStatement          statement = PythonParserHelper.GetAssignmentStatement("_button1.FlatAppearance.BorderSize = 3");
                PythonControlFieldExpression field     = PythonControlFieldExpression.Create(statement.Left[0] as MemberExpression);

                Assert.AreEqual(button.FlatAppearance, field.GetObjectForMemberName(button));
            }
        }
コード例 #29
0
ファイル: Unstacker.cs プロジェクト: wbskyboy/ILMerge
 public override Statement VisitAssignmentStatement(AssignmentStatement assignment)
 {
     if (assignment == null)
     {
         return(null);
     }
     assignment.Source = this.VisitExpression(assignment.Source);
     assignment.Target = this.VisitTargetExpression(assignment.Target);
     return(assignment);
 }
コード例 #30
0
 public override Statement VisitAssignmentStatement(AssignmentStatement assignment)
 {
   Expression source = this.VisitExpression(assignment.Source);
   System.Diagnostics.Debug.Assert(source != null, "VisitExpression must return non-null if passed non-null");
   assignment.Source = source;
   Expression target = this.VisitTargetExpression(assignment.Target);
   System.Diagnostics.Debug.Assert(target != null, "VisitExpression must return non-null if passed non-null");
   assignment.Target = target;
   return assignment;
 }
コード例 #31
0
        public void GetAssignmentStatementReturnsFirstAssignmentStatementInCode()
        {
            string code =
                "i = 10";

            AssignmentStatement assignment     = PythonParserHelper.GetAssignmentStatement(code);
            NameExpression      nameExpression = assignment.Left[0] as NameExpression;

            Assert.AreEqual("i", nameExpression.Name);
        }
コード例 #32
0
        public void PythonControlFieldExpressionEquals()
        {
            AssignmentStatement          statement = PythonParserHelper.GetAssignmentStatement("self._textBox1.Name = \"abc\"");
            PythonControlFieldExpression field1    = PythonControlFieldExpression.Create(statement.Left[0] as MemberExpression);

            statement = PythonParserHelper.GetAssignmentStatement("self._textBox1.Name = \"def\"");
            PythonControlFieldExpression field2 = PythonControlFieldExpression.Create(statement.Left[0] as MemberExpression);

            Assert.AreEqual(field1, field2);
        }
コード例 #33
0
        private void Assign(Scope scope, string name, object val, bool isConst, object expected)
        {
            Expression expr = isConst
                            ? (Expression) new ConstantExpression(val)
                            : (Expression) new VariableExpression(val.ToString(), scope);
            var exp = new AssignmentStatement(name, expr, scope);

            exp.Execute();
            Assert.AreEqual(expected, scope.Get <object>(name));
        }
コード例 #34
0
        public override bool Walk(AssignmentStatement node)
        {
            node.Right?.Walk(this);
            foreach (var exp in node.Left)
            {
                AddVarSymbolRecursive(exp);
            }

            return(false);
        }
コード例 #35
0
        public override void VisitAssignmentStatement(AssignmentStatement assignment)
        {
            base.VisitAssignmentStatement(assignment);
            if (assignment == null)
            {
                return;
            }

            var targetLocal = assignment.Target as Local;
            if (targetLocal != null)
            {
                this.assignmented[targetLocal] = assignment.Source;
            }
        }
コード例 #36
0
        private void CheckAssignment(AssignmentStatement assignmentStatement, string targetName, HandleContext context)
        {
            ISymbolTable symbolTable = context.SymbolTable;
              Fragment targetFragmentType = symbolTable.GetFragmentType (targetName);
              Fragment sourceFragmentType = symbolTable.InferFragmentType (assignmentStatement.Source);

              if (targetFragmentType != sourceFragmentType)
            {
              symbolTable.MakeUnsafe (targetName);
            }
            else
            {
              SetPreConditionForIndexerObject (assignmentStatement, targetName, sourceFragmentType, context);
            }
        }
コード例 #37
0
        private Method GetAssignedDelegateMethod(AssignmentStatement assignmentStatement)
        {
            Construct construct = (Construct) assignmentStatement.Source;
              var expression = construct.Operands[1];
              MemberBinding methodBinding;

              if (expression is UnaryExpression)
            methodBinding = (MemberBinding) ((UnaryExpression) expression).Operand;
              else if (expression is BinaryExpression)
              //vb.net generates binaryExpressions instead of unary
            methodBinding = (MemberBinding) ((BinaryExpression) expression).Operand2;
              else
            throw new InvalidOperationException ("Could not fetch member binding from delegate statement.");

              return (Method) methodBinding.BoundMember;
        }
コード例 #38
0
 private void InferArrayFragment(AssignmentStatement assignmentStatement, string targetName, HandleContext context)
 {
     ISymbolTable symbolTable = context.SymbolTable;
       Fragment targetFragmentType = symbolTable.InferFragmentType (assignmentStatement.Source);
       if (context.ArrayFragmentTypeDefined[targetName] == false)
       {
     symbolTable.MakeSafe(targetName, targetFragmentType);
     context.ArrayFragmentTypeDefined[targetName] = true;
       }
       else if (symbolTable.GetFragmentType(targetName) == Fragment.CreateLiteral())
       {
     symbolTable.MakeSafe(targetName, targetFragmentType);
       }
       else if (symbolTable.GetFragmentType(targetName) != targetFragmentType && targetFragmentType != Fragment.CreateLiteral())
       {
     symbolTable.MakeUnsafe(targetName);
       }
 }
コード例 #39
0
        public override void VisitAssignmentStatement(AssignmentStatement assignment)
        {
            base.VisitAssignmentStatement(assignment);

            if (assignment == null)
            {
                return;
            }

            var targetLocal = assignment.Target as Local;
            if (targetLocal == null)
            {
                return;
            }

            var sourceLiteral = assignment.Source as Literal;
            this.localsOfLiteral[targetLocal] = sourceLiteral;
        }
コード例 #40
0
 public override Expression VisitMemberBinding(MemberBinding binding) 
 {
   Member boundMember = binding.BoundMember;
   if (boundMember is Field && !boundMember.IsStatic && boundMember.DeclaringType != null && boundMember.DeclaringType.Contract != null && boundMember.DeclaringType.Contract.FramePropertyGetter != null && boundMember != boundMember.DeclaringType.Contract.FrameField) 
   {
     Expression target = VisitExpression(binding.TargetObject);
     // Since we do not visit member bindings of assignment statements, we know/guess that this is a ldfld.
     Local targetLocal = new Local(boundMember.DeclaringType);
     Statement evaluateTarget = new AssignmentStatement(targetLocal, target, binding.SourceContext);
     Expression guard = new MethodCall(new MemberBinding(targetLocal, boundMember.DeclaringType.Contract.FramePropertyGetter), null, NodeType.Call, SystemTypes.Guard);
     Statement check = new ExpressionStatement(new MethodCall(new MemberBinding(guard, SystemTypes.Guard.GetMethod(Identifier.For("CheckIsReading"))), null, NodeType.Call, SystemTypes.Void));
     Statement ldfld = new ExpressionStatement(new MemberBinding(targetLocal, boundMember, binding.SourceContext));
     return new BlockExpression(new Block(new StatementList(new Statement[] {evaluateTarget, check, ldfld})), binding.Type);
   }
   else
   {
     return base.VisitMemberBinding(binding);
   }
 }
コード例 #41
0
ファイル: UnusedReasign.cs プロジェクト: lavn0/CodeAnalysis
        public override void VisitAssignmentStatement(AssignmentStatement assignment)
        {
            this.statements.Add(assignment);
            base.VisitAssignmentStatement(assignment);

            if (assignment != null)
            {
                var local = assignment.Target as Local;
                if (local != null &&
                    !Microsoft.FxCop.Sdk.RuleUtilities.IsCompilerGenerated(local))
                {
                    this.locals.Remove(local);
                    if (!this.initedLocals.Add(local) &&
                        !this.locals.Contains(local))
                    {
                        this.Violate(assignment);
                    }

                    this.locals.Clear();
                }
            }
        }
コード例 #42
0
			protected internal override void VisitAssignmentStatement(AssignmentStatement statement)
			{
				_stm = Ssm.Stm.NewAsgnStm(((Ssm.Expr.VarExpr)GetTransformed(statement.AssignmentTarget)).Item, GetTransformed(statement.Expression));
			}
コード例 #43
0
 // AssignmentStatement
 public virtual bool Walk(AssignmentStatement node) { return true; }
コード例 #44
0
ファイル: Updater.cs プロジェクト: asvishnyakov/CodeContracts
 public virtual Statement VisitAssignmentStatement(AssignmentStatement assignment, AssignmentStatement changes, AssignmentStatement deletions, AssignmentStatement insertions){
   this.UpdateSourceContext(assignment, changes);
   if (assignment == null) return changes;
   if (changes != null){
     if (deletions == null || insertions == null)
       Debug.Assert(false);
     else{
       assignment.Operator = changes.Operator;
       assignment.Source = this.VisitExpression(assignment.Source, changes.Source, deletions.Source, insertions.Source);
       assignment.Target = this.VisitExpression(assignment.Target, changes.Target, deletions.Target, insertions.Target);
     }
   }else if (deletions != null)
     return null;
   return assignment;
 }
コード例 #45
0
 // AssignmentStatement
 public override bool Walk(AssignmentStatement node) { return false; }
コード例 #46
0
ファイル: Parser.cs プロジェクト: unycorn/lolcode-dot-net
 void TypecastStatement(out Statement stat)
 {
     AssignmentStatement ass = new AssignmentStatement(GetPragma(la)); stat = ass; Type t;
     LValue(out ass.lval);
     Expect(12);
     Expect(46);
     Expect(20);
     Typename(out t);
     SetEndPragma(ass); ass.rval = new TypecastExpression(ass.location, t, ass.lval);
 }
コード例 #47
0
 public override Statement VisitAssignmentStatement(AssignmentStatement assignment){
   assignment = (AssignmentStatement)base.VisitAssignmentStatement(assignment);
   if (assignment == null) return null;
   Expression target = assignment.Target;
   Expression source = assignment.Source;
   TypeNode tType = target == null ? null : target.Type;
   TypeNode sType = source == null ? null : source.Type;
   if (tType != null && sType != null){
     //^ assert target != null;
     if (tType.IsValueType){
       if (sType is Reference)
         assignment.Source = new AddressDereference(source, tType);
       else if (!sType.IsValueType && !(sType == CoreSystemTypes.Object && source is Literal && target.NodeType == NodeType.AddressDereference))
         assignment.Source = new AddressDereference(new BinaryExpression(source, new MemberBinding(null, sType), NodeType.Unbox), sType);
     }else{
       if (sType.IsValueType){
         if (!(tType is Reference))
           assignment.Source = new BinaryExpression(source, new MemberBinding(null, sType), NodeType.Box, tType);
       }
     }
   }
   return assignment;
 }
コード例 #48
0
ファイル: Resolver.cs プロジェクト: dbremner/specsharp
 public override Statement VisitAssignmentStatement(AssignmentStatement assignment){
   if (assignment == null) return null;
   if (assignment.Operator == NodeType.Add || assignment.Operator == NodeType.Sub){
     Expression t = this.VisitExpression(assignment.Target);
     DelegateNode dt = TypeNode.StripModifiers(t.Type) as DelegateNode;
     MemberBinding mb = t as MemberBinding;
     if (dt != null && mb != null){
       Event e = mb.BoundMember as Event;
       if (e != null){
         //There is no backing field for this event, use the add or remove accessor
         ExpressionList arguments = new ExpressionList(1);
         Expression src = this.VisitExpression(assignment.Source);
         if (src is MemberBinding && ((MemberBinding)src).BoundMember is Method)
           src = this.VisitExpression(new Construct(new MemberBinding(null, e.HandlerType), new ExpressionList(assignment.Source)));
         arguments.Add(src);
         Method adderOrRemover = assignment.Operator == NodeType.Add ? e.HandlerAdder : e.HandlerRemover;
         adderOrRemover.ObsoleteAttribute = e.ObsoleteAttribute;
         mb.BoundMember = adderOrRemover;
         MethodCall mc = new MethodCall(mb, arguments, NodeType.Call);
         if (!(mb.TargetObject is Base) && e.HandlerAdder.IsVirtualAndNotDeclaredInStruct) 
           mc.NodeType = NodeType.Callvirt;
         mc.Type = SystemTypes.Void;
         mc.SourceContext = assignment.SourceContext;
         Construct c1 = src as Construct;
         if (c1 != null && c1.Type == null)
           c1.Type = t.Type;
         Identifier id = src as Identifier;
         if (id != null && id.Type == null && t.Type != null && t.Type.IsAssignableTo(SystemTypes.Enum))
           id.Type = t.Type;
         return new ExpressionStatement(mc);
       }else if (mb.BoundMember.DeclaringType != this.currentType && (mb.BoundMember is Field && ((Field)mb.BoundMember).IsPrivate)){
         Expression src = this.VisitExpression(assignment.Source);
         if (src is MemberBinding && ((MemberBinding)src).BoundMember is Method)
           src = this.VisitExpression(new Construct(new MemberBinding(null, dt), new ExpressionList(assignment.Source)));
         BinaryExpression bExpr = new BinaryExpression(assignment.Target, src, NodeType.AddEventHandler);
         bExpr.SourceContext = assignment.SourceContext;
         if (assignment.Operator != NodeType.Add) bExpr.NodeType = NodeType.RemoveEventHandler;
         bExpr.Type = SystemTypes.Void;
         Construct c1 = src as Construct;
         if (c1 != null && c1.Type == null)
           c1.Type = t.Type;
         Identifier id = src as Identifier;
         if (id != null && id.Type == null && t.Type != null && t.Type.IsAssignableTo(SystemTypes.Enum))
           id.Type = t.Type;
         return new ExpressionStatement(this.VisitExpression(bExpr), assignment.SourceContext);
       }
     }
   }
   Expression opnd1 = assignment.Target = this.VisitTargetExpression(assignment.Target);
   TypeNode opnd1Type = opnd1 == null ? null : TypeNode.StripModifiers(opnd1.Type);
   Expression opnd2;
   if (opnd1 != null && opnd1Type is DelegateNode) {
     TemplateInstance ti = assignment.Source as TemplateInstance;
     if (ti != null && !ti.IsMethodTemplate){
       ti.IsMethodTemplate = true;
       opnd2 = assignment.Source = this.VisitExpression(new Construct(new MemberBinding(null, opnd1Type), new ExpressionList(assignment.Source)));
     }else{
       Expression source = assignment.Source;
       AnonymousNestedFunction anonFunc = source as  AnonymousNestedFunction;
       if (anonFunc != null) this.FillInImplicitType(anonFunc, (DelegateNode)opnd1Type);
       opnd2 = assignment.Source = this.VisitExpression(assignment.Source);
       MemberBinding mb = opnd2 as MemberBinding;
       if (mb != null && mb.BoundMember is Method)
         opnd2 = assignment.Source = this.VisitExpression(new Construct(new MemberBinding(null, opnd1Type), new ExpressionList(source)));
     }
   }else{
     opnd2 = assignment.Source = this.VisitExpression(assignment.Source);
   }
   if (assignment.Operator == NodeType.Add && opnd1 != null && opnd2 != null){
     TypeNode t1 = this.typeSystem.Unwrap(opnd1.Type);
     TypeNode t2 = this.typeSystem.Unwrap(opnd2.Type);
     if (t1 == SystemTypes.String){
       if (t2 == SystemTypes.String || this.typeSystem.ImplicitCoercionFromTo(t2, SystemTypes.String, this.TypeViewer))
         assignment.OperatorOverload = Runtime.StringConcatStrings;
       else
         assignment.OperatorOverload = Runtime.StringConcatObjects;
       return assignment;
     }
   }
   if (assignment.Operator != NodeType.Nop){
     BinaryExpression binExpr = new BinaryExpression(assignment.Target, assignment.Source, assignment.Operator);
     assignment.OperatorOverload = this.GetBinaryOperatorOverload(binExpr);
     if (assignment.OperatorOverload == null && opnd1 != null){
       TypeNode t1 = this.typeSystem.Unwrap(opnd1.Type);
       if (t1 != null && !t1.IsPrimitiveNumeric && t1 != SystemTypes.Char && !(t1 is EnumNode)){
         Literal lit2 = opnd2 as Literal;
         if (lit2 != null && lit2.Type != null) {
           TypeNode t2 = this.typeSystem.UnifiedType(lit2, t1, this.TypeViewer);
           if (t1 != t2 && t2 != SystemTypes.Object) assignment.UnifiedType = t2;
         }
       }
     }
   }
   if (assignment != null && assignment.Target != null) {
     TypeNode type = assignment.Target.Type;
     Construct c = assignment.Source as Construct;
     if (c != null && c.Type == null)
       c.Type = type;
     Identifier id = assignment.Source as Identifier;
     if (id != null && id.Type == null && type != null && type.IsAssignableTo(SystemTypes.Enum))
       id.Type = type;
   }
   return assignment;
 }
コード例 #49
0
    public virtual Differences VisitAssignmentStatement(AssignmentStatement assignment1, AssignmentStatement assignment2){
      Differences differences = new Differences(assignment1, assignment2);
      if (assignment1 == null || assignment2 == null){
        if (assignment1 != assignment2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      AssignmentStatement changes = (AssignmentStatement)assignment2.Clone();
      AssignmentStatement deletions = (AssignmentStatement)assignment2.Clone();
      AssignmentStatement insertions = (AssignmentStatement)assignment2.Clone();

      if (assignment1.Operator == assignment2.Operator) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;

      Differences diff = this.VisitExpression(assignment1.Source, assignment2.Source);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Source = diff.Changes as Expression;
      deletions.Source = diff.Deletions as Expression;
      insertions.Source = diff.Insertions as Expression;
      Debug.Assert(diff.Changes == changes.Source && diff.Deletions == deletions.Source && diff.Insertions == insertions.Source);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      diff = this.VisitExpression(assignment1.Target, assignment2.Target);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Target = diff.Changes as Expression;
      deletions.Target = diff.Deletions as Expression;
      insertions.Target = diff.Insertions as Expression;
      Debug.Assert(diff.Changes == changes.Target && diff.Deletions == deletions.Target && diff.Insertions == insertions.Target);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      if (differences.NumberOfDifferences == 0){
        differences.Changes = null;
        differences.Deletions = null;
        differences.Insertions = null;
      }else{
        differences.Changes = changes;
        differences.Deletions = deletions;
        differences.Insertions = insertions;
      }
      return differences;
    }
コード例 #50
0
 /// <summary>
 /// Replace an implicit Push with an assignment to the appropriate stack variable.
 /// </summary>
 protected override Statement PushExprTransformer(ExpressionStatement expr_stat, int depth) 
 {
   Statement new_stat = new AssignmentStatement(get_stack_var(depth, expr_stat.Expression, ref expr_stat.SourceContext), expr_stat.Expression);
   new_stat.SourceContext = expr_stat.SourceContext;
   return new_stat;
 }
コード例 #51
0
 /// <summary>
 /// Remove the Pop from a CciHelper statement "sequence" of the form "Pop expr".
 /// </summary>
 protected override Statement PopExprTransformer(ExpressionStatement expr_stat, int depth) 
 {
   Expression real_expr = ((UnaryExpression) expr_stat.Expression).Operand;
   Statement new_stat;
   new_stat = new AssignmentStatement(get_stack_var(depth, expr_stat.Expression), real_expr);
   real_expr.SourceContext = expr_stat.SourceContext;
   new_stat.SourceContext  = expr_stat.SourceContext;
   return new_stat;
 }
コード例 #52
0
ファイル: Checker.cs プロジェクト: hesam/SketchSharp
 public override Statement VisitAssignmentStatement(AssignmentStatement assignment) {
   if (assignment == null) return null;
   if (this.TypeInVariableContext(assignment.Source as Literal))
     return null;
   if (this.insideMethodContract || this.insideAssertOrAssume || this.insideInvariant) {
     this.HandleError(assignment, Error.SideEffectsNotAllowedInContracts);
     return null;
   }
   Composition comp = assignment.Target as Composition;
   if (comp != null) {
     comp.Expression = this.VisitTargetExpression(comp.Expression);
     if (comp.Expression == null) return null;
   } else {
     bool savedMayReferenceThisAndBase = this.MayReferenceThisAndBase;
     MemberBinding mb = assignment.Target as MemberBinding;
     if (assignment.Operator == NodeType.Nop
       && mb != null
       && (mb.TargetObject is ImplicitThis || mb.TargetObject is This)) {
       this.MayReferenceThisAndBase = true;
     }
     assignment.Target = this.VisitTargetExpression(assignment.Target);
     this.MayReferenceThisAndBase = savedMayReferenceThisAndBase;
     if (assignment.Target == null) return null;
   }
   TypeNode t = assignment.Target.Type;
   if (t == null) assignment.Target.Type = t = SystemTypes.Object;
   Expression source = this.VisitExpression(assignment.Source);
   if (source == null) return null;
   Reference rt = t as Reference;
   NodeType oper = assignment.Operator;
   if (rt != null && oper != NodeType.CopyReference) t = rt.ElementType;
   if (oper != NodeType.Nop && oper != NodeType.CopyReference) {
     this.CheckForGetAccessor(assignment.Target);
     LRExpression e = new LRExpression(assignment.Target);
     assignment.Target = e;
     if (assignment.OperatorOverload == null) {
       BinaryExpression be = new BinaryExpression(e, source, assignment.Operator, t, assignment.SourceContext);
       if (assignment.UnifiedType != t && assignment.UnifiedType != null) be.Type = assignment.UnifiedType;
       Expression pop = new Expression(NodeType.Pop, be.Type);
       Pointer pt = t as Pointer;
       if (pt != null && (assignment.Operator == NodeType.Add || assignment.Operator == NodeType.Sub)) {
         if (pt.ElementType != SystemTypes.Int8 && pt.ElementType != SystemTypes.UInt8) {
           UnaryExpression sizeOf = new UnaryExpression(new Literal(pt.ElementType, SystemTypes.Type), NodeType.Sizeof, SystemTypes.UInt32);
           Expression elemSize = PureEvaluator.EvalUnaryExpression((Literal)sizeOf.Operand, sizeOf);
           if (elemSize == null) elemSize = sizeOf;
           TypeNode offsetType = SystemTypes.Int32;
           if (source.Type != null && source.Type.IsPrimitiveInteger) offsetType = source.Type;
           BinaryExpression offset = new BinaryExpression(source, elemSize, NodeType.Mul, offsetType, source.SourceContext);
           Literal offsetLit = PureEvaluator.TryEvalBinaryExpression(source as Literal, elemSize as Literal, offset, this.typeSystem);
           if (offsetLit == null) {
             if (offsetType == SystemTypes.Int32)
               offset.Operand1 = new UnaryExpression(source, NodeType.Conv_I);
             else
               offset.Operand2 = this.typeSystem.ExplicitCoercion(elemSize, offsetType, this.TypeViewer);
             source = offset;
           } else
             source = offsetLit;
         }
         source = this.typeSystem.ExplicitCoercion(source, pt, this.TypeViewer);
         be.Operand2 = source;
         assignment.Source = be;
         return assignment;
       }
       source = this.CoerceBinaryExpressionOperands(be, pop, source);
       if (source == null) return null;
       if (source == pop)
         source = e;
       else if (!(source is Literal)) {
         be.Operand1 = e;
       }
     }
     assignment.Operator = NodeType.Nop;
     if (!t.IsPrimitiveNumeric && t != SystemTypes.Char && t != SystemTypes.Boolean && assignment.OperatorOverload == null &&
       (assignment.UnifiedType == null || !assignment.UnifiedType.IsPrimitiveNumeric) &&
       oper != NodeType.AddEventHandler && oper != NodeType.RemoveEventHandler && 
       !(t is DelegateNode && (source.NodeType == NodeType.Add || source.NodeType == NodeType.Sub)) && !(t is EnumNode)) {
       this.HandleError(assignment, Error.BadBinaryOps,
         this.GetOperatorSymbol(oper), this.GetTypeName(t), this.GetTypeName(assignment.Source.Type));
       return null;
     }
     if (assignment.OperatorOverload != null) {
       if (assignment.OperatorOverload.Parameters == null || assignment.OperatorOverload.Parameters.Count < 2) {
         Debug.Assert(false); return null;
       }
       source = this.typeSystem.ImplicitCoercion(source, assignment.OperatorOverload.Parameters[1].Type, this.TypeViewer);
       ExpressionList arguments = new ExpressionList(e, source);
       source = new MethodCall(new MemberBinding(null, assignment.OperatorOverload), arguments, NodeType.Call, assignment.OperatorOverload.ReturnType);
       assignment.OperatorOverload = null;
     }
   }
   assignment.Source = this.typeSystem.ImplicitCoercion(source, t, this.TypeViewer);
   return assignment;
 }
コード例 #53
0
ファイル: NodeInspector.cs プロジェクト: carrie901/mono
		public virtual void VisitAssignmentStatement (AssignmentStatement node)
		{
			if (node == null)
				return;
			VisitTargetExpression (node.Target);
			VisitExpression (node.Source);
		}
コード例 #54
0
 public static string Print(AssignmentStatement asgn)
 {
     return  "sourceexpression type: " + asgn.Source.Type.Name + "\n" +
             "operator: " + asgn.Operator.ToString() + "\n" +
             "targetexpression type: " + asgn.Target.NodeType.ToString();
 }
コード例 #55
0
        public override void VisitAssignmentStatement(AssignmentStatement assignment)
        {
            try
            {
                if (assignment == null)
                {
                    return;
                }

                var targetLocal = assignment.Target as Local;
                if (targetLocal == null)
                {
                    return;
                }

                switch (assignment.Source.NodeType)
                {
                    case NodeType.Literal:
                        this.localsOfLiteral[targetLocal] = assignment.Source as Literal;
                        break;

                    case NodeType.Call: // MethodCall
                        var sourceMethodCall = assignment.Source as MethodCall;
                        bool isStringConcatMethodCall = RuleUtilities.IsStringConcatMethodCall(sourceMethodCall);
                        if (!isStringConcatMethodCall)
                        {
                            this.localsOfLiteral.Remove(targetLocal);
                            break;
                        }

                        for (var i = 1; i < sourceMethodCall.Operands.Count; i++)
                        {
                            // 前連結側のリテラルを算出する
                            var prepareLiteral = sourceMethodCall.Operands[i - 1] as Literal;
                            if (prepareLiteral == null)
                            {
                                var prepareLocal = sourceMethodCall.Operands[i - 1] as Local;
                                if (prepareLocal != null)
                                {
                                    // ローカル値の場合、処理中に最後に代入されたローカル値を取り出してみる
                                    this.localsOfLiteral.TryGetValue(prepareLocal, out prepareLiteral);
                                }
                            }

                            if (prepareLiteral == null)
                            {
                                // 前連結側がリテラル値でなければ終了
                                continue;
                            }

                            var afterLiteral = sourceMethodCall.Operands[i] as Literal;
                            if (afterLiteral == null)
                            {
                                var afterLocal = sourceMethodCall.Operands[i] as Local;
                                if (afterLocal != null)
                                {
                                    // ローカル値の場合、処理中に最後に代入されたローカル値を取り出してみる
                                    this.localsOfLiteral.TryGetValue(afterLocal, out afterLiteral);
                                }
                            }

                            if (afterLiteral == null)
                            {
                                continue;
                            }

                            this.Violate(
                                assignment,
                                prepareLiteral.Value,
                                afterLiteral.Value);
                        }

                        break;

                    default:
                        this.localsOfLiteral.Remove(targetLocal);
                        break;
                }
            }
            finally
            {
                base.VisitAssignmentStatement(assignment);
            }
        }
コード例 #56
0
ファイル: DefaultNodeVisitor.cs プロジェクト: carrie901/mono
		public virtual Statement VisitAssignmentStatement (AssignmentStatement node)
		{
			if (node == null)
				return node;
			node.Target = VisitTargetExpression (node.Target);
			node.Source = VisitExpression (node.Source);

			return node;
		}
コード例 #57
0
 public virtual void PostWalk(AssignmentStatement node) { }
コード例 #58
0
ファイル: Parser.cs プロジェクト: unycorn/lolcode-dot-net
 void AssignmentStatement(out Statement stat)
 {
     AssignmentStatement ass = new AssignmentStatement(GetPragma(la)); stat = ass;
     LValue(out ass.lval);
     Expect(11);
     Expression(out ass.rval);
     SetEndPragma(stat);
 }
コード例 #59
0
 public override void PostWalk(AssignmentStatement node) { }
コード例 #60
0
ファイル: Parser.cs プロジェクト: unycorn/lolcode-dot-net
 void ExpressionStatement(out Statement stat)
 {
     AssignmentStatement ass = new AssignmentStatement(GetPragma(la)); ass.lval = new VariableLValue(GetPragma(la), GetVariable("IT")); stat = ass; Expression exp;
     Expression(out exp);
     ass.rval = exp; SetEndPragma(ass);
 }