public Invocation GetCtorInvocation() { AST.Expression rr = LazyInit.VolatileRead(ref this.ctorInvocation); if (rr != null) { return(rr as Invocation); } else { int totalArgumentCount = unresolved.positionalArguments.Count + unresolved.namedCtorArguments.Count; AST.Expression[] arguments = new AST.Expression[totalArgumentCount]; string[] argumentNames = new string[totalArgumentCount]; int i = 0; while (i < unresolved.positionalArguments.Count) { IConstantValue cv = unresolved.positionalArguments[i]; arguments[i] = cv.ResolveConstant(context); i++; } foreach (var pair in unresolved.namedCtorArguments) { argumentNames[i] = pair.Key; arguments[i] = pair.Value.ResolveConstant(context); i++; } rr = NewExpression.ResolveObjectCreation(context, unresolved.loc, attributeType, arguments, argumentNames); return(LazyInit.GetOrSet(ref this.ctorInvocation, rr) as Invocation); } }
void ISupportsInterning.PrepareForInterning(IInterningProvider provider) { name = provider.Intern(name); type = provider.Intern(type); attributes = provider.InternList(attributes); defaultValue = provider.Intern(defaultValue); }
public UnresolvedSecurityDeclarationBlob(int securityAction, byte[] blob) { BlobReader reader = new BlobReader(blob, null); this.securityAction = new SimpleConstantValue(securityActionTypeReference, securityAction); this.blob = blob; if (reader.ReadByte() == '.') { // binary attribute uint attributeCount = reader.ReadCompressedUInt32(); for (uint i = 0; i < attributeCount; i++) { unresolvedAttributes.Add(new UnresolvedSecurityAttribute(this, (int)i)); } } else { // for backward compatibility with .NET 1.0: XML-encoded attribute var attr = new DefaultUnresolvedAttribute(permissionSetAttributeTypeReference); attr.ConstructorParameterTypes.Add(securityActionTypeReference); attr.PositionalArguments.Add(this.securityAction); string xml = System.Text.Encoding.Unicode.GetString(blob); attr.AddNamedPropertyArgument("XML", new SimpleConstantValue(KnownTypeReference.String, xml)); unresolvedAttributes.Add(attr); } }
public IParameter CreateResolvedParameter(ITypeResolveContext context) { Freeze(); if (DefaultExpression != null) { defaultValue = new CastExpression(this.type as Expression, DefaultExpression, DefaultExpression.Location); } if (defaultValue != null) { return(new ResolvedParameterWithDefaultValue(defaultValue, context) { Type = type.Resolve(context), Name = name, Region = region, Attributes = attributes.CreateResolvedAttributes(context), IsRef = this.IsRef, IsOut = this.IsOut, IsParams = this.IsParams }); } else { var owner = context.CurrentMember as IParameterizedMember; var resolvedAttributes = attributes.CreateResolvedAttributes(context); bool isOptional = resolvedAttributes != null && resolvedAttributes.Any(a => IsOptionalAttribute(a.AttributeType)); return(new ParameterSpec(type.Resolve(context), name, owner, region, resolvedAttributes, IsRef, IsOut, IsParams, isOptional)); } }
InvocationResolveResult GetCtorInvocation() { ResolveResult rr = LazyInit.VolatileRead(ref this.ctorInvocation); if (rr != null) { return(rr as InvocationResolveResult); } else { CSharpResolver resolver = new CSharpResolver(context); int totalArgumentCount = unresolved.positionalArguments.Count + unresolved.namedCtorArguments.Count; ResolveResult[] arguments = new ResolveResult[totalArgumentCount]; string[] argumentNames = new string[totalArgumentCount]; int i = 0; while (i < unresolved.positionalArguments.Count) { IConstantValue cv = unresolved.positionalArguments[i]; arguments[i] = cv.Resolve(context); i++; } foreach (var pair in unresolved.namedCtorArguments) { argumentNames[i] = pair.Key; arguments[i] = pair.Value.Resolve(context); i++; } rr = resolver.ResolveObjectCreation(attributeType, arguments, argumentNames); return(LazyInit.GetOrSet(ref this.ctorInvocation, rr) as InvocationResolveResult); } }
public void AddNamedFieldArgument(string fieldName, IConstantValue value) { this.NamedArguments.Add(new KeyValuePair <IMemberReference, IConstantValue>( new DefaultMemberReference(EntityType.Field, attributeType, fieldName), value )); }
public override BoundNode VisitObjectCreationExpression(ObjectCreationExpressionSyntax node) { if (node.Initializer != null) { throw new NotSupportedException(LocStr.CE_InitializerListsNotSupported, node); } MethodSymbol constructorSymbol = (MethodSymbol)GetSymbol(node); BoundExpression[] boundArguments = new BoundExpression[node.ArgumentList.Arguments.Count]; bool isConstant = true; for (int i = 0; i < boundArguments.Length; ++i) { boundArguments[i] = VisitExpression(node.ArgumentList.Arguments[i].Expression, constructorSymbol.Parameters[i].Type); isConstant &= boundArguments[i].IsConstant; } // Constant folding on struct creation when possible // Also implicitly handles parameterless constructors on value types, which Udon does not expose constructors for if (isConstant && constructorSymbol.IsExtern && constructorSymbol.ContainingType.IsValueType) { var constArgs = boundArguments.Select(e => e.ConstantValue.Value).ToArray(); object constantValue = Activator.CreateInstance(constructorSymbol.ContainingType.UdonType.SystemType, constArgs); IConstantValue constantStore = (IConstantValue)Activator.CreateInstance(typeof(ConstantValue <>).MakeGenericType(constantValue.GetType()), constantValue); return(new BoundConstantExpression(constantStore, constructorSymbol.ContainingType, node)); } return(BoundInvocationExpression.CreateBoundInvocation(Context, node, constructorSymbol, null, boundArguments)); }
public void AddNamedPropertyArgument(string propertyName, IConstantValue value) { this.NamedArguments.Add(new KeyValuePair <IMemberReference, IConstantValue>( new DefaultMemberReference(EntityType.Property, attributeType, propertyName), value )); }
public Expression ConvertConstantValue(IConstantValue constantValue) { if (constantValue == null) { throw new ArgumentNullException("constantValue"); } return(ConvertConstantValue(constantValue.Resolve(context))); }
public override void ApplyInterningProvider(IInterningProvider provider) { base.ApplyInterningProvider(provider); if (provider != null) { constantValue = provider.Intern(constantValue); } }
public BoundPrefixOperatorExpression(AbstractPhaseContext context, SyntaxNode node, BoundAccessExpression assignmentTarget, MethodSymbol operatorMethod) : base(node, null, null, null) { TargetExpression = assignmentTarget; Type targetType = TargetExpression.ValueType.UdonType.SystemType; IConstantValue incrementValue = (IConstantValue)Activator.CreateInstance( typeof(ConstantValue <>).MakeGenericType(targetType), Convert.ChangeType(1, targetType)); InternalExpression = CreateBoundInvocation(context, null, operatorMethod, null, new BoundExpression[] { assignmentTarget, new BoundConstantExpression(incrementValue, TargetExpression.ValueType, node) }); }
ResolveResult Resolve(IConstantValue constantValue, ITypeResolveContext context) { if (constantValue != null) { return(constantValue.Resolve(context)); } else { return(new ErrorResolveResult(SharedTypes.UnknownType)); } }
/// <summary> /// Copy constructor /// </summary> public DefaultParameter(IParameter p) { this.name = p.Name; this.type = p.Type; this.attributes = CopyList(p.Attributes); this.defaultValue = p.DefaultValue; this.region = p.Region; this.IsRef = p.IsRef; this.IsOut = p.IsOut; this.IsParams = p.IsParams; }
/// <summary> /// Copy constructor /// </summary> public DefaultParameter(IParameter p) { this.name = p.Name; this.type = p.Type; this.attributes = CopyList(p.Attributes); this.defaultValue = p.DefaultValue; this.region = p.Region; this.IsRef = p.IsRef; this.IsOut = p.IsOut; this.IsParams = p.IsParams; }
internal override Expression Resolve(ParserContext parser) { if (parser.ConstantAndEnumResolutionState[this.ConstStatement] != ConstantResolutionState.RESOLVED) { this.ConstStatement.Resolve(parser); } IConstantValue value = this.ConstStatement.Expression as IConstantValue; if (value == null) { throw new ParserException(this.ConstStatement, "Could not resolve this expression into a constant value."); } return(value.CloneValue(this.FirstToken, this.Owner)); }
public void FieldOffsetAttribute() { IField field = ctx.GetClass(typeof(ExplicitFieldLayoutStruct)).Fields.Single(f => f.Name == "Field0"); Assert.AreEqual("System.Runtime.InteropServices.FieldOffsetAttribute", field.Attributes.Single().AttributeType.Resolve(ctx).FullName); IConstantValue arg = field.Attributes.Single().PositionalArguments.Single(); Assert.AreEqual("System.Int32", arg.GetValueType(ctx).FullName); Assert.AreEqual(0, arg.GetValue(ctx)); field = ctx.GetClass(typeof(ExplicitFieldLayoutStruct)).Fields.Single(f => f.Name == "Field100"); Assert.AreEqual("System.Runtime.InteropServices.FieldOffsetAttribute", field.Attributes.Single().AttributeType.Resolve(ctx).FullName); arg = field.Attributes.Single().PositionalArguments.Single(); Assert.AreEqual("System.Int32", arg.GetValueType(ctx).FullName); Assert.AreEqual(100, arg.GetValue(ctx)); }
public IncrementConstantValue(IConstantValue baseValue, int incrementAmount = 1) { if (baseValue == null) { throw new ArgumentNullException("baseValue"); } if (baseValue is IncrementConstantValue icv) { this.baseValue = icv.baseValue; this.incrementAmount = icv.incrementAmount + incrementAmount; } else { this.baseValue = baseValue; this.incrementAmount = incrementAmount; } }
internal override Expression Resolve(ParserContext parser) { HashSet <int> intKeyDupeCheck = new HashSet <int>(); HashSet <string> stringKeyDupeCheck = new HashSet <string>(); bool dictHasStringKeys = false; // Iterate through KVP in parallel so that errors will get reported in the preferred order. for (int i = 0; i < this.Keys.Length; ++i) { Expression keyExpr = this.Keys[i].Resolve(parser); IConstantValue keyConst = keyExpr as IConstantValue; bool keyIsString = keyConst is StringConstant; bool keyIsInteger = keyConst is IntegerConstant; if (!keyIsInteger && !keyIsString) { throw new ParserException(keyExpr.FirstToken, "Only string and integer constants can be used as dictionary keys in inline definitions."); } if (i == 0) { dictHasStringKeys = keyIsString; } else if (dictHasStringKeys != keyIsString) { throw new ParserException(keyExpr.FirstToken, "Cannot mix types of dictionary keys."); } bool collision = false; if (keyIsString) { string keyValue = ((StringConstant)keyConst).Value; collision = stringKeyDupeCheck.Contains(keyValue); stringKeyDupeCheck.Add(keyValue); } else { int keyValue = ((IntegerConstant)keyConst).Value; collision = intKeyDupeCheck.Contains(keyValue); intKeyDupeCheck.Add(keyValue); } this.Keys[i] = keyExpr; this.Values[i] = this.Values[i].Resolve(parser); } return(this); }
private static bool TryImplicitConstantConversion(ref BoundExpression boundExpression, TypeSymbol targetType) { if (!boundExpression.IsConstant) { return(false); } if (boundExpression.ValueType == targetType) { return(false); } var targetSystemType = targetType.UdonType.SystemType; object constantValue = boundExpression.ConstantValue.Value; // if (targetSystemType == typeof(string)) // { // IConstantValue constant = new ConstantValue<string>(constantValue?.ToString() ?? ""); // // boundExpression = new BoundConstantExpression(constant, targetType, boundExpression.SyntaxNode); // } var sourceSystemType = boundExpression.ValueType.UdonType.SystemType; if (ConstantExpressionOptimizer.CanDoConstantConversion(sourceSystemType) && ConstantExpressionOptimizer.CanDoConstantConversion(targetSystemType)) { IConstantValue constant = (IConstantValue)Activator.CreateInstance(typeof(ConstantValue <>).MakeGenericType(targetSystemType), ConstantExpressionOptimizer.FoldConstantConversion(targetSystemType, constantValue)); boundExpression = new BoundConstantExpression(constant, targetType, boundExpression.SyntaxNode); return(true); } if (boundExpression.ValueType.IsEnum && boundExpression.ValueType.IsExtern && UdonSharpUtils.IsIntegerType(targetSystemType)) { boundExpression = new BoundConstantExpression(ConstantExpressionOptimizer.FoldConstantConversion(targetSystemType, constantValue), targetType); return(true); } return(false); }
internal override Expression Resolve(ParserContext parser) { for (int i = 0; i < this.Args.Length; ++i) { this.Args[i] = this.Args[i].Resolve(parser); } this.Root = this.Root.Resolve(parser); // TODO: this is hardcoded just for Math.floor(numeric constant). Eventually, it'd be nice // for a few common functions to have a compile-time codepath here. // e.g. Core.parseInt, Math.sin, etc. if (this.Root is FunctionReference) { FunctionDefinition funcDef = ((FunctionReference)this.Root).FunctionDefinition; IConstantValue cv = this.SimplifyFunctionCall(funcDef, this.Args); if (cv != null) { return((Expression)cv); } } if (this.Root is SpecialEntity) { if (this.Root is SpecialEntity.EnumMaxFunction) { int max = ((SpecialEntity.EnumMaxFunction) this.Root).GetMax(); return(new IntegerConstant(this.Root.FirstToken, max, this.Owner)); } if (this.Root is SpecialEntity.EnumValuesFunction) { int[] rawValues = ((SpecialEntity.EnumValuesFunction) this.Root).GetValues(); List <Expression> values = new List <Expression>(); foreach (int rawValue in rawValues) { values.Add(new IntegerConstant(this.Root.FirstToken, rawValue, this.Owner)); } return(new ListDefinition(this.FirstToken, values, AType.Integer(this.FirstToken), this.Owner, false, null)); } } return(this); }
public static BoundConstantExpression FoldConstantUnaryPrefixExpression( BindContext context, PrefixUnaryExpressionSyntax syntax, MethodSymbol unaryOperator, BoundExpression operand) { if (!operand.IsConstant) { return(null); } if (unaryOperator.IsOperator && unaryOperator.IsExtern) { object foldedValue; object operandValue = operand.ConstantValue.Value; switch (syntax.OperatorToken.Kind()) { case SyntaxKind.MinusToken: foldedValue = DynamicInvoke.UnaryNegate(operandValue); break; case SyntaxKind.ExclamationToken: foldedValue = DynamicInvoke.UnaryNot(operandValue); break; case SyntaxKind.TildeToken: foldedValue = DynamicInvoke.BitwiseNot(operandValue); break; default: return(null); } IConstantValue constantValue = (IConstantValue)Activator.CreateInstance(typeof(ConstantValue <>).MakeGenericType(foldedValue.GetType()), foldedValue); return(new BoundConstantExpression(constantValue, context.GetTypeSymbol(foldedValue.GetType()), syntax)); } return(null); }
public override Value EmitValue(EmitContext context) { Value returnValue = context.GetReturnValue(TargetExpression.ValueType); context.EmitValueAssignment(returnValue, TargetExpression); Type targetType = TargetExpression.ValueType.UdonType.SystemType; IConstantValue incrementValue = (IConstantValue)Activator.CreateInstance( typeof(ConstantValue <>).MakeGenericType(targetType), Convert.ChangeType(1, targetType)); BoundExpression expression = CreateBoundInvocation(context, null, InternalExpression.Method, null, new BoundExpression[] { BoundAccessExpression.BindAccess(returnValue), new BoundConstantExpression(incrementValue, TargetExpression.ValueType, SyntaxNode) }); if (InternalExpression.Method.ReturnType != TargetExpression.ValueType) { expression = new BoundCastExpression(null, expression, ValueType, true); } context.EmitSet(TargetExpression, expression); return(returnValue); }
public UnresolvedSecurityDeclarationBlob(int securityAction, byte[] blob) { BlobReader reader = new BlobReader(blob, null); this.securityAction = new SimpleConstantValue(securityActionTypeReference, securityAction); this.blob = blob; if (reader.ReadByte() == '.') { // binary attribute uint attributeCount = reader.ReadCompressedUInt32(); for (uint i = 0; i < attributeCount; i++) { unresolvedAttributes.Add(new UnresolvedSecurityAttribute(this, (int)i)); } } else { // for backward compatibility with .NET 1.0: XML-encoded attribute var attr = new DefaultUnresolvedAttribute(permissionSetAttributeTypeReference); attr.ConstructorParameterTypes.Add(securityActionTypeReference); attr.PositionalArguments.Add(this.securityAction); string xml = System.Text.Encoding.Unicode.GetString(blob); attr.AddNamedPropertyArgument("XML", new SimpleConstantValue(KnownTypeReference.String, xml)); unresolvedAttributes.Add(attr); } }
public IMethod ResolveConstructor(ITypeResolveContext context) { CSharpResolver r = new CSharpResolver(context); IType type = attributeType.Resolve(context); int totalArgumentCount = 0; if (positionalArguments != null) { totalArgumentCount += positionalArguments.Count; } if (namedCtorArguments != null) { totalArgumentCount += namedCtorArguments.Count; } ResolveResult[] arguments = new ResolveResult[totalArgumentCount]; string[] argumentNames = new string[totalArgumentCount]; int i = 0; if (positionalArguments != null) { while (i < positionalArguments.Count) { IConstantValue cv = positionalArguments[i]; arguments[i] = new ConstantResolveResult(cv.GetValueType(context), cv.GetValue(context)); i++; } } if (namedCtorArguments != null) { foreach (var pair in namedCtorArguments) { argumentNames[i] = pair.Key; arguments[i] = new ConstantResolveResult(pair.Value.GetValueType(context), pair.Value.GetValue(context)); i++; } } MemberResolveResult mrr = r.ResolveObjectCreation(type, arguments, argumentNames) as MemberResolveResult; return(mrr != null ? mrr.Member as IMethod : null); }
public void ExplicitStructLayoutAttribute() { IAttribute attr = ctx.GetClass(typeof(ExplicitFieldLayoutStruct)).Attributes.Single(); Assert.AreEqual("System.Runtime.InteropServices.StructLayoutAttribute", attr.AttributeType.Resolve(ctx).FullName); IConstantValue arg1 = attr.PositionalArguments.Single(); Assert.AreEqual("System.Runtime.InteropServices.LayoutKind", arg1.GetValueType(ctx).FullName); Assert.AreEqual((int)LayoutKind.Explicit, arg1.GetValue(ctx)); var arg2 = attr.NamedArguments[0]; Assert.AreEqual("CharSet", arg2.Key); Assert.AreEqual("System.Runtime.InteropServices.CharSet", arg2.Value.GetValueType(ctx).FullName); Assert.AreEqual((int)CharSet.Unicode, arg2.Value.GetValue(ctx)); var arg3 = attr.NamedArguments[1]; Assert.AreEqual("Pack", arg3.Key); Assert.AreEqual("System.Int32", arg3.Value.GetValueType(ctx).FullName); Assert.AreEqual(8, arg3.Value.GetValue(ctx)); }
void ISupportsInterning.PrepareForInterning(IInterningProvider provider) { baseValue = provider.Intern(baseValue); }
protected DefaultField(IField f) : base(f) { this.constantValue = f.ConstantValue; this.IsReadOnly = f.IsReadOnly; this.IsVolatile = f.IsVolatile; }
public UnresolvedSecurityDeclaration(IConstantValue securityAction, byte[] blob) { Debug.Assert(securityAction != null); Debug.Assert(blob != null); this.securityAction = securityAction; this.blob = blob; }
public void AddNamedArgument(string name, IConstantValue value) { CheckBeforeMutation(); this.NamedArguments.Add(new KeyValuePair<string, IConstantValue>(name, value)); }
public void AddNamedFieldArgument(string fieldName, IConstantValue value) { this.NamedArguments.Add(new KeyValuePair<IMemberReference, IConstantValue>( new DefaultMemberReference(EntityType.Field, attributeType, fieldName), value )); }
public override void VisitConstantValueNode(IConstantValue constantValueParam, IHighlightingConsumer context) { context.AddHighlighting(new CgHighlighting(CgHighlightingAttributeIds.NUMBER, constantValueParam.GetDocumentRange())); base.VisitConstantValueNode(constantValueParam, context); }
public ResolvedParameterWithDefaultValue(IConstantValue defaultValue, ITypeResolveContext context) { this.defaultValue = defaultValue; this.context = context; }
void ISupportsInterning.PrepareForInterning(IInterningProvider provider) { baseValue = provider.Intern(baseValue); }
public void AddNamedArgument(string name, IConstantValue value) { CheckBeforeMutation(); this.NamedArguments.Add(new KeyValuePair <string, IConstantValue>(name, value)); }
public ResolvedParameterWithDefaultValue(IConstantValue defaultValue, ITypeResolveContext context) { this.defaultValue = defaultValue; this.context = context; }
static void AddNamedArgument(DefaultAttribute attribute, string name, IConstantValue value) { attribute.NamedArguments.Add(new KeyValuePair<string, IConstantValue>(name, value)); }
public void AddNamedPropertyArgument(string propertyName, IConstantValue value) { this.NamedArguments.Add(new KeyValuePair<IMemberReference, IConstantValue>( new DefaultMemberReference(EntityType.Property, attributeType, propertyName), value )); }
public BoundConstantExpression(IConstantValue constantValue, TypeSymbol constantType, SyntaxNode node) : base(node, null) { ConstantValue = constantValue; ConstantType = constantType; }
ResolveResult Resolve(IConstantValue constantValue, ITypeResolveContext context) { if (constantValue != null) return constantValue.Resolve(context); else return new ErrorResolveResult(SharedTypes.UnknownType); }
protected DefaultField(IField f) : base(f) { this.constantValue = f.ConstantValue; this.IsReadOnly = f.IsReadOnly; this.IsVolatile = f.IsVolatile; }
public override void ApplyInterningProvider(IInterningProvider provider) { base.ApplyInterningProvider(provider); if (provider != null) constantValue = provider.Intern(constantValue); }
public IncrementConstantValue(IConstantValue baseValue, int incrementAmount = 1) { if (baseValue == null) throw new ArgumentNullException("baseValue"); IncrementConstantValue icv = baseValue as IncrementConstantValue; if (icv != null) { this.baseValue = icv.baseValue; this.incrementAmount = icv.incrementAmount + incrementAmount; } else { this.baseValue = baseValue; this.incrementAmount = incrementAmount; } }
public Expression ConvertConstantValue(IConstantValue constantValue) { if (constantValue == null) throw new ArgumentNullException("constantValue"); return ConvertConstantValue(constantValue.Resolve(context)); }
void ISupportsInterning.PrepareForInterning(IInterningProvider provider) { name = provider.Intern(name); type = provider.Intern(type); attributes = provider.InternList(attributes); defaultValue = provider.Intern(defaultValue); }
public static BoundConstantExpression FoldConstantBinaryExpression( BindContext context, BinaryExpressionSyntax syntax, MethodSymbol binaryOperator, BoundExpression lhs, BoundExpression rhs) { // Value type + null comparison which will always be false for == and true for != // This folding is needed for null comparisons in generics to work as expected if ((lhs.ValueType.IsValueType && rhs.IsConstant && rhs.ConstantValue.Value == null) || (rhs.ValueType.IsValueType && lhs.IsConstant && lhs.ConstantValue.Value == null)) { if (syntax.OperatorToken.Kind() == SyntaxKind.EqualsEqualsToken) { return(new BoundConstantExpression(new ConstantValue <bool>(false), context.GetTypeSymbol(typeof(bool)), syntax)); } if (syntax.OperatorToken.Kind() == SyntaxKind.ExclamationEqualsToken) { return(new BoundConstantExpression(new ConstantValue <bool>(true), context.GetTypeSymbol(typeof(bool)), syntax)); } } if (!lhs.IsConstant || !rhs.IsConstant) { return(null); } if (binaryOperator == null || (binaryOperator.IsOperator && binaryOperator.IsExtern)) { object foldedValue; object lhsValue = lhs.ConstantValue.Value; object rhsValue = rhs.ConstantValue.Value; switch (syntax.OperatorToken.Kind()) { case SyntaxKind.PlusToken: foldedValue = DynamicInvoke.Add(lhsValue, rhsValue); break; case SyntaxKind.MinusToken: foldedValue = DynamicInvoke.Sub(lhsValue, rhsValue); break; case SyntaxKind.AsteriskToken: foldedValue = DynamicInvoke.Mul(lhsValue, rhsValue); break; case SyntaxKind.SlashToken: foldedValue = DynamicInvoke.Div(lhsValue, rhsValue); break; case SyntaxKind.PercentToken: foldedValue = DynamicInvoke.Mod(lhsValue, rhsValue); break; case SyntaxKind.LessThanLessThanToken: foldedValue = DynamicInvoke.LSh(lhsValue, rhsValue); break; case SyntaxKind.GreaterThanGreaterThanToken: foldedValue = DynamicInvoke.RSh(lhsValue, rhsValue); break; case SyntaxKind.CaretToken: foldedValue = DynamicInvoke.Xor(lhsValue, rhsValue); break; case SyntaxKind.AmpersandToken: case SyntaxKind.AmpersandAmpersandToken: // When we're dealing with constants short circuiting shouldn't matter foldedValue = DynamicInvoke.BitwiseAnd(lhsValue, rhsValue); break; case SyntaxKind.BarToken: case SyntaxKind.BarBarToken: foldedValue = DynamicInvoke.BitwiseOr(lhsValue, rhsValue); break; case SyntaxKind.GreaterThanToken: foldedValue = DynamicInvoke.GreaterThan(lhsValue, rhsValue); break; case SyntaxKind.GreaterThanEqualsToken: foldedValue = DynamicInvoke.GreaterThanOrEquals(lhsValue, rhsValue); break; case SyntaxKind.LessThanToken: foldedValue = DynamicInvoke.LessThan(lhsValue, rhsValue); break; case SyntaxKind.LessThanOrEqualExpression: foldedValue = DynamicInvoke.LessThanOrEquals(lhsValue, rhsValue); break; case SyntaxKind.EqualsEqualsToken: foldedValue = DynamicInvoke.Equal(lhsValue, rhsValue); break; case SyntaxKind.ExclamationEqualsToken: foldedValue = DynamicInvoke.NotEqual(lhsValue, rhsValue); break; default: return(null); } IConstantValue constantValue = (IConstantValue)Activator.CreateInstance(typeof(ConstantValue <>).MakeGenericType(foldedValue.GetType()), foldedValue); return(new BoundConstantExpression(constantValue, context.GetTypeSymbol(foldedValue.GetType()), syntax)); } return(null); }