Пример #1
0
        static Expression CollectCondition(Expression switchExpr, AstNodeCollection <CaseLabel> caseLabels)
        {
            // default
            if (caseLabels.Count == 0 || caseLabels.Any(label => label.Expression.IsNull))
            {
                return(null);
            }

            var conditionList = caseLabels.Select(
                label => new BinaryOperatorExpression(switchExpr.Clone(), BinaryOperatorType.Equality, label.Expression.Clone()))
                                .ToArray();

            // insert necessary parentheses
            foreach (var expr in conditionList)
            {
                expr.AcceptVisitor(insertParenthesesVisitor);
            }

            if (conditionList.Length == 1)
            {
                return(conditionList [0]);
            }

            // combine case labels into an conditional or expression
            BinaryOperatorExpression condition        = null;
            BinaryOperatorExpression currentCondition = null;

            for (int i = 0; i < conditionList.Length - 1; i++)
            {
                var newCondition = new BinaryOperatorExpression
                {
                    Operator = BinaryOperatorType.ConditionalOr,
                    Left     = conditionList[i]
                };
                if (currentCondition == null)
                {
                    condition = newCondition;
                }
                else
                {
                    currentCondition.Right = newCondition;
                }
                currentCondition = newCondition;
            }
            currentCondition.Right = conditionList [conditionList.Length - 1];

            return(condition);
        }
Пример #2
0
        private void AddMethod(bool ctor, EntityDeclaration methodDeclaration, AstNodeCollection<ParameterDeclaration> parameters)
        {
            CLRType t = m_clrTypes.Value.Last.Value;

            List<KeyValuePair<string, string>> args = parameters.Select(p =>
                                                        new KeyValuePair<string, string>(p.Name, p.Type.ToString())
                                                      )
                                                      .ToList();

            Method m = new Method(
                CheckFlag(methodDeclaration.Modifiers, Modifiers.Override),
                ctor,
                CheckFlag(methodDeclaration.Modifiers, Modifiers.Static),
                new Visibility(VisibilityMapper.Map(methodDeclaration.Modifiers)),
                CheckFlag(methodDeclaration.Modifiers, Modifiers.Virtual),
                methodDeclaration.Name,
                CheckFlag(methodDeclaration.Modifiers, Modifiers.Abstract),
                args,
                methodDeclaration.ReturnType.ToString()

            );

            t.Methods.Add(m);   // connect
        }
Пример #3
0
 private List <JStatement> VisitStatements(AstNodeCollection <Statement> list)
 {
     return(list.Select(VisitStatement).ToList());
 }
Пример #4
0
        private void AddMethod(bool ctor, EntityDeclaration md, AstNodeCollection<ParameterDeclaration> ps)
        {
            ClassesAndStructsAndInterfaces csi = (ClassesAndStructsAndInterfaces)GetDeclarationFor(md);

            List<KeyValuePair<string, string>> args = ps.Select(p =>
                                                        new KeyValuePair<string, string>(p.Name, p.Type.ToString())
                                                      )
                                                      .ToList();

            if( args.Count > 0 ){
                args.ForEach(kvp => AddToNotDefaultReferencedTypes(csi, kvp.Value));
            }

            Method m = new Method(
                GetVisibility(md),
                md.Name,
                al.CheckFlag(md.Modifiers, Modifiers.Static),
                al.CheckFlag(md.Modifiers, Modifiers.Virtual),
                al.CheckFlag(md.Modifiers, Modifiers.Abstract),
                al.CheckFlag(md.Modifiers, Modifiers.Override),
                md.ReturnType.ToString(),
                ctor,
                args
            );

            AddToNotDefaultReferencedTypes(csi, m.ReturnType);
            csi.Methods.Add(m);
        }