public ArrayType(TypeSystemServices tagManager, IType elementType, int rank) { _array = tagManager.ArrayType; _elementType = elementType; _rank = rank; _enumerable = tagManager.IEnumerableGenericType; }
internal AnonymousCallableType(TypeSystemServices services, CallableSignature signature) { if (null == services) throw new ArgumentNullException("services"); if (null == signature) throw new ArgumentNullException("signature"); _typeSystemServices = services; _signature = signature; }
Assembly GetBoundAssembly(ReferenceExpression reference) { return(((AssemblyReference)TypeSystemServices.GetEntity(reference)).Assembly); }
void RegisterAdaptor(ICallableType to, ICallableType from, ClassDefinition adaptor) { _adaptors.Add(new AdaptorRecord(to, from, adaptor)); TypeSystemServices.GetCompilerGeneratedTypesModule().Members.Add(adaptor); }
public AnonymousCallablesManager(TypeSystemServices tss) { _tss = tss; }
public InternalGenericParameter(TypeSystemServices tss, GenericParameterDeclaration declaration) : base(tss) { _declaration = declaration; }
override public void LeaveForStatement(ForStatement node) { IType enumeratorType = GetExpressionType(node.Iterator); IType enumeratorItemType = TypeSystemServices.GetEnumeratorItemType(enumeratorType); DeclarationCollection declarations = node.Declarations; Block body = new Block(node.LexicalInfo); InternalLocal iterator = CodeBuilder.DeclareLocal( _current, "___iterator" + _context.AllocIndex(), TypeSystemServices.IEnumeratorType); if (TypeSystemServices.IEnumeratorType.IsAssignableFrom(enumeratorType)) { body.Add( CodeBuilder.CreateAssignment( CodeBuilder.CreateReference(iterator), node.Iterator)); } else { // ___iterator = <node.Iterator>.GetEnumerator() body.Add( CodeBuilder.CreateAssignment( CodeBuilder.CreateReference(iterator), CodeBuilder.CreateMethodInvocation( node.Iterator, IEnumerable_GetEnumerator))); } // while __iterator.MoveNext(): WhileStatement ws = new WhileStatement(node.LexicalInfo); ws.Condition = CodeBuilder.CreateMethodInvocation( CodeBuilder.CreateReference(iterator), IEnumerator_MoveNext); Expression current = CodeBuilder.CreateMethodInvocation( CodeBuilder.CreateReference(iterator), IEnumerator_get_Current); if (1 == declarations.Count) { // item = __iterator.Current ws.Block.Add( CodeBuilder.CreateAssignment( CodeBuilder.CreateReference((InternalLocal)declarations[0].Entity), current)); } else { UnpackExpression(ws.Block, CodeBuilder.CreateCast( enumeratorItemType, current), node.Declarations); } ws.Block.Add(node.Block); body.Add(ws); ReplaceCurrentNode(body); }
public ArrayType(TypeSystemServices tagManager, IType elementType) : this(tagManager, elementType, 1) { }
IMethod Map(MethodInfo method) { return(TypeSystemServices.Map(method)); }
public InternalGenericParameter(TypeSystemServices tss, GenericParameterDeclaration declaration, int position) : this(tss, declaration) { _position = position; }
public bool IsVoid(Expression e) => RuntimeServices.EqualityOperator(TypeSystemServices.GetExpressionType(e), this.TypeSystemServices.VoidType);
bool CheckInheritedMethodImpl(IMethod impl, IMethod baseMethod) { return(TypeSystemServices.CheckOverrideSignature(impl, baseMethod)); }
private IType Map(Type actualType) { return(TypeSystemServices.Map(actualType)); }
private static bool IsUnknown(IType type) { return(TypeSystemServices.IsUnknown(type)); }
public static IType TypeOfFirstArgument(MethodInvocationExpression invocation, IMethod method) { return(TypeSystemServices.GetExpressionType(invocation.Arguments[0])); }
void ResolveAbstractMethod(ClassDefinition node, TypeReference baseTypeRef, IMethod entity) { if (entity.IsSpecialName) { return; } foreach (TypeMember member in node.Members) { if (entity.Name == member.Name && NodeType.Method == member.NodeType && IsCorrectExplicitMemberImplOrNoExplicitMemberAtAll(member, entity)) { Method method = (Method)member; if (TypeSystemServices.CheckOverrideSignature(GetEntity(method), entity)) { if (IsUnknown(method.ReturnType)) { method.ReturnType = CodeBuilder.CreateTypeReference(entity.ReturnType); } else { if (entity.ReturnType != method.ReturnType.Entity) { Error(CompilerErrorFactory.ConflictWithInheritedMember(method, method.FullName, entity.FullName)); } } if (null != method.ExplicitInfo) { method.ExplicitInfo.Entity = entity; } if (!method.IsOverride && !method.IsVirtual) { method.Modifiers |= TypeMemberModifiers.Virtual; } _context.TraceInfo("{0}: Method {1} implements {2}", method.LexicalInfo, method, entity); return; } } } foreach (SimpleTypeReference parent in node.BaseTypes) { if (_classDefinitionList.Contains(parent.Name)) { depth++; ResolveAbstractMethod(_classDefinitionList[parent.Name] as ClassDefinition, baseTypeRef, entity); depth--; } } if (CheckInheritsInterfaceImplementation(node, entity)) { return; } if (depth == 0) { if (!AbstractMemberNotImplemented(node, baseTypeRef, entity)) { //BEHAVIOR < 0.7.7: no stub, mark class as abstract node.Members.Add(CodeBuilder.CreateAbstractMethod(baseTypeRef.LexicalInfo, entity)); } } }
protected override void ResolveImpl(MappedToken token) { switch (Node.NodeType) { case NodeType.SelfLiteralExpression: var classDefinition = Node; while (classDefinition.ParentNode != null) { if (classDefinition.NodeType != NodeType.ClassDefinition) { classDefinition = classDefinition.ParentNode; } else { varType = TypeSystemServices.GetType(classDefinition); break; } } break; case NodeType.MemberReferenceExpression: case NodeType.ReferenceExpression: var expression = (ReferenceExpression)Node; IEntity entity; try { entity = TypeSystemServices.GetEntity(expression); } catch { break; } var prefix = ""; if (entity is InternalParameter) { prefix = "(parameter) "; varType = TypeSystemServices.GetType(expression); declarationNode = CompileResults.GetMappedNode(((InternalParameter)entity).Parameter); } if (entity is InternalLocal) { prefix = "(local variable) "; varType = ((InternalLocal)entity).Type; declarationNode = CompileResults.GetMappedNode(((InternalLocal)entity).Local); } if (entity is InternalField) { varType = TypeSystemServices.GetType(Node); declaringType = ((InternalField)entity).DeclaringType; declarationNode = CompileResults.GetMappedNode(((InternalField)entity).Field); } if (entity is InternalMethod) { declaringType = ((InternalMethod)entity).DeclaringType; declarationNode = CompileResults.GetMappedNode(((InternalMethod)entity).Method); if (entity is InternalConstructor) { varType = ((InternalConstructor)entity).DeclaringType; } else { varType = ((InternalMethod)entity).ReturnType; } } if (entity is InternalProperty) { declaringType = ((InternalProperty)entity).DeclaringType; varType = TypeSystemServices.GetType(Node); declarationNode = CompileResults.GetMappedNode(((InternalProperty)entity).Property); } if (entity is InternalEvent) { declaringType = ((InternalEvent)entity).DeclaringType; varType = TypeSystemServices.GetType(Node); declarationNode = CompileResults.GetMappedNode(((InternalEvent)entity).Event); } if (entity is ExternalType) { varType = ((ExternalType)entity).Type; format = Formats.BooType; isTypeReference = true; } if (entity is AbstractInternalType) { varType = ((AbstractInternalType)entity).Type; format = Formats.BooType; isTypeReference = true; declarationNode = CompileResults.GetMappedNode(((AbstractInternalType)entity).TypeDefinition); } if (entity is ExternalField) { varType = TypeSystemServices.GetType(Node); declaringType = ((ExternalField)entity).DeclaringType; // declarationNode = CompileResults.GetMappedNode(((ExternalField)entity).Field); } if (entity is ExternalMethod) { declaringType = ((ExternalMethod)entity).DeclaringType; // declarationNode = CompileResults.GetMappedNode(declaration); if (entity is ExternalConstructor) { varType = ((ExternalConstructor)entity).DeclaringType; } else { varType = ((ExternalMethod)entity).ReturnType; } } if (entity is ExternalProperty) { declaringType = ((ExternalProperty)entity).DeclaringType; varType = TypeSystemServices.GetType(Node); // declarationNode = CompileResults.GetMappedNode(((ExternalProperty)entity).Property); } if (entity is ExternalEvent) { declaringType = ((ExternalEvent)entity).DeclaringType; varType = TypeSystemServices.GetType(Node); // declarationNode = CompileResults.GetMappedNode(((ExternalEvent)entity).Event); } if (expression.ExpressionType != null) { if (declaringType != null) { prefix += declaringType.FullName + '.'; } quickInfoTip = prefix + expression.Name + " as " + expression.ExpressionType.FullName; } break; default: break; } }
protected AbstractGenericParameter(TypeSystemServices tss) { _tss = tss; }
public ExternalProperty(TypeSystemServices tagManager, System.Reflection.PropertyInfo property) { _typeSystemServices = tagManager; _property = property; }
/// <summary> /// Optimize the <c>for item in range()</c> construct /// </summary> /// <param name="node">the for statement to check</param> private void CheckForItemInRangeLoop(ForStatement node) { MethodInvocationExpression mi = node.Iterator as MethodInvocationExpression; if (null == mi) { return; } if (!IsRangeInvocation(mi)) { return; } DeclarationCollection declarations = node.Declarations; if (declarations.Count != 1) { return; } ExpressionCollection args = mi.Arguments; Block body = new Block(node.LexicalInfo); Expression min; Expression max; Expression step; if (args.Count == 1) { min = CodeBuilder.CreateIntegerLiteral(0); max = args[0]; step = CodeBuilder.CreateIntegerLiteral(1); } else if (args.Count == 2) { min = args[0]; max = args[1]; step = CodeBuilder.CreateIntegerLiteral(1); } else { min = args[0]; max = args[1]; step = args[2]; } InternalLocal numVar = CodeBuilder.DeclareTempLocal( _currentMethod, TypeSystemServices.IntType); Expression numRef = CodeBuilder.CreateReference(numVar); // __num = <min> body.Add( CodeBuilder.CreateAssignment( numRef, min)); Expression endRef; if (max.NodeType == NodeType.IntegerLiteralExpression) { endRef = max; } else { InternalLocal endVar = CodeBuilder.DeclareTempLocal( _currentMethod, TypeSystemServices.IntType); endRef = CodeBuilder.CreateReference(endVar); // __end = <end> body.Add( CodeBuilder.CreateAssignment( endRef, max)); } if (args.Count == 1) { if (max.NodeType == NodeType.IntegerLiteralExpression) { if (((IntegerLiteralExpression)max).Value < 0) { // raise ArgumentOutOfRangeException("max") (if <max> < 0) Statement statement = CodeBuilder.RaiseException( body.LexicalInfo, TypeSystemServices.Map(System_ArgumentOutOfRangeException_ctor), CodeBuilder.CreateStringLiteral("max")); body.Add(statement); } } else { IfStatement ifStatement = new IfStatement(body.LexicalInfo); ifStatement.TrueBlock = new Block(); // raise ArgumentOutOfRangeException("max") if __end < 0 Statement statement = CodeBuilder.RaiseException( body.LexicalInfo, TypeSystemServices.Map(System_ArgumentOutOfRangeException_ctor), CodeBuilder.CreateStringLiteral("max")); ifStatement.Condition = CodeBuilder.CreateBoundBinaryExpression( TypeSystemServices.BoolType, BinaryOperatorType.LessThan, endRef, CodeBuilder.CreateIntegerLiteral(0)); ifStatement.TrueBlock.Add(statement); body.Add(ifStatement); } } Expression stepRef; switch (args.Count) { case 1: stepRef = CodeBuilder.CreateIntegerLiteral(1); break; case 2: if ((min.NodeType == NodeType.IntegerLiteralExpression) && (max.NodeType == NodeType.IntegerLiteralExpression) && (((IntegerLiteralExpression)max).Value < ((IntegerLiteralExpression)min).Value)) { // __step = -1 stepRef = CodeBuilder.CreateIntegerLiteral(-1); } else if ((min.NodeType == NodeType.IntegerLiteralExpression) && (max.NodeType == NodeType.IntegerLiteralExpression)) { // __step = 1 stepRef = CodeBuilder.CreateIntegerLiteral(1); } else { InternalLocal stepVar = CodeBuilder.DeclareTempLocal( _currentMethod, TypeSystemServices.IntType); stepRef = CodeBuilder.CreateReference(stepVar); // __step = 1 body.Add( CodeBuilder.CreateAssignment( stepRef, CodeBuilder.CreateIntegerLiteral(1))); // __step = -1 if __end < __num IfStatement ifStatement = new IfStatement(node.LexicalInfo); ifStatement.Condition = CodeBuilder.CreateBoundBinaryExpression( TypeSystemServices.BoolType, BinaryOperatorType.LessThan, endRef, numRef); ifStatement.TrueBlock = new Block(); ifStatement.TrueBlock.Add( CodeBuilder.CreateAssignment( stepRef, CodeBuilder.CreateIntegerLiteral(-1))); body.Add(ifStatement); } break; default: if (step.NodeType == NodeType.IntegerLiteralExpression) { stepRef = step; } else { InternalLocal stepVar = CodeBuilder.DeclareTempLocal( _currentMethod, TypeSystemServices.IntType); stepRef = CodeBuilder.CreateReference(stepVar); // __step = <step> body.Add( CodeBuilder.CreateAssignment( stepRef, step)); } break; } if (args.Count == 3) { Expression condition = null; bool run = false; if (step.NodeType == NodeType.IntegerLiteralExpression) { if (((IntegerLiteralExpression)step).Value < 0) { if ((max.NodeType == NodeType.IntegerLiteralExpression) && (min.NodeType == NodeType.IntegerLiteralExpression)) { run = (((IntegerLiteralExpression)max).Value > ((IntegerLiteralExpression)min).Value); } else { condition = CodeBuilder.CreateBoundBinaryExpression( TypeSystemServices.BoolType, BinaryOperatorType.GreaterThan, endRef, numRef); } } else { if ((max.NodeType == NodeType.IntegerLiteralExpression) && (min.NodeType == NodeType.IntegerLiteralExpression)) { run = (((IntegerLiteralExpression)max).Value < ((IntegerLiteralExpression)min).Value); } else { condition = CodeBuilder.CreateBoundBinaryExpression( TypeSystemServices.BoolType, BinaryOperatorType.LessThan, endRef, numRef); } } } else { if ((max.NodeType == NodeType.IntegerLiteralExpression) && (min.NodeType == NodeType.IntegerLiteralExpression)) { if (((IntegerLiteralExpression)max).Value < ((IntegerLiteralExpression)min).Value) { condition = CodeBuilder.CreateBoundBinaryExpression( TypeSystemServices.BoolType, BinaryOperatorType.GreaterThan, stepRef, CodeBuilder.CreateIntegerLiteral(0)); } else { condition = CodeBuilder.CreateBoundBinaryExpression( TypeSystemServices.BoolType, BinaryOperatorType.LessThan, stepRef, CodeBuilder.CreateIntegerLiteral(0)); } } else { condition = CodeBuilder.CreateBoundBinaryExpression( TypeSystemServices.BoolType, BinaryOperatorType.Or, CodeBuilder.CreateBoundBinaryExpression( TypeSystemServices.BoolType, BinaryOperatorType.And, CodeBuilder.CreateBoundBinaryExpression( TypeSystemServices.BoolType, BinaryOperatorType.LessThan, stepRef, CodeBuilder.CreateIntegerLiteral(0)), CodeBuilder.CreateBoundBinaryExpression( TypeSystemServices.BoolType, BinaryOperatorType.GreaterThan, endRef, numRef)), CodeBuilder.CreateBoundBinaryExpression( TypeSystemServices.BoolType, BinaryOperatorType.And, CodeBuilder.CreateBoundBinaryExpression( TypeSystemServices.BoolType, BinaryOperatorType.GreaterThan, stepRef, CodeBuilder.CreateIntegerLiteral(0)), CodeBuilder.CreateBoundBinaryExpression( TypeSystemServices.BoolType, BinaryOperatorType.LessThan, endRef, numRef))); } } // raise ArgumentOutOfRangeException("step") if (__step < 0 and __end > __begin) or (__step > 0 and __end < __begin) Statement statement = CodeBuilder.RaiseException( body.LexicalInfo, TypeSystemServices.Map(System_ArgumentOutOfRangeException_ctor), CodeBuilder.CreateStringLiteral("step")); if (condition != null) { IfStatement ifStatement = new IfStatement(body.LexicalInfo); ifStatement.TrueBlock = new Block(); ifStatement.Condition = condition; ifStatement.TrueBlock.Add(statement); body.Add(ifStatement); } else if (run) { body.Add(statement); } // __end = __num + __step * cast(int, Math.Ceiling((__end - __num)/cast(double, __step))) if ((step.NodeType == NodeType.IntegerLiteralExpression) && (max.NodeType == NodeType.IntegerLiteralExpression) && (min.NodeType == NodeType.IntegerLiteralExpression)) { int stepVal = (int)((IntegerLiteralExpression)step).Value; int maxVal = (int)((IntegerLiteralExpression)max).Value; int minVal = (int)((IntegerLiteralExpression)min).Value; endRef = CodeBuilder.CreateIntegerLiteral( minVal + stepVal * (int)System.Math.Ceiling((maxVal - minVal) / ((double)stepVal))); } else { Expression endBak = endRef; if (max.NodeType == NodeType.IntegerLiteralExpression) { InternalLocal endVar = CodeBuilder.DeclareTempLocal( _currentMethod, TypeSystemServices.IntType); endRef = CodeBuilder.CreateReference(endVar); } body.Add( CodeBuilder.CreateAssignment( endRef, CodeBuilder.CreateBoundBinaryExpression( TypeSystemServices.IntType, BinaryOperatorType.Addition, numRef, CodeBuilder.CreateBoundBinaryExpression( TypeSystemServices.IntType, BinaryOperatorType.Multiply, stepRef, CodeBuilder.CreateCast( TypeSystemServices.IntType, CodeBuilder.CreateMethodInvocation( TypeSystemServices.Map(System_Math_Ceiling), CodeBuilder.CreateBoundBinaryExpression( TypeSystemServices.DoubleType, BinaryOperatorType.Division, CodeBuilder.CreateBoundBinaryExpression( TypeSystemServices.IntType, BinaryOperatorType.Subtraction, endBak, numRef), CodeBuilder.CreateCast( TypeSystemServices.DoubleType, stepRef)))))))); } } // while __num != __end: WhileStatement ws = new WhileStatement(node.LexicalInfo); BinaryOperatorType op = BinaryOperatorType.Inequality; if (stepRef.NodeType == NodeType.IntegerLiteralExpression) { if (((IntegerLiteralExpression)stepRef).Value > 0) { op = BinaryOperatorType.LessThan; } else { op = BinaryOperatorType.GreaterThan; } } ws.Condition = CodeBuilder.CreateBoundBinaryExpression( TypeSystemServices.BoolType, op, numRef, endRef); ws.Condition.LexicalInfo = node.LexicalInfo; // item = __num ws.Block.Add( CodeBuilder.CreateAssignment( CodeBuilder.CreateReference((InternalLocal)declarations[0].Entity), numRef)); Block rawBlock = new Block(); rawBlock["checked"] = false; // __num += __step rawBlock.Add( CodeBuilder.CreateAssignment( numRef, CodeBuilder.CreateBoundBinaryExpression( TypeSystemServices.IntType, BinaryOperatorType.Addition, numRef, stepRef))); ws.Block.Add(rawBlock as Statement); // <block> ws.Block.Add(node.Block); body.Add(ws); ReplaceCurrentNode(body); }
public bool Matches(Node node) { return(_entity == TypeSystemServices.GetOptionalEntity(node)); }
public GenericMappedTypeParameter(TypeSystemServices tss, IGenericParameter source, GenericMapping mapping) : base(tss) { _source = source; _mapping = mapping; }
IMethod Map(System.Reflection.MethodInfo method) { return(TypeSystemServices.Map(method)); }
private bool IsDuckTyped(Expression e) { return(TypeSystemServices.IsDuckTyped(e)); }
public ExternalEvent(TypeSystemServices tagManager, System.Reflection.EventInfo event_) { _typeSystemServices = tagManager; _event = event_; }
public override void Initialize(CompilerContext context) { base.Initialize(context); _astAttributeInterface = TypeSystemServices.Map(typeof(IAstAttribute)); }
static ICompileUnit GetBoundReference(ReferenceExpression reference) { return((ICompileUnit)TypeSystemServices.GetEntity(reference)); }
bool IsSystemAttribute(IType type) { return(TypeSystemServices.IsAttribute(type)); }
private IType GeneratorItemTypeFrom(IType expectedType) { return(TypeSystemServices.IsGenericGeneratorReturnType(expectedType) ? expectedType.ConstructedInfo.GenericArguments[0] : null); }
bool IsDuckTyped(Expression expression) { IType type = expression.ExpressionType; return(null != type && TypeSystemServices.IsDuckType(type)); }
public static IType TypeReferencedBySecondArgument(MethodInvocationExpression invocation, IMethod method) { return(TypeSystemServices.GetReferencedType(invocation.Arguments[1])); }
protected virtual IType GetDuckTypingServicesType() { return(TypeSystemServices.Map(typeof(Boo.Lang.Runtime.RuntimeServices))); }
public virtual IType GeneratorItemTypeFor(InternalMethod generator) { return(TypeSystemServices.MapWildcardType(InferGeneratorItemTypeFor(generator))); }
internal AnonymousCallableType(TypeSystemServices services, CallableSignature signature) { _typeSystemServices = services; _signature = signature; }