Ejemplo n.º 1
0
        public override void LeaveBinaryExpression(BinaryExpression node)
        {
            if (CheckExpressionType(node.Right))
                CheckExpressionType(node.Left);

            if (BinaryOperatorType.ReferenceEquality == node.Operator)
            {
                if (IsTypeReference(node.Right))
                {
                    Warnings.Add(
                        CompilerWarningFactory.IsInsteadOfIsa(node));
                }
            }

            //check that the assignment or comparison is meaningful
            if (BinaryOperatorType.Assign == node.Operator
                || AstUtil.GetBinaryOperatorKind(node) == BinaryOperatorKind.Comparison)
            {
                if (AreSameExpressions(node.Left, node.Right))
                {
                    Warnings.Add(
                        (BinaryOperatorType.Assign == node.Operator)
                        ? CompilerWarningFactory.AssignmentToSameVariable(node)
                        : CompilerWarningFactory.ComparisonWithSameVariable(node)
                    );
                }
                else if (BinaryOperatorType.Assign != node.Operator
                         && AreConstantExpressions(node.Left, node.Right))
                {
                    WarnAboutConstantExpression(node);
                }
            }
        }
 public override void LeaveBinaryExpression(BinaryExpression node)
 {
     if (IsAssignmentToSpecialMember(node))
     {
         ProcessAssignmentToSpecialMember(node);
     }
 }
Ejemplo n.º 3
0
 public static Expression ComparisonFor(Expression local, IEnumerable<Expression> expressions)
 {
     BinaryExpression expression;
     IEnumerator<Expression> enumerator = expressions.GetEnumerator();
     if (!enumerator.MoveNext())
     {
         throw new AssertionFailedException("e.MoveNext()");
     }
     BinaryExpression expression1 = expression = new BinaryExpression(LexicalInfo.Empty);
     expression.set_Operator(11);
     expression.set_Left(Expression.Lift(local));
     expression.set_Right(Expression.Lift(enumerator.Current));
     Expression expression2 = expression;
     while (enumerator.MoveNext())
     {
         BinaryExpression expression3;
         BinaryExpression expression4;
         BinaryExpression expression11 = expression4 = new BinaryExpression(LexicalInfo.Empty);
         expression4.set_Operator(0x1c);
         expression4.set_Left(Expression.Lift(expression2));
         BinaryExpression expression12 = expression3 = new BinaryExpression(LexicalInfo.Empty);
         expression3.set_Operator(11);
         expression3.set_Left(Expression.Lift(local));
         expression3.set_Right(Expression.Lift(enumerator.Current));
         expression4.set_Right(expression3);
         expression2 = expression4;
     }
     return expression2;
 }
Ejemplo n.º 4
0
        public override void OnBinaryExpression(BinaryExpression node)
        {
            if (node.IsDeclarationStatement())
            {
                var localDeclaration = (InternalLocal)node.Left.Entity;
                if (localDeclaration.OriginalDeclaration == null)
                {
                    var closureBlock = node.GetAncestor <Block>();
                    if (closureBlock != null && closureBlock == node.ParentNode.ParentNode)
                    {
                        closureBlock.Statements.Remove((ExpressionStatement)node.ParentNode);  // Step 4: removes the local initialization

                        var capturedVariables = CollectCapturedParameters(closureBlock);

                        IntroduceLocalVariablesForCapturedLocals(closureBlock, capturedVariables);

                        FixCapturedVariableReferences(closureBlock, capturedVariables);

                        RemoveLocalVariableDeclaration(closureBlock, localDeclaration);

                        RemoveClosureInstanceInitialization(closureBlock);
                    }
                }
                return;
            }

            base.OnBinaryExpression(node);
        }
        protected virtual void AddDependency(ArrayLiteralExpression dependencies, BinaryExpression binaryExpression)
        {
            StringLiteralExpression dependency;

            //HACK: replace with proper AST method invocation
            if (binaryExpression.Left is StringLiteralExpression)
            {
                dependency = new StringLiteralExpression(string.Format("{0}|{1}",
                                                    binaryExpression.Left.ToString().Trim('\''),
                                                    binaryExpression.Right.ToString().Trim('\'')));
            }
            else if(binaryExpression.Left is BinaryExpression)
            {

                var left = (BinaryExpression) binaryExpression.Left;

                var package = left.Left.ToString().Trim('\'');
                var version = left.Right.ToString().Trim('\'');
                var dll = binaryExpression.Right.ToString().Trim('\'');

                dependency = new StringLiteralExpression(string.Format("{0}|{1}|{2}",
                                                    package,
                                                    dll,
                                                    version));
            }
            else
                throw new ArgumentOutOfRangeException(string.Format("Unknown Expression type {0} passed to RightShiftToMethodCompilerStep.AddDependency", binaryExpression.Left.GetType().Name));

            dependencies.Items.Add(dependency);
        }
