/// <summary> /// Applies the transformation /// </summary> /// <returns>The transformed item.</returns> /// <param name="el">The item to visit.</param> public ASTItem Transform(ASTItem el) { var ss = el as SwitchStatement; if (ss == null) { return(el); } // We cannot support conversions as part of the switch statements, // so we statically compute them here var nonstatic = ss.Cases.SelectMany(x => x.Item1).OfType <CustomNodes.ConversionExpression>().ToArray(); if (nonstatic.Length != 0) { foreach (var e in nonstatic) { var et = State.VHDLType(e); var cx = e.Expression; var pt = State.VHDLType(cx); // If we have a coversion thing caused by an off enum if (et.IsEnum && pt == VHDLTypes.INTEGER && cx is PrimitiveExpression) { var name = State.RegisterCustomEnum(ss.SwitchExpression.SourceResultType, et, (cx as PrimitiveExpression).Value); var c = new AST.Constant() { Name = name, CecilType = ss.SwitchExpression.SourceResultType, DefaultValue = name // (cx as PrimitiveExpression).Value }; var mr = new AST.MemberReferenceExpression() { Parent = ss, SourceResultType = c.CecilType, Target = c }; e.ReplaceWith(mr); } } return(null); } return(el); }
/// <summary> /// Creates a new variable instnace /// </summary> /// <param name="source">The source item</param> public Literal(AST.Constant source) { Source = source ?? throw new ArgumentNullException(nameof(source)); }