public ExternSynthesizedOperatorSymbol(BuiltinOperatorType operatorType, TypeSymbol type, AbstractPhaseContext context) : base(null, context) { TypeSymbol boolType = context.GetTypeSymbol(SpecialType.System_Boolean); if (type == boolType && operatorType == BuiltinOperatorType.UnaryNegation) { Parameters = new[] { new ParameterSymbol(type, context) }.ToImmutableArray(); } else { if ((operatorType == BuiltinOperatorType.LeftShift || operatorType == BuiltinOperatorType.RightShift) && (type == context.GetTypeSymbol(SpecialType.System_UInt32) || type == context.GetTypeSymbol(SpecialType.System_UInt64) || type == context.GetTypeSymbol(SpecialType.System_Int64))) { Parameters = new[] { new ParameterSymbol(type, context), new ParameterSymbol(context.GetTypeSymbol(SpecialType.System_Int32), context) }.ToImmutableArray(); } else { Parameters = new[] { new ParameterSymbol(type, context), new ParameterSymbol(type, context) } }
public BoundShortCircuitOperatorExpression(BinaryExpressionSyntax node, BuiltinOperatorType operatorType, BoundExpression lhs, BoundExpression rhs, AbstractPhaseContext context) : base(node) { ValueType = context.GetTypeSymbol(SpecialType.System_Boolean); Lhs = lhs; Rhs = rhs; OperatorType = operatorType; }
public ExternBuiltinOperatorSymbol(IMethodSymbol sourceSymbol, AbstractPhaseContext context) : base(sourceSymbol, context) { if (sourceSymbol.Parameters.Length == 1 && (ContainingType == context.GetTypeSymbol(SpecialType.System_Byte) || ContainingType == context.GetTypeSymbol(SpecialType.System_SByte) || ContainingType == context.GetTypeSymbol(SpecialType.System_Int16) || ContainingType == context.GetTypeSymbol(SpecialType.System_UInt16))) { ReturnType = context.GetTypeSymbol(SpecialType.System_Int32); } OperatorType = TranslateOperatorName(sourceSymbol.Name); ExternSignature = GetSignature(context); }
public static MethodInfo[] GetOperators(System.Type type, BuiltinOperatorType builtinOperatorType) { List <MethodInfo> foundOperators = new List <MethodInfo>(); // If it's a builtin type then create a fake operator methodinfo for it. // If this operator doesn't actually exist, it will get filtered by the overload finding if (IsBuiltinType(type)) { foundOperators.Add(new OperatorMethodInfo(type, builtinOperatorType)); } // Now look for operators that the type defines string operatorName = System.Enum.GetName(typeof(BuiltinOperatorType), builtinOperatorType); if (builtinOperatorType == BuiltinOperatorType.Multiplication) { operatorName = "Multiply"; // Udon breaks standard naming with its multiplication overrides on base types } else if (builtinOperatorType == BuiltinOperatorType.UnaryMinus) { operatorName = "UnaryNegation"; } operatorName = $"op_{operatorName}"; System.Type currentType = type; while (currentType != null) { foundOperators.AddRange(currentType.GetMethods(BindingFlags.Public | BindingFlags.Static).Where(e => e.Name == operatorName)); currentType = currentType.BaseType; } // Add the object equality and inequality operators if we haven't already found better matches if (foundOperators.Count == 0 && type != typeof(object) && !type.IsValueType && (builtinOperatorType == BuiltinOperatorType.Equality || builtinOperatorType == BuiltinOperatorType.Inequality)) { foundOperators.AddRange(GetOperators(typeof(object), builtinOperatorType)); } else if (foundOperators.Count == 0 && type.IsEnum && (builtinOperatorType == BuiltinOperatorType.Equality || builtinOperatorType == BuiltinOperatorType.Inequality)) // Handle enum comparisons { foundOperators.Add(typeof(object).GetMethod("Equals", BindingFlags.Public | BindingFlags.Static)); } return(foundOperators.ToArray()); }
public OperatorMethodInfo(Type type, BuiltinOperatorType operatorTypeIn) { operatorSourceType = type; operatorType = operatorTypeIn; }