Ejemplo n.º 6
0
        protected override Statement ExpandImpl(MacroStatement macro){
            var result = new Block();
            foreach (Statement st in macro.Body.Statements){
                var decl = st as DeclarationStatement;
                var refer = st as ExpressionStatement;
                if(null==decl){
                    var ex = refer.Expression;
                    if (ex is MethodInvocationExpression){
                        decl =
                            new DeclarationStatement(
                                new Declaration(((MethodInvocationExpression) refer.Expression).Target.ToCodeString(),
                                                null), null);
                    }
                    if(ex is BinaryExpression){
                        var b = ex as BinaryExpression;
                        decl = new DeclarationStatement(
                            new Declaration(b.Left.ToCodeString(),null),b.Right
                            );
                    }
                }

                var bin = new BinaryExpression(BinaryOperatorType.Assign,
                                               new TryCastExpression(new ReferenceExpression(decl.Declaration.Name),
                                                                     decl.Declaration.Type),
                                               decl.Initializer);
                var def = new MacroStatement("definebrailproperty");
                def.Arguments.Add(bin);
                result.Add(def);
            }
            return result;
        }
		override protected void ProcessAssignment(BinaryExpression node)
		{
			if (TypeSystemServices.IsQuackBuiltin(node.Left.Entity))
				BindDuck(node);
			else
				ProcessStaticallyTypedAssignment(node);
		}
Ejemplo n.º 8
0
 public object VisitRemoveHandlerStatement(RemoveHandlerStatement removeHandlerStatement, object data)
 {
     B.Expression expr = new B.BinaryExpression(GetLexicalInfo(removeHandlerStatement),
                                                B.BinaryOperatorType.InPlaceSubtraction,
                                                ConvertExpression(removeHandlerStatement.EventExpression),
                                                ConvertExpression(removeHandlerStatement.HandlerExpression));
     return(new B.ExpressionStatement(expr));
 }
Ejemplo n.º 9
0
 public object VisitAddHandlerStatement(AddHandlerStatement addHandlerStatement, object data)
 {
     B.Expression expr = new B.BinaryExpression(GetLexicalInfo(addHandlerStatement),
                                                B.BinaryOperatorType.InPlaceAddition,
                                                ConvertExpression(addHandlerStatement.EventExpression),
                                                ConvertExpression(addHandlerStatement.HandlerExpression));
     return(new B.ExpressionStatement(expr));
 }
Ejemplo n.º 10
0
 public override void LeaveBinaryExpression(BinaryExpression node)
 {
     if (BinaryOperatorType.Assign == node.Operator
         && (node.Right.NodeType != NodeType.TryCastExpression)
         && (IsTopLevelOfConditional(node)))
     {
         Warnings.Add(CompilerWarningFactory.EqualsInsteadOfAssign(node));
     }
 }
Ejemplo n.º 11
0
        public override void LeaveBinaryExpression(BinaryExpression node)
        {
            if (BinaryOperatorType.Assign != node.Operator)
                return;

            Expression newRight = Convert(node.Left.ExpressionType, node.Right);
            if (null != newRight)
                node.Right = newRight;
        }
