protected override Boolean handleSwitch(SwitchStatementNode switchStatement, HashSet <StatementNode> visited)
        {
            if (expressionChecker.handleExpression(switchStatement.Selector, visited, true) == AssignmentState.Assigned)
            {
                return(null);
            }
            bool hasDefault = false;

            foreach (var section in switchStatement.Sections)
            {
                if (section.CaseExpression == null)
                {
                    hasDefault = true;
                }
                if (section.Statements.size() == 0)
                {
                    continue;
                }
                var first = section.Statements[0];
                if (first.getUserData(typeof(StatementInfo)) == null)
                {
                    continue;
                }
                visitOrigin(first);
            }
            if (hasDefault)
            {
                return(Boolean.FALSE);
            }
            return(Boolean.TRUE);
        }
 public virtual Value evaluate(Context cx, SwitchStatementNode node)
 {
     output("<SwitchStatementNode position=\"" + node.pos() + "\">");
     indent_Renamed_Field++;
     if (node.expr != null)
     {
         node.expr.evaluate(cx, this);
     }
     if (node.statements != null)
     {
         node.statements.evaluate(cx, this);
     }
     indent_Renamed_Field--;
     output("</SwitchStatementNode>");
     return(null);
 }
Ejemplo n.º 3
0
            protected override Void handleSwitch(SwitchStatementNode switchStatement, Set <TypeInfo> dependencies)
            {
                expressionHandler.handleExpression(switchStatement.Selector, dependencies, true);
                var sinfo = switchStatement.Selector.getUserData(typeof(ExpressionInfo));

                addDependencies(sinfo.Type, dependencies);
                foreach (var section in switchStatement.Sections)
                {
                    if (section.CaseExpression != null)
                    {
                        if (!sinfo.Type.IsEnum)
                        {
                            expressionHandler.handleExpression(section.CaseExpression, dependencies, true);
                        }
                    }
                    foreach (var s in section.Statements)
                    {
                        handleStatement(s, dependencies);
                    }
                }
                return(null);
            }
Ejemplo n.º 4
0
 private static void Walk([NotNull] Agent agent, [NotNull] SwitchStatementNode switchStatement, bool isStrict)
 {
     //TODO
 }
		public virtual Value evaluate(Context cx, SwitchStatementNode node)
		{
			output("<SwitchStatementNode position=\"" + node.pos() + "\">");
			indent_Renamed_Field++;
			if (node.expr != null)
			{
				node.expr.evaluate(cx, this);
			}
			if (node.statements != null)
			{
				node.statements.evaluate(cx, this);
			}
			indent_Renamed_Field--;
			output("</SwitchStatementNode>");
			return null;
		}
        protected override Void handleSwitch(SwitchStatementNode switchStatement, Void source)
        {
            this.ExpressionValidator.handleExpression(switchStatement.Selector, null, true);
            var sinfo = switchStatement.Selector.getUserData(typeof(ExpressionInfo));

            if (sinfo == null)
            {
                throw context.error(CompileErrorId.IntegerStringOrEnumExpected, switchStatement.Selector);
            }
            var type = ValidationHelper.getType(context, switchStatement.getSelector());

            if (!type.IsNumeric && !type.IsEnum && type != context.TypeSystem.StringType)
            {
                throw context.error(CompileErrorId.IntegerStringOrEnumExpected, switchStatement.Selector);
            }
            var isString = false;

            switch (type.NumericTypeKind)
            {
            case Long:
            case Float:
            case Double:
                throw context.error(CompileErrorId.IntegerStringOrEnumExpected, switchStatement.Selector);

            default:
                ValidationHelper.setBoxing(context, context.TypeSystem.IntType, switchStatement.getSelector());
                break;

            case None:
                isString = !type.IsEnum;
                break;
            }
            var hasDefault = false;
            HashMap <String, Integer> enumOrdinals = null;
            HashSet <String>          cases        = null;

            if (type.IsEnum)
            {
                enumOrdinals = new HashMap <String, Integer>();
                cases        = new HashSet <String>();
                int i = 0;
                foreach (var f in type.Fields)
                {
                    if (f.IsEnum)
                    {
                        enumOrdinals[f.Name] = Integer.valueOf(i++);
                    }
                }
            }
            try {
                context.MemberResolver.enterScope();
                foreach (var section in switchStatement.Sections)
                {
                    if (section.CaseExpression == null)
                    {
                        if (hasDefault)
                        {
                            throw context.error(CompileErrorId.DuplicateCase, section);
                        }
                        hasDefault = true;
                    }
                    else
                    {
                        if (type.IsEnum)
                        {
                            if (section.CaseExpression.ExpressionKind != ExpressionKind.SimpleName)
                            {
                                throw context.error(CompileErrorId.EnumCaseNotIdentifier, section);
                            }
                            var name = (SimpleNameExpressionNode)section.CaseExpression;
                            var text = context.getIdentifier(name.NameOffset, name.NameLength);
                            if (!cases.add(text))
                            {
                                throw context.error(CompileErrorId.DuplicateCase, section);
                            }
                            if (!enumOrdinals.containsKey(text))
                            {
                                throw context.error(CompileErrorId.UnknownEnumMember, section, text, BytecodeHelper.getDisplayName(type));
                            }
                            name.addOrReplaceUserData(enumOrdinals.get(text));
                        }
                        else
                        {
                            this.ExpressionValidator.handleExpression(section.CaseExpression, type, true);
                            ValidationHelper.getType(context, section.CaseExpression);
                            var cinfo = section.CaseExpression.getUserData(typeof(ExpressionInfo));
                            if (cinfo == null)
                            {
                                if (!isString)
                                {
                                    throw context.error(CompileErrorId.UnexpectedNull, switchStatement);
                                }
                            }
                            else
                            {
                                if (!cinfo.IsConstant)
                                {
                                    throw context.error(CompileErrorId.ConstantValueExpected, section);
                                }
                                if (!type.isAssignableFrom(ValidationHelper.getType(context, section.CaseExpression)))
                                {
                                    context.addError(CompileErrorId.NoImplicitConversion, section.CaseExpression,
                                                     BytecodeHelper.getDisplayName(cinfo.Type),
                                                     BytecodeHelper.getDisplayName(type));
                                }
                            }
                        }
                    }
                    foreach (var s in section.Statements)
                    {
                        handleStatement(s, null);
                    }
                }
            } finally {
                context.MemberResolver.leaveScope();
            }
            return(null);
        }
Ejemplo n.º 7
0
 internal override void Visit(SwitchStatementNode node)
 {
 }