public static ExpressionCollection FromArray(params Boo.Lang.Compiler.Ast.Expression[] items) { var collection = new ExpressionCollection(); collection.AddRange(items); return(collection); }
public override void PropagateChanges(MethodInvocationExpression eval, List chain) { ExpressionCollection expressions = new ExpressionCollection(); foreach (object local1 in chain.Reversed) { if (!(local1 is ProcessAssignmentsToSpecialMembers.ChainItem)) { } ProcessAssignmentsToSpecialMembers.ChainItem item = (ProcessAssignmentsToSpecialMembers.ChainItem) RuntimeServices.Coerce(local1, typeof(ProcessAssignmentsToSpecialMembers.ChainItem)); if (item.Container is MethodInvocationExpression) { break; } if (item.Container is SlicingExpression) { SlicingExpression expression = item.Container; Expression[] expressionArray1 = new Expression[] { expression.get_Target().CloneNode(), expression.get_Indices().get_Item(0).get_Begin().CloneNode(), this.get_CodeBuilder().CreateReference(item.Local) }; expressions.Add(this.CreateConstructorInvocation(this._sliceValueTypeChangeConstructor, expressionArray1)); break; } MemberReferenceExpression container = item.Container; Expression[] args = new Expression[] { container.get_Target().CloneNode(), this.get_CodeBuilder().CreateStringLiteral(container.get_Name()), this.get_CodeBuilder().CreateReference(item.Local) }; expressions.Add(this.CreateConstructorInvocation(this._valueTypeChangeConstructor, args)); } MethodInvocationExpression expression3 = this.get_CodeBuilder().CreateMethodInvocation(this._propagateChanges); IArrayType type = this._valueTypeChangeType.MakeArrayType(1); expression3.get_Arguments().Add(this.get_CodeBuilder().CreateArray(type, expressions)); eval.get_Arguments().Add(expression3); }
public static bool IsArrayArgumentExplicitlyProvided(IParameter[] parameters, ExpressionCollection args) { IType expressionType = TypeSystemServices.GetExpressionType(args.get_Item(-1)); IType rhs = parameters[parameters.Length + -1].get_Type(); if (!RuntimeServices.EqualityOperator(expressionType, rhs)) { } return ((parameters.Length == args.Count) ? RuntimeServices.EqualityOperator(expressionType, EmptyArrayType.Default) : false); }
void ConvertExpressions(IEnumerable input, B.ExpressionCollection output) { foreach (Expression e in input) { B.Expression expr = ConvertExpression(e); if (expr != null) { output.Add(expr); } } }
public GenericParameterInferrer(CompilerContext context, IMethod genericMethod, ExpressionCollection arguments) { _context = context; _genericMethod = genericMethod; _arguments = arguments; InitializeInferredTypes(GenericMethod.GenericInfo.GenericParameters); InitializeDependencies( GenericMethod.GenericInfo.GenericParameters, GenericMethod.CallableType.GetSignature()); }
public GenericParameterInferrer(CompilerContext context, IMethod genericMethod, ExpressionCollection arguments) { _genericMethod = genericMethod; Initialize(context); InitializeArguments(arguments); InitializeTypeParameters(GenericMethod.GenericInfo.GenericParameters); InitializeDependencies( GenericMethod.GenericInfo.GenericParameters, GenericMethod.CallableType.GetSignature()); InitializeClosureDependencies(); }
private IEntity ResolveAmbiguousPropertyReference(ReferenceExpression node, Ambiguous candidates, ExpressionCollection args) { IEntity[] entities = candidates.Entities; IEntity[] getters = GetGetMethods(entities); IEntity found = GetCorrectCallableReference(node, args, getters); if (null != found && EntityType.Method == found.EntityType) { IProperty property = (IProperty)entities[GetIndex(getters, found)]; BindProperty(node, property); return property; } return candidates; }
private IEntity ResolveAmbiguousMethodReference(ReferenceExpression node, Ambiguous candidates, ExpressionCollection args) { //BOO-656 if (!AstUtil.IsTargetOfMethodInvocation(node) && !AstUtil.IsTargetOfSlicing(node) && !node.IsTargetOfAssignment()) { return candidates.Entities[0]; } return candidates; }
bool HasOperatorSignature(IMethod method, ExpressionCollection args) { return method.IsStatic && (args.Count == method.GetParameters().Length) && CheckParameterTypesStrictly(method, args); }
IType GetMostGenericType(ExpressionCollection args) { return TypeSystemServices.GetMostGenericType(args); }
IEntity GetCorrectCallableReference(Node sourceNode, ExpressionCollection args, IEntity[] candidates) { // BOO-844: Ensure all candidates were visited (to make property setters have correct signature) foreach (IEntity candidate in candidates) { EnsureRelatedNodeWasVisited(sourceNode, candidate); } IEntity found = CallableResolutionService.ResolveCallableReference(args, candidates); if (null == found) EmitCallableResolutionError(sourceNode, candidates, args); else BindNullableParameters(args, ((IMethodBase) found).CallableType); return found; }
private void EmitCallableResolutionError(Node sourceNode, IEntity[] candidates, ExpressionCollection args) { //if this is call without arguments and ambiguous contains generic method without arguments //than emit BCE0164 for readability var genericMethod = candidates.OfType<IMethod>().FirstOrDefault(m => m.GenericInfo != null && m.GetParameters().Length == 0); if (args.Count == 0 && genericMethod != null) { Error(CompilerErrorFactory.CannotInferGenericMethodArguments(sourceNode, genericMethod)); return; } if (CallableResolutionService.ValidCandidates.Count > 1) { Error(CompilerErrorFactory.AmbiguousReference(sourceNode, candidates[0].Name, CallableResolutionService.ValidCandidates.Select(c => (IEntity)c.Method))); return; } var candidate = candidates[0]; var constructor = candidate as IConstructor; if (constructor != null) { Error(CompilerErrorFactory.NoApropriateConstructorFound(sourceNode, constructor.DeclaringType, GetSignature(args))); } else { Error(CompilerErrorFactory.NoApropriateOverloadFound(sourceNode, GetSignature(args), candidate.FullName)); } }
private void CheckItems(IType expectedElementType, ExpressionCollection items) { foreach (Expression element in items) AssertTypeCompatibility(element, expectedElementType, GetExpressionType(element)); }
/// <summary> /// Attempts to infer the generic parameters of a method from a set of arguments. /// </summary> /// <returns> /// An array consisting of inferred types for the method's generic arguments, /// or null if type inference failed. /// </returns> public IType[] InferMethodGenericArguments(IMethod method, ExpressionCollection arguments) { if (method.GenericInfo == null) return null; GenericParameterInferrer inferrerr = new GenericParameterInferrer(Context, method, arguments); if (inferrerr.Run()) { return inferrerr.GetInferredTypes(); } return null; }
public static bool EndsWithExplodeExpression(ExpressionCollection expressionCollection) { return(expressionCollection.Count > 0 && IsExplodeExpression(expressionCollection[-1])); }
public ArrayLiteralExpression CreateArray(IType arrayType, ExpressionCollection items) { if (!arrayType.IsArray) throw new ArgumentException(string.Format("'{0}' is not an array type!", arrayType), "arrayType"); var array = new ArrayLiteralExpression(); array.ExpressionType = arrayType; array.Items.AddRange(items); TypeSystemServices.MapToConcreteExpressionTypes(array.Items); return array; }
public Boo.Lang.Compiler.Ast.ExpressionCollection PopRange(int begin) { Boo.Lang.Compiler.Ast.ExpressionCollection range = new Boo.Lang.Compiler.Ast.ExpressionCollection(_parent); range.InnerList.Extend(InternalPopRange(begin)); return(range); }
protected void list_items( ExpressionCollection items ) //throws RecognitionException, TokenStreamException { Expression item = null; try { // for error handling { switch ( LA(1) ) { case ESEPARATOR: case CAST: case CHAR: case FALSE: case NOT: case NULL: case SELF: case SUPER: case THEN: case TRUE: case TYPEOF: case TRIPLE_QUOTED_STRING: case LPAREN: case DOUBLE_QUOTED_STRING: case SINGLE_QUOTED_STRING: case ID: case MULTIPLY: case LBRACK: case SPLICE_BEGIN: case DOT: case LBRACE: case QQ_BEGIN: case SUBTRACT: case LONG: case INCREMENT: case DECREMENT: case ONES_COMPLEMENT: case INT: case BACKTICK_QUOTED_STRING: case RE_LITERAL: case DOUBLE: case FLOAT: case TIMESPAN: { item=expression(); if (0==inputState.guessing) { items.Add(item); } { { // ( ... )* for (;;) { if ((LA(1)==COMMA) && (tokenSet_5_.member(LA(2)))) { match(COMMA); item=expression(); if (0==inputState.guessing) { items.Add(item); } } else { goto _loop634_breakloop; } } _loop634_breakloop: ; } // ( ... )* } { switch ( LA(1) ) { case COMMA: { match(COMMA); break; } case RBRACK: case RBRACE: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } break; } case RBRACK: case RBRACE: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } } catch (RecognitionException ex) { if (0 == inputState.guessing) { reportError(ex, "list_items"); recover(ex,tokenSet_129_); } else { throw ex; } } }
bool CheckParameterTypesStrictly(IMethod method, ExpressionCollection args) { IParameter[] parameters = method.GetParameters(); for (int i=0; i<args.Count; ++i) { IType expressionType = GetExpressionType(args[i]); IType parameterType = parameters[i].Type; if (!IsAssignableFrom(parameterType, expressionType) && !(TypeSystemServices.IsNumber(expressionType) && TypeSystemServices.IsNumber(parameterType)) && TypeSystemServices.FindImplicitConversionOperator(expressionType,parameterType) == null) { return false; } } return true; }
protected void expression_list( ExpressionCollection ec ) //throws RecognitionException, TokenStreamException { Expression e = null; try { // for error handling { switch ( LA(1) ) { case ESEPARATOR: case CAST: case CHAR: case FALSE: case NOT: case NULL: case SELF: case SUPER: case THEN: case TRUE: case TYPEOF: case TRIPLE_QUOTED_STRING: case LPAREN: case DOUBLE_QUOTED_STRING: case SINGLE_QUOTED_STRING: case ID: case MULTIPLY: case LBRACK: case SPLICE_BEGIN: case DOT: case LBRACE: case QQ_BEGIN: case SUBTRACT: case LONG: case INCREMENT: case DECREMENT: case ONES_COMPLEMENT: case INT: case BACKTICK_QUOTED_STRING: case RE_LITERAL: case DOUBLE: case FLOAT: case TIMESPAN: { e=expression(); if (0==inputState.guessing) { ec.Add(e); } { // ( ... )* for (;;) { if ((LA(1)==COMMA)) { match(COMMA); e=expression(); if (0==inputState.guessing) { if (e != null) ec.Add(e); } } else { goto _loop653_breakloop; } } _loop653_breakloop: ; } // ( ... )* break; } case EOL: case IF: case UNLESS: case WHILE: case EOS: case RPAREN: case COLON: case RBRACE: case QQ_END: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } } catch (RecognitionException ex) { if (0 == inputState.guessing) { reportError(ex, "expression_list"); recover(ex,tokenSet_29_); } else { throw ex; } } }
IMethod FindOperator(IType type, string operatorName, ExpressionCollection args) { IEntity entity = NameResolutionService.Resolve(type, operatorName, EntityType.Method); if (entity != null) { IMethod method = ResolveOperatorEntity(entity, args); if (null != method) return method; } entity = NameResolutionService.ResolveExtension(type, operatorName); if (entity != null) return ResolveOperatorEntity(entity, args); return null; }
protected bool CheckExactArgsParameters(ICallableType method, ExpressionCollection args, bool reportErrors) { if (method.GetSignature().Parameters.Length != args.Count) return false; return AssertParameterTypes(method, args, args.Count, reportErrors); }
IConstructor GetCorrectConstructor(Node sourceNode, IType type, ExpressionCollection arguments) { IConstructor[] constructors = type.GetConstructors().ToArray(); if (constructors.Length > 0) return (IConstructor)GetCorrectCallableReference(sourceNode, arguments, constructors); if (!IsError(type)) { if (type is IGenericParameter) Error(CompilerErrorFactory.CannotCreateAnInstanceOfGenericParameterWithoutDefaultConstructorConstraint(sourceNode, type)); else Error(CompilerErrorFactory.NoApropriateConstructorFound(sourceNode, type, GetSignature(arguments))); } return null; }
protected virtual bool CheckParameters(ICallableType method, ExpressionCollection args, bool reportErrors) { BindNullableParameters(args, method); return AcceptVarArgs(method) ? CheckVarArgsParameters(method, args) : CheckExactArgsParameters(method, args, reportErrors); }
private TypeReference GetMostGenericTypeReference(ExpressionCollection expressions) { var type = MapNullToObject(GetMostGenericType(expressions)); return CodeBuilder.CreateTypeReference(type); }
protected bool CheckVarArgsParameters(ICallableType method, ExpressionCollection args) { return CallableResolutionService.IsValidVargsInvocation(method.GetSignature().Parameters, args); }
private IEntity ResolveAmbiguousLValue(Expression sourceNode, Ambiguous candidates, Expression rvalue) { if (!candidates.AllEntitiesAre(EntityType.Property)) return null; IEntity[] entities = candidates.Entities; IEntity[] getters = GetSetMethods(entities); ExpressionCollection args = new ExpressionCollection(); args.Add(rvalue); IEntity found = GetCorrectCallableReference(sourceNode, args, getters); if (null != found && EntityType.Method == found.EntityType) { IProperty property = (IProperty)entities[GetIndex(getters, found)]; BindProperty(sourceNode, property); return property; } return null; }
bool AssertParameters(Node sourceNode, IMethod method, ExpressionCollection args) { return AssertParameters(sourceNode, method, method.CallableType, args); }
IMethod ResolveAmbiguousOperator(IEntity[] entities, ExpressionCollection args) { foreach (IEntity entity in entities) { IMethod method = entity as IMethod; if (null != method) { if (HasOperatorSignature(method, args)) { return method; } } } return null; }
bool AssertParameters(Node sourceNode, IEntity sourceEntity, ICallableType method, ExpressionCollection args) { if (CheckParameters(method, args, true)) return true; if (IsLikelyMacroExtensionMethodInvocation(sourceEntity)) Error(CompilerErrorFactory.MacroExpansionError(sourceNode)); else Error(CompilerErrorFactory.MethodSignature(sourceNode, sourceEntity, GetSignature(args))); return false; }
private IMethod ResolveOperatorEntity(IEntity op, ExpressionCollection args) { if (EntityType.Ambiguous == op.EntityType) return ResolveAmbiguousOperator(((Ambiguous)op).Entities, args); if (EntityType.Method == op.EntityType) { IMethod candidate = (IMethod)op; if (HasOperatorSignature(candidate, args)) return candidate; } return null; }
bool AssertParameterTypes(ICallableType method, ExpressionCollection args, int count, bool reportErrors) { IParameter[] parameters = method.GetSignature().Parameters; for (int i=0; i<count; ++i) { IParameter param = parameters[i]; IType parameterType = param.Type; IType argumentType = GetExpressionType(args[i]); if (param.IsByRef) { if (!(args[i] is ReferenceExpression || args[i] is SlicingExpression || (args[i] is SelfLiteralExpression && argumentType.IsValueType))) { if (reportErrors) Error(CompilerErrorFactory.RefArgTakesLValue(args[i])); return false; } if (!CallableResolutionService.IsValidByRefArg(param, parameterType, argumentType, args[i])) { return false; } } else { if (!CanBeReachedFrom(args[i], parameterType, argumentType)) return false; } } return true; }
public ArrayLiteralExpression CreateObjectArray(ExpressionCollection items) { return CreateArray(TypeSystemServices.ObjectArrayType, items); }
void BindNullableParameters(ExpressionCollection args, ICallableType target) { if (null == target) return; IParameter[] parameters = target.GetSignature().Parameters; for (int i = 0; i < parameters.Length; ++i) { if (!TypeSystemServices.IsNullable(parameters[i].Type)) continue; if (TypeSystemServices.IsNullable(GetExpressionType(args[i]))) continue; //already nullable args.Replace(args[i], CreateNullableInstantiation(args[i], parameters[i].Type)); Visit(args[i]); } }