Ejemplo n.º 12
0
        public object VisitReDimStatement(ReDimStatement reDimStatement, object data)
        {
            // Redim [Preserve] a(newBounds)
            // without preserve:
            //    a = array(Type, newBounds)
            // with preserve:
            //    ??1 = array(Type, newBounds)
            //    Array.Copy(a, ??1, System.Math.Min(a.Length, ??1.Length))
            //    a = ??1
            if (reDimStatement.IsPreserve)
            {
                AddError(reDimStatement, "Redim Preserve is not supported.");
            }
            ArrayList list = new ArrayList();

            foreach (InvocationExpression o in reDimStatement.ReDimClauses)
            {
                IdentifierExpression identifier = o.TargetObject as IdentifierExpression;
                if (identifier == null)
                {
                    AddError(o, "Sorry, that expression is too complex to be resolved by the converter.");
                }
                else
                {
                    if (identifier.TypeArguments != null && identifier.TypeArguments.Count > 0)
                    {
                        AddError(o, "Type parameters are not allowed here.");
                    }

                    // first we need to find out the array type
                    VariableResolver resolver = new VariableResolver(nameComparer);
                    TypeReference    r        = resolver.FindType(identifier.Identifier, reDimStatement);
                    if (r == null)
                    {
                        AddError(o, "The name '" + identifier.Identifier + "' could not be resolved by the converter.");
                    }
                    else if (!r.IsArrayType)
                    {
                        AddError(o, identifier.Identifier + " is not an array.");
                    }
                    else
                    {
                        ArrayCreateExpression ace = new ArrayCreateExpression(r);
                        foreach (Expression boundExpr in o.Arguments)
                        {
                            ace.Arguments.Add(Expression.AddInteger((Expression)boundExpr, 1));
                        }
                        ace.StartLocation = o.StartLocation;
                        B.Expression expr = new B.ReferenceExpression(GetLexicalInfo(identifier), identifier.Identifier);
                        expr = new B.BinaryExpression(GetLexicalInfo(reDimStatement), B.BinaryOperatorType.Assign, expr, ConvertExpression(ace));
                        list.Add(new B.ExpressionStatement(expr));
                    }
                }
            }
            return(list);
        }
Ejemplo n.º 13
0
 public override void LeaveBinaryExpression(BinaryExpression node)
 {
     switch (node.Operator)
     {
     case BinaryOperatorType.And:
     case BinaryOperatorType.Or:
         BindLogicalOperator(node);
         break;
     }
 }
Ejemplo n.º 14
0
        private MethodInvocationExpression MethodInvocationForEventSubscription(BinaryExpression node, IMethod method)
        {
            var methodTarget = CodeBuilder.CreateMemberReference(node.Left.LexicalInfo,
                ((MemberReferenceExpression)node.Left).Target, method);

            var mie = new MethodInvocationExpression(methodTarget);
            mie.Arguments.Add(node.Right);
            BindExpressionType(mie, method.ReturnType);
            return mie;
        }
Ejemplo n.º 15
0
 public override void OnBinaryExpression(BinaryExpression node)
 {
     var lhs = node.Left.ExpressionType;
     var rhs = node.Right.ExpressionType;
     base.OnBinaryExpression(node);
     var expression = GetLinqExpressionForOperator(node.Operator);
     ReplaceCurrentNode(new MethodInvocationExpression(
         ReferenceExpression.Lift(expression),
         AddOptionalConvert(rhs, lhs, node.Left),
         AddOptionalConvert(lhs, rhs, node.Right)));
 }
Ejemplo n.º 16
0
        public object VisitEraseStatement(EraseStatement eraseStatement, object data)
        {
            ArrayList statements = new ArrayList();

            foreach (Expression expr in eraseStatement.Expressions)
            {
                B.Expression e = ConvertExpression(expr);
                e = new B.BinaryExpression(B.BinaryOperatorType.Assign, e, new B.NullLiteralExpression());
                statements.Add(new B.ExpressionStatement(e));
            }
            return(statements);
        }
Ejemplo n.º 17
0
 public override void LeaveBinaryExpression(BinaryExpression node)
 {
     CheckExpressionType(node.Right);
     if (BinaryOperatorType.ReferenceEquality == node.Operator)
     {
         if (IsTypeReference(node.Right))
         {
             Warnings.Add(
                 CompilerWarningFactory.IsInsteadOfIsa(node));
         }
     }
 }
Ejemplo n.º 18
0
        public override void LeaveBinaryExpression(BinaryExpression node)
        {
            if (node.Operator != BinaryOperatorType.Assign
                || node.Right.NodeType != NodeType.IntegerLiteralExpression)
                return;

            IType expectedType = GetExpressionType(node.Left);
            if (!TypeSystemServices.IsPrimitiveNumber(expectedType))
                return;

            AssertLiteralInRange((IntegerLiteralExpression) node.Right, expectedType);
        }
