Ejemplo n.º 1
0
 // AssignStatement
 public override bool Walk(AssignStatement node)
 {
     assignmentAnalyzer.Analyze(node);
     return true;
 }
Ejemplo n.º 2
0
 public void Analyze(AssignStatement assignment)
 {
     this.assignment = assignment;
     foreach (Expression e in assignment.Left) {
         FieldExpression field = e as FieldExpression;
         if (null != field) {
             analyzer.SaveFieldExpressionession(field, assignment.Right);
         }
         e.Walk(this);
     }
 }
 public void PostWalk(AssignStatement node)
 {
     PostProcess(node);
 }
 // AssignStatement
 public bool Walk(AssignStatement node)
 {
     return Process(node);
 }
Ejemplo n.º 5
0
 public override void PostWalk(AssignStatement node)
 {
 }
Ejemplo n.º 6
0
 // AssignStmt
 public override bool Walk(AssignStatement node)
 {
     node.Right.Walk(this);
     foreach (Expression e in node.Left) {
         e.Walk(fdef);
     }
     return false;
 }
            // anything else gets emitted directly
            // into the current initialization function.  If this
            // is something like a conditional block that includes
            // a function definition it will not be visible at .NET
            // scope (but will still work).
            public override bool Walk(AssignStatement node)
            {
                if (stack.Count == 1) {
                    node.Emit(stack.Peek().StaticConstructor);
                    return false;
                }

                CallExpression rhsCall = node.Right as CallExpression;
                if (rhsCall != null) {
                    bool fCantEmit = false;
                    NameExpression ne = rhsCall.Target as NameExpression;
                    string get = null, set = null;
                    if (ne != null) {
                        if (ne.Name.GetString() == "property") {
                            // property definition...
                            fCantEmit = GetPropertyAccessors(rhsCall, ref ne, ref get, ref set);
                        }
                    }

                    if (!fCantEmit) {
                        PropertyBuilder pb = stack.Peek().Type.DefineProperty(((NameExpression)node.Left[0]).Name.GetString(), PropertyAttributes.None, typeof(object));

                        foreach (CodeGen cg in stack.Peek().Methods) {
                            if (get != null && cg.methodInfo.Name == get) {
                                pb.SetGetMethod((MethodBuilder)cg.methodInfo);
                            } else if (set != null && cg.methodInfo.Name == set) {
                                pb.SetSetMethod((MethodBuilder)cg.methodInfo);
                            }
                        }
                        return false;
                    }
                }

                ConstantExpression rhsConstant = node.Right as ConstantExpression;
                NameExpression rhsName;
                if (rhsConstant != null) {
                    if (rhsConstant.Value != null) {
                        stack.Peek().Type.AddStaticField(rhsConstant.Value.GetType(), ((NameExpression)node.Left[0]).Name.GetString());
                    } else {
                        stack.Peek().Type.AddStaticField(typeof(object), ((NameExpression)node.Left[0]).Name.GetString());
                    }
                } else if ((rhsName = node.Right as NameExpression) != null &&
                    (rhsName.Name.GetString() == "True" || rhsName.Name.GetString() == "False")) {
                    stack.Peek().Type.AddStaticField(typeof(bool), ((NameExpression)node.Left[0]).Name.GetString());
                } else {
                    Emit(node);
                }

                return false;
            }
 public AssignmentDefinition(AssignStatement assignment)
 {
     this.assignment = assignment;
 }
            public override bool Walk(AssignStatement node)
            {
                if (!FoundSlots && node.Left.Count == 1) {
                    NameExpression ne = node.Left[0] as NameExpression;
                    if (ne != null && ne.Name.GetString() == "__slots__") {
                        ListExpression le = node.Right as ListExpression;
                        if (le != null) {
                            string[] slotRes = new string[le.Items.Count];
                            for (int i = 0; i < le.Items.Count; i++) {
                                ConstantExpression ce = le.Items[i] as ConstantExpression;
                                if (ce == null) {
                                    slotRes = null;
                                    break;
                                }

                                string slotStr = ce.Value as string;
                                if (slotStr == null) {
                                    slotRes = null;
                                    break;
                                }
                                slotRes[i] = slotStr;
                            }
                            slots = slotRes;
                        }

                        FoundSlots = true;
                    }
                }
                return false;
            }
Ejemplo n.º 10
0
 public virtual void PostWalk(AssignStatement node)
 {
 }
Ejemplo n.º 11
0
 // AssignStatement
 public virtual bool Walk(AssignStatement node)
 {
     return true;
 }
Ejemplo n.º 12
0
 // AssignStmt
 public override bool Walk(AssignStatement node)
 {
     foreach (Expression e in node.Left) {
         e.Walk(define);
     }
     return true;
 }
Ejemplo n.º 13
0
        //expr_stmt: testlist (augassign testlist | ('=' testlist)*)
        //augassign: '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' | '<<=' | '>>=' | '**=' | '//='
        private Statement ParseExprStmt()
        {
            Expression lhs = ParseTestListAsExpr(false);

            if (MaybeEat(TokenKind.Assign)) {
                List<Expression> l = new List<Expression>();
                l.Add(lhs);
                do {
                    Expression e = ParseTestListAsExpr(false);
                    l.Add(e);
                } while (MaybeEat(TokenKind.Assign));

                int last = l.Count - 1;
                Expression rhs = (Expression)l[last];
                l.RemoveAt(last);
                Expression[] lhss = l.ToArray();

                //We check for legal assignment targets during code generation rather than parsing
                Statement ret = new AssignStatement(lhss, rhs);
                ret.SetLoc(GetExternal(), lhs.Start, GetEnd());
                return ret;
            } else {
                BinaryOperator op = GetAssignOp(PeekToken());
                if (op == null) {
                    Statement ret = new ExpressionStatement(lhs);
                    ret.SetLoc(GetExternal(), lhs.Start, GetEnd());
                    return ret;
                } else {
                    NextToken();
                    Expression rhs = ParseTestListAsExpr(false);
                    Statement ret = new AugAssignStatement(op, lhs, rhs);
                    ret.SetLoc(GetExternal(), lhs.Start, GetEnd());
                    return ret;
                }
            }
        }