Ejemplo n.º 19
0
 public override void OnBinaryExpression(BinaryExpression node)
 {
     base.OnBinaryExpression(node);
     BinaryOperatorType type = node.get_Operator();
     if (((type == 0x1f) || (type == 30)) && (this.IsBoolean(node.get_Left()) && this.IsBoolean(node.get_Right())))
     {
         string[] strArray = (node.get_Operator() != 0x1f) ? new string[] { "||", "|" } : new string[] { "&&", "&" };
         string expectedOperator = strArray[0];
         string actualOperator = strArray[1];
         this.get_Warnings().Add(UnityScriptWarnings.BitwiseOperatorWithBooleanOperands(node.get_LexicalInfo(), expectedOperator, actualOperator));
     }
 }
 protected bool IsAssignmentToSpecialMember(BinaryExpression node)
 {
     if (BinaryOperatorType.Assign == node.Operator &&
         NodeType.MemberReferenceExpression == node.Left.NodeType)
     {
         MemberReferenceExpression memberRef = node.Left as MemberReferenceExpression;
         Expression target = memberRef.Target;
         return !IsTerminalReferenceNode(target)
             && IsSpecialMemberTarget(target);
     }
     return false;
 }
		public override void OnBinaryExpression(BinaryExpression node)
		{
			if (acceptImplicit) {
				ReferenceExpression reference = node.Left as ReferenceExpression;
				if (node.Operator == BinaryOperatorType.Assign && reference != null) {
					if (!(reference is MemberReferenceExpression)) {
						DeclarationFound(reference.Name, null, node.Right, reference.LexicalInfo);
					}
				}
			}
			base.OnBinaryExpression(node);
		}
Ejemplo n.º 22
0
 void BindLogicalOperator(BinaryExpression node)
 {
     if (InjectImplicitBooleanConversions.IsLogicalCondition(node))
     {
     BindLogicalOperatorCondition(node);
     }
     else
     {
     node.Left = ExplicitBooleanContext(node.Left);
     node.Right = ExplicitBooleanContext(node.Right);
     }
 }
 public void ApplyImplicitArrayConversion(BinaryExpression node)
 {
     IType expressionType = this.GetExpressionType(node.get_Left());
     if (expressionType.get_IsArray())
     {
         IType type2 = this.GetExpressionType(node.get_Right());
         if (type2 == this.UnityScriptLangArray())
         {
             node.set_Right(this.get_CodeBuilder().CreateCast(expressionType, this.get_CodeBuilder().CreateMethodInvocation(node.get_Right(), this.ResolveMethod(type2, "ToBuiltin"), this.get_CodeBuilder().CreateTypeofExpression(expressionType.get_ElementType()))));
         }
     }
 }
Ejemplo n.º 24
0
 private void CheckEventUnsubscribe(BinaryExpression node, IEvent eventInfo)
 {
     CallableSignature expected = ((ICallableType) eventInfo.Type).GetSignature();
     CallableSignature actual = GetCallableSignature(node.Right);
     if (expected != actual)
     {
         Warnings.Add(
             CompilerWarningFactory.InvalidEventUnsubscribe(
                 node,
                 eventInfo.FullName,
                 expected));
     }
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Perform the actual expansion of the macro
        /// </summary>
        /// <param name="macro">The macro.</param>
        /// <returns></returns>
        protected override Statement DoExpand(MacroStatement macro)
        {
            Block body = (Block)macro.GetAncestor(NodeType.Block);
            MacroStatement macroParent = (MacroStatement)macro.GetAncestor(NodeType.MacroStatement);
           
            if (macro.Body.Statements.Count < 1 && parent.Name=="join")
            {
                Errors.Add(CompilerErrorFactory.CustomError(macro.LexicalInfo, "Join " + name + " section must contain at least a single expression statement"));
                return null;
            }

            if (macro.Arguments.Count == 0 && parent.Name!="join")
            {
                Errors.Add(CompilerErrorFactory.CustomError(macro.LexicalInfo, "Join " + name + " section must contain at least one key column"));
                return null;
            }

            if (macro.Arguments.Count > 0)
            {
                ArrayLiteralExpression ale = new ArrayLiteralExpression(macro.LexicalInfo);
                ale.Type = new ArrayTypeReference(CodeBuilder.CreateTypeReference(typeof(string)));
                foreach (Expression argument in macro.Arguments)
                {
                    ReferenceExpression expr = argument as ReferenceExpression;
                    if (expr == null)
                    {
                        Errors.Add(CompilerErrorFactory.CustomError(macro.LexicalInfo,"Join " + name +" section arguments must be reference expressions. Example: " + name + " name, surname"));
                        return null;
                    }
                    ale.Items.Add(new StringLiteralExpression(expr.Name));
                }
                var keyExpr = new BinaryExpression(BinaryOperatorType.Assign, new ReferenceExpression(name+"KeyColumns"), ale);
                macroParent.Arguments.Add(keyExpr);
            }

            foreach (Statement statement in macro.Body.Statements)
            {
                ExpressionStatement exprStmt = statement as ExpressionStatement;
                if(exprStmt==null)
                {
                    Errors.Add(CompilerErrorFactory.CustomError(macro.LexicalInfo, "Join " + name + " section can only contain expressions"));
                    return null;
                }
                Expression expr = exprStmt.Expression;
                parent.Arguments.Add(new MethodInvocationExpression(new ReferenceExpression(name), expr));
            }

            return null;
            
        }
        void BindComplexArraySlicing(SlicingExpression node)
        {
            if (node.Indices.Count > 1)
            {
                MethodInvocationExpression mie = null;
                var collapse = new ArrayLiteralExpression();
                var ranges = new ArrayLiteralExpression();
                for (int i = 0; i < node.Indices.Count; i++)
                {
                    ranges.Items.Add(node.Indices[i].Begin);
                    if (node.Indices[i].End == null ||
                        node.Indices[i].End == OmittedExpression.Default)
                    {
                        var end = new BinaryExpression(BinaryOperatorType.Addition,
                                                                    node.Indices[i].Begin,
                                                                    new IntegerLiteralExpression(1));
                        ranges.Items.Add(end);
                        BindExpressionType(end, GetExpressionType(node.Indices[i].Begin));
                        collapse.Items.Add(new BoolLiteralExpression(true));
                    }
                    else
                    {
                        ranges.Items.Add(node.Indices[i].End);
                        collapse.Items.Add(new BoolLiteralExpression(false));
                    }
                }
                mie = CodeBuilder.CreateMethodInvocation(MethodCache.RuntimeServices_GetMultiDimensionalRange1, node.Target, ranges);
                mie.Arguments.Add(collapse);

                BindExpressionType(ranges, TypeSystemServices.Map(typeof(int[])));
                BindExpressionType(collapse, TypeSystemServices.Map(typeof(bool[])));
                node.ParentNode.Replace(node, mie);
            }
            else
            {
                Slice slice = node.Indices[0];
                MethodInvocationExpression mie = null;

                if (null == slice.End || slice.End == OmittedExpression.Default)
                {
                    mie = CodeBuilder.CreateMethodInvocation(MethodCache.RuntimeServices_GetRange1, node.Target, slice.Begin);
                }
                else
                {
                    mie = CodeBuilder.CreateMethodInvocation(MethodCache.RuntimeServices_GetRange2, node.Target, slice.Begin, slice.End);
                }
                node.ParentNode.Replace(node, mie);
            }
        }
Ejemplo n.º 27
0
        public override void LeaveBinaryExpression(BinaryExpression node)
        {
            if (AstUtil.GetBinaryOperatorKind(node.Operator) == BinaryOperatorKind.Assignment
                || node.Operator == BinaryOperatorType.ReferenceEquality
                || node.Operator == BinaryOperatorType.ReferenceInequality)
                return;

            if (null == node.Left.ExpressionType || null == node.Right.ExpressionType)
                return;

            object lhs = GetLiteralValue(node.Left);
            object rhs = GetLiteralValue(node.Right);
            if (null == lhs || null == rhs)
                return;

            Expression folded = null;
            IType lhsType = GetExpressionType(node.Left);
            IType rhsType = GetExpressionType(node.Right);

            if (TypeSystemServices.BoolType == lhsType && TypeSystemServices.BoolType == rhsType)
            {
                folded = GetFoldedBoolLiteral(node.Operator, Convert.ToBoolean(lhs), Convert.ToBoolean(rhs));
            }
            else if (TypeSystemServices.DoubleType == lhsType || TypeSystemServices.SingleType == lhsType
                || TypeSystemServices.DoubleType == rhsType || TypeSystemServices.SingleType == rhsType)
            {
                folded = GetFoldedDoubleLiteral(node.Operator, Convert.ToDouble(lhs), Convert.ToDouble(rhs));
            }
            else if (TypeSystemServices.IsIntegerNumber(lhsType) || lhsType.IsEnum)
            {
                bool lhsSigned = TypeSystemServices.IsSignedNumber(lhsType);
                bool rhsSigned = TypeSystemServices.IsSignedNumber(rhsType);
                if (lhsSigned == rhsSigned) //mixed signed/unsigned not supported for folding
                {
                    folded = lhsSigned
                             ? GetFoldedIntegerLiteral(node.Operator, Convert.ToInt64(lhs), Convert.ToInt64(rhs))
                             : GetFoldedIntegerLiteral(node.Operator, Convert.ToUInt64(lhs), Convert.ToUInt64(rhs));
                }
            }

            if (null != folded)
            {
                folded.LexicalInfo = node.LexicalInfo;
                folded.ExpressionType = GetExpressionType(node);
                folded.Annotate(FoldedExpression, node);
                ReplaceCurrentNode(folded);
            }
        }
Ejemplo n.º 28
0
        public override void OnBinaryExpression(BinaryExpression node)
        {
            if (node.ContainsAnnotation("AssignsAreAttributes_visited"))
                return;
            if (node.Operator == BinaryOperatorType.Assign)
            {
                var name = node.Left.expand();
                var value = node.Right.expand();

                Element.SetAttributeValue(name,value.Replace("_QUOTED_USD_","$"));
            }
            else{
                base.OnBinaryExpression(node);
            }
            node.Annotate("AssignsAreAttributes_visited");
        }
		public override void OnBinaryExpression(BinaryExpression node)
		{
			if (node.Operator != BinaryOperatorType.Equality)
				return;

			if (IsTryGetParameterInvocation(node.Left) == false &&
				IsTryGetParameterInvocation(node.Right) == false)
				return;

			var mie = new MethodInvocationExpression();
			var expression = AstUtil.CreateReferenceExpression("Castle.MonoRail.Views.Brail.IgnoreNull.AreEqual");
			mie.Target = expression;
			mie.Arguments.Add(node.Left);
			mie.Arguments.Add(node.Right);

			ReplaceCurrentNode(mie);
		}
Ejemplo n.º 30
0
    	public override void LeaveBinaryExpression(BinaryExpression node)
        {
            var eventInfo = node.Left.Entity as IEvent;
            if (eventInfo == null)
                return;

            IMethod method;
            if (node.Operator == BinaryOperatorType.InPlaceAddition)
                method = eventInfo.GetAddMethod();
            else
            {
                method = eventInfo.GetRemoveMethod();
                CheckEventUnsubscribe(node, eventInfo);
            }

            ReplaceCurrentNode(
                MethodInvocationForEventSubscription(node, method));
        }
Ejemplo n.º 31
0
        public override void LeaveBinaryExpression(BinaryExpression node)
        {
            if (BinaryOperatorType.Assign == node.Operator)
            {
                ProcessAssignment(node);
                return;
            }

            if (!AstUtil.IsOverloadableOperator(node.Operator)) return;
            if (!IsDuckTyped(node.Left) && !IsDuckTyped(node.Right)) return;

            MethodInvocationExpression mie = CodeBuilder.CreateMethodInvocation(
                node.LexicalInfo,
                RuntimeServices_InvokeBinaryOperator,
                CodeBuilder.CreateStringLiteral(
                AstUtil.GetMethodNameForOperator(node.Operator)),
                node.Left, node.Right);
            Replace(mie);
        }
Ejemplo n.º 32
0
 public override void Apply(Node targetNode) {
     var cls = targetNode as ClassDefinition;
     if(cls==null) {
         this.Context.Errors.Add(new CompilerError(this.LexicalInfo,
                                                   "ControllerAttribute is applyable only to classes"));
         return;
     }
     targetNode.GetEnclosingModule().Imports.Add(new Import(this.LexicalInfo,"Comdiv.Controllers"));
      cls.BaseTypes.Clear();
      cls.BaseTypes.Insert(0, new SimpleTypeReference("Comdiv.Controllers.ExtensionBaseController"));
     if(!cls.Name.EndsWith("Controller")) {
         cls.Name = cls.Name + "Controller";
     }
     var body = targetNode.GetEnclosingModule()["regmethod"] as Block;
     var registrycall = new SlicingExpression(new ReferenceExpression("registry"), new StringLiteralExpression(cls.Name.ToLower()));
     var assign = new ReferenceExpression(cls.Name);
     var aexpr = new BinaryExpression(BinaryOperatorType.Assign, registrycall, assign);
     body.Add(aexpr);
 }
Ejemplo n.º 33
0
        public object VisitAssignmentExpression(AssignmentExpression assignmentExpression, object data)
        {
            B.Expression left  = ConvertExpression(assignmentExpression.Left);
            B.Expression right = ConvertExpression(assignmentExpression.Right);
            bool         isInPlace;

            B.BinaryOperatorType op = ConvertOperator(assignmentExpression.Op, out isInPlace);
            if (op == B.BinaryOperatorType.None)
            {
                AddError(assignmentExpression, "Unknown operator.");
                return(null);
            }
            if (!isInPlace)
            {
                // convert L <OP>= R to L = L OP R
                right = new B.BinaryExpression(GetLexicalInfo(assignmentExpression), op, left, right);
                op    = B.BinaryOperatorType.Assign;
            }
            return(new B.BinaryExpression(GetLexicalInfo(assignmentExpression), op, left, right));
        }
			// Possible declarations:
			// Dictionary<LineNumber, List<ColumnNumber>>
			// LineNumber and ColumnNumber are 0-based (text editor coordinates)
			
			public override void OnBinaryExpression(BinaryExpression node)
			{
				ReferenceExpression reference = node.Left as ReferenceExpression;
				if (node.Operator == BinaryOperatorType.Assign
				    && reference != null
				    && !(reference is MemberReferenceExpression)
				    && reference.LexicalInfo.IsValid)
				{
					int lineNumber = reference.LexicalInfo.Line - 1;
					
					List<int> l;
					if (!declarations.TryGetValue(lineNumber, out l)) {
						l = new List<int>();
						declarations.Add(lineNumber, l);
					}
					
					l.Add(reference.LexicalInfo.Column - 1);
				}
				base.OnBinaryExpression(node);
			}
Ejemplo n.º 35
0
		private void tryClass(Node targetNode) {
			var cls = targetNode as ClassDefinition;
			if (cls == null)
			{
				return;
			}
			if (cls.BaseTypes.Count == 0)
			{
				cls.BaseTypes.Insert(0, new SimpleTypeReference("Comdiv.Framework.Quick.QuickBase"));
			}
			var attr = new Attribute("Comdiv.Framework.Quick.actionAttribute");
			attr.Arguments.Add(new StringLiteralExpression(cls.Name.Replace("_", ".")));
			cls.Attributes.Add(attr);

			var body = targetNode.GetEnclosingModule()["regmethod"] as Block;
			var registrycall = new SlicingExpression(new ReferenceExpression("registry"), new StringLiteralExpression(cls.Name.Replace("_", ".") + ".quick"));
			var assign = new ReferenceExpression(cls.Name);
			var aexpr = new BinaryExpression(BinaryOperatorType.Assign, registrycall, assign);
			body.Add(aexpr);
		}
Ejemplo n.º 36
0
 public override void LeaveBinaryExpression(BinaryExpression node)
 {
     switch (node.Operator)
     {
         case BinaryOperatorType.BitwiseOr:
             LeaveBitwiseOr(node);
             break;
         case BinaryOperatorType.BitwiseAnd:
             LeaveBitwiseAnd(node);
             break;
         case BinaryOperatorType.Addition:
             LeaveAddition(node);
             break;
         case BinaryOperatorType.Subtraction:
             LeaveSubtraction(node);
             break;
         case BinaryOperatorType.ExclusiveOr:
             LeaveExclusiveOr(node);
             break;
     }
 }
Ejemplo n.º 37
0
        private ReferenceExpression CreateLocalVariableDeclarationFor(MemberReferenceExpression mre, BinaryExpression initializationExpression)
        {
            var localName = mre.Name.Replace("$", "");
            var local     = new ReferenceExpression(localName)
            {
                ExpressionType = initializationExpression.Right.ExpressionType,
                Entity         = new InternalLocal(new Local(localName, true), initializationExpression.Right.ExpressionType)
                {
                    OriginalDeclaration = new Declaration(localName, CodeBuilder.CreateTypeReference(initializationExpression.Right.ExpressionType)),
                }
            };

            return(local);
        }
Ejemplo n.º 38
0
        public object VisitSwitchStatement(SwitchStatement switchStatement, object data)
        {
            // We have a problem: given is still not implemented in boo.
            // So here's the if / else workaround:
            string oldSwitchTempName = currentSwitchTempName;

            currentSwitchTempName = GenerateName();
            ArrayList l = new ArrayList(3);

            B.BinaryExpression init = new B.BinaryExpression(B.BinaryOperatorType.Assign,
                                                             new B.ReferenceExpression(currentSwitchTempName),
                                                             ConvertExpression(switchStatement.SwitchExpression));
            l.Add(new B.ExpressionStatement(init));
            B.IfStatement    dummyStatement = new B.IfStatement(GetLexicalInfo(switchStatement));
            B.IfStatement    first          = null;
            B.IfStatement    current        = dummyStatement;
            B.BreakStatement bs;
            for (int i = 0; i < switchStatement.SwitchSections.Count; i++)
            {
                current = (B.IfStatement)((INode)switchStatement.SwitchSections[i]).AcceptVisitor(this, current);
                if (i == 0)
                {
                    first = current;
                }
                bs = GetLastStatement(current.TrueBlock) as B.BreakStatement;
                if (bs != null)
                {
                    bs.ReplaceBy(null);
                }
            }
            bs = GetLastStatement(current.FalseBlock) as B.BreakStatement;
            if (bs != null)
            {
                bs.ReplaceBy(null);
            }

            string endSwitchName = currentSwitchTempName + "_end";

            first.Accept(new ReplaceBreakStatementsVisitor(endSwitchName));

            FindUnneededLabelsVisitor fulv = new FindUnneededLabelsVisitor(currentSwitchTempName + "_", nameComparer);

            first.Accept(fulv);

            bool needsEndLabel = fulv.NeededLabels.Contains(endSwitchName);

            fulv.RemoveLabels();             // remove "goto case" labels that aren't needed
            currentSwitchTempName = oldSwitchTempName;

            if (first == dummyStatement)
            {
                l.AddRange(dummyStatement.FalseBlock.Statements);
            }
            else
            {
                l.Add(first);
            }
            if (needsEndLabel)
            {
                l.Add(MakeLabel(endSwitchName));
            }

            return(l);
        }
Ejemplo n.º 39
0
        public object VisitSwitchSection(SwitchSection switchSection, object data)
        {
            B.IfStatement surroundingIf = (B.IfStatement)data;
            bool          isDefault     = false;
            ArrayList     conditions    = new ArrayList();
            ArrayList     labels        = new ArrayList();

            foreach (CaseLabel caseLabel in switchSection.SwitchLabels)
            {
                if (caseLabel.IsDefault)
                {
                    isDefault = true;
                }
                else
                {
                    if (caseLabel.BinaryOperatorType != BinaryOperatorType.None)
                    {
                        AddError(caseLabel, "VB's Case Is currently not supported (Daniel's too lazy for VB stuff)");
                    }
                    else
                    {
                        B.Expression expr = ConvertExpression(caseLabel.Label);
                        if (expr != null)
                        {
                            conditions.Add(new B.BinaryExpression(B.BinaryOperatorType.Equality,
                                                                  new B.ReferenceExpression(currentSwitchTempName),
                                                                  expr));
                            string labelName = expr.ToCodeString().GetHashCode().ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
                            labels.Add(MakeLabel(currentSwitchTempName + "_" + labelName));
                        }
                    }
                }
            }
            B.IfStatement s = null;
            if (conditions.Count > 0)
            {
                s = new B.IfStatement(GetLexicalInfo(switchSection));
                if (surroundingIf != null)
                {
                    s.FalseBlock             = surroundingIf.FalseBlock;
                    surroundingIf.FalseBlock = new B.Block();
                    surroundingIf.FalseBlock.Add(s);
                }
                s.TrueBlock = new B.Block();
                foreach (B.Statement stmt in labels)
                {
                    s.TrueBlock.Add(stmt);
                }
                B.Expression combined = (B.Expression)conditions[0];
                for (int i = 1; i < conditions.Count; i++)
                {
                    combined = new B.BinaryExpression(B.BinaryOperatorType.Or, combined, (B.Expression)conditions[i]);
                }
                s.Condition = combined;
                foreach (Statement node in switchSection.Children)
                {
                    AddToBlock(node, s.TrueBlock);
                }
            }
            if (s == null)
            {
                s = surroundingIf;
            }
            if (isDefault)
            {
                if (s.FalseBlock == null)
                {
                    s.FalseBlock = new B.Block();
                }
                s.FalseBlock.Add(MakeLabel(currentSwitchTempName + "_default"));
                foreach (Statement node in switchSection.Children)
                {
                    AddToBlock(node, s.FalseBlock);
                }
            }
            return(s);
        }
Ejemplo n.º 40
0
 public static BinaryOperatorKind GetBinaryOperatorKind(BinaryExpression expression)
 {
     return(GetBinaryOperatorKind(expression.Operator, false));
 }
Ejemplo n.º 41
0
 public static BinaryOperatorKind GetBinaryOperatorKind(BinaryExpression expression, bool exact)
 {
     return(GetBinaryOperatorKind(expression.Operator, exact));
 }