Beispiel #1
0
        public static TypeReferenceCollection FromArray(params Boo.Lang.Compiler.Ast.TypeReference[] items)
        {
            var collection = new TypeReferenceCollection();

            collection.AddRange(items);
            return(collection);
        }
Beispiel #2
0
 public GenericConstructionChecker(TypeSystemServices tss, Node constructionNode, TypeReferenceCollection argumentNodes, CompilerErrorCollection errorCollection)
 {
     _tss = tss;
     _constructionNode = constructionNode;
     _argumentNodes = argumentNodes;
     _errors = errorCollection;
 }
 void ConvertTypeReferences(List <TypeReference> input, B.TypeReferenceCollection output)
 {
     foreach (TypeReference t in input)
     {
         B.TypeReference r = ConvertTypeReference(t);
         if (r != null)
         {
             output.Add(r);
         }
     }
 }
Beispiel #4
0
	protected void type_reference_list(
		TypeReferenceCollection container
	) //throws RecognitionException, TokenStreamException
{
		
		
				TypeReference tr = null;
			
		
		try {      // for error handling
			tr=type_reference();
			if (0==inputState.guessing)
			{
				container.Add(tr);
			}
			{    // ( ... )*
				for (;;)
				{
					if ((LA(1)==COMMA))
					{
						match(COMMA);
						tr=type_reference();
						if (0==inputState.guessing)
						{
							container.Add(tr);
						}
					}
					else
					{
						goto _loop246_breakloop;
					}
					
				}
_loop246_breakloop:				;
			}    // ( ... )*
		}
		catch (RecognitionException ex)
		{
			if (0 == inputState.guessing)
			{
				reportError(ex, "type_reference_list");
				recover(ex,tokenSet_41_);
			}
			else
			{
				throw ex;
			}
		}
	}
Beispiel #5
0
	protected void base_types(
		TypeReferenceCollection container
	) //throws RecognitionException, TokenStreamException
{
		
		
				TypeReference tr = null;
			
		
		try {      // for error handling
			match(LPAREN);
			{
				switch ( LA(1) )
				{
				case CALLABLE:
				case CHAR:
				case THEN:
				case LPAREN:
				case ID:
				case SPLICE_BEGIN:
				{
					tr=type_reference();
					if (0==inputState.guessing)
					{
						container.Add(tr);
					}
					{    // ( ... )*
						for (;;)
						{
							if ((LA(1)==COMMA))
							{
								match(COMMA);
								tr=type_reference();
								if (0==inputState.guessing)
								{
									container.Add(tr);
								}
							}
							else
							{
								goto _loop94_breakloop;
							}
							
						}
_loop94_breakloop:						;
					}    // ( ... )*
					break;
				}
				case RPAREN:
				{
					break;
				}
				default:
				{
					throw new NoViableAltException(LT(1), getFilename());
				}
				 }
			}
			match(RPAREN);
		}
		catch (RecognitionException ex)
		{
			if (0 == inputState.guessing)
			{
				reportError(ex, "base_types");
				recover(ex,tokenSet_54_);
			}
			else
			{
				throw ex;
			}
		}
	}
Beispiel #6
0
 public static IReturnType CreateReturnType(AST.TypeReference reference, IClass callingClass,
                                            IMethodOrProperty callingMember, int caretLine, int caretColumn,
                                            IProjectContent projectContent)
 {
     System.Diagnostics.Debug.Assert(projectContent != null);
     if (reference == null)
     {
         return(GetDefaultReturnType(projectContent));
     }
     if (reference is AST.ArrayTypeReference)
     {
         AST.ArrayTypeReference arr = (AST.ArrayTypeReference)reference;
         return(new ArrayReturnType(projectContent,
                                    CreateReturnType(arr.ElementType, callingClass, callingMember,
                                                     caretLine, caretColumn, projectContent),
                                    (arr.Rank != null) ? (int)arr.Rank.Value : 1));
     }
     else if (reference is AST.SimpleTypeReference)
     {
         string      name = ((AST.SimpleTypeReference)reference).Name;
         IReturnType rt;
         int         typeParameterCount = (reference is AST.GenericTypeReference) ? ((AST.GenericTypeReference)reference).GenericArguments.Count : 0;
         if (name == "duck")
         {
             rt = new BooResolver.DuckClass(new DefaultCompilationUnit(projectContent)).DefaultReturnType;
         }
         else if (BooAmbience.ReverseTypeConversionTable.ContainsKey(name))
         {
             rt = new GetClassReturnType(projectContent, BooAmbience.ReverseTypeConversionTable[name], typeParameterCount);
         }
         else if (callingClass == null)
         {
             rt = new GetClassReturnType(projectContent, name, typeParameterCount);
         }
         else
         {
             rt = new SearchClassReturnType(projectContent, callingClass, caretLine, caretColumn,
                                            name, typeParameterCount);
         }
         if (typeParameterCount > 0)
         {
             AST.TypeReferenceCollection arguments = ((AST.GenericTypeReference)reference).GenericArguments;
             // GenericTypeReference derives from SimpleTypeReference
             IReturnType[] typeArguments = new IReturnType[arguments.Count];
             for (int i = 0; i < typeArguments.Length; i++)
             {
                 typeArguments[i] = CreateReturnType(arguments[i], callingClass, callingMember, caretLine, caretColumn,
                                                     projectContent);
             }
             rt = new ConstructedReturnType(rt, typeArguments);
         }
         return(rt);
     }
     else if (reference is AST.CallableTypeReference)
     {
         AST.CallableTypeReference ctr  = (AST.CallableTypeReference)reference;
         AnonymousMethodReturnType amrt = new AnonymousMethodReturnType(new DefaultCompilationUnit(projectContent));
         if (ctr.ReturnType != null)
         {
             amrt.MethodReturnType = CreateReturnType(ctr.ReturnType, callingClass, callingMember, caretLine, caretColumn, projectContent);
         }
         amrt.MethodParameters = new List <IParameter>();
         AddParameters(ctr.Parameters, amrt.MethodParameters, callingMember, callingClass ?? new DefaultClass(new DefaultCompilationUnit(projectContent), "__Dummy"));
         return(amrt);
     }
     else
     {
         throw new NotSupportedException("unknown reference type: " + reference.ToString());
     }
 }
Beispiel #7
0
        /// <summary>
        /// Constructs generic entities out of an ambiguous definition.
        /// </summary>
        private IEntity ConstructAmbiguousEntity(Ambiguous ambiguousDefinition, Node constructionNode, TypeReferenceCollection argumentNodes)
        {
            GenericConstructionChecker checker = new GenericConstructionChecker(
                TypeSystemServices,
                constructionNode,
                argumentNodes,
                new CompilerErrorCollection());

            List<IEntity> matches = new List<IEntity>(ambiguousDefinition.Entities);

            // Filter matches by genericness, generity and constraints
            Predicate<IEntity>[] filters = new Predicate<IEntity>[] {
                checker.NotGenericDefinition,
                checker.IncorrectGenerity,
                checker.ViolatesParameterConstraints };

            foreach (Predicate<IEntity> filter in filters)
            {
                checker.Errors.Clear();
                matches.RemoveAll(filter);

                // If no matches pass the filter, record the first error only
                // (providing all the distinct errors that occured would be superfluous)
                if (matches.Count == 0)
                {
                    Errors.Add(checker.Errors[0]);
                    return TypeSystemServices.ErrorEntity;
                }

                // If only one match passes the filter, continue construction normally
                if (matches.Count == 1)
                {
                    return ConstructEntity(matches[0], constructionNode, argumentNodes);
                }
            }

            // Several matches have passed the filter -
            // construct all of them and return another Ambiguous entity
            IEntity[] constructed = Array.ConvertAll<IEntity, IEntity>(
                matches.ToArray(),
                delegate(IEntity def) { return ConstructEntity(def, constructionNode, argumentNodes); });

            return new Ambiguous(constructed);
        }
Beispiel #8
0
        /// <summary>
        /// Checks whether a given set of arguments can be used to construct a generic type or method from a specified definition.
        /// </summary>
        public bool CheckGenericConstruction(IEntity definition, Node node, TypeReferenceCollection arguments, CompilerErrorCollection errors)
        {
            // Ensure definition is a valid entity
            if (definition == null || TypeSystemServices.IsError(definition))
            {
                return false;
            }

            // Ensure definition really is a generic definition
            GenericConstructionChecker checker = new GenericConstructionChecker(
                TypeSystemServices, node, arguments, Errors);

            return !(
                checker.NotGenericDefinition(definition) ||
                checker.IncorrectGenerity(definition) ||
                checker.ViolatesParameterConstraints(definition));
        }
Beispiel #9
0
        /// <summary>
        /// Constructs an entity from a generic definition and arguments, after ensuring the construction is valid.
        /// </summary>
        /// <param name="definition">The generic definition entity.</param>
        /// <param name="node">The node in which construction occurs.</param>
        /// <param name="argumentNodes">The nodes of the arguments supplied for generic construction.</param>
        /// <returns>The constructed entity.</returns>
        public IEntity ConstructEntity(IEntity definition, Node constructionNode, TypeReferenceCollection argumentNodes)
        {
            // Ambiguous generic constructions are handled separately
            if (definition.EntityType == EntityType.Ambiguous)
            {
                return ConstructAmbiguousEntity((Ambiguous)definition, constructionNode, argumentNodes);
            }

            // Check that the construction is valid
            if (!CheckGenericConstruction(definition, constructionNode, argumentNodes, Errors))
            {
                return TypeSystemServices.ErrorEntity;
            }

            // Construct a type or a method according to the definition
            IType[] arguments = Array.ConvertAll<TypeReference, IType>(
                argumentNodes.ToArray(),
                delegate(TypeReference tr) { return (IType)tr.Entity; });

            if (IsGenericType(definition))
            {
                return ((IType)definition).GenericInfo.ConstructType(arguments);
            }
            if (IsGenericMethod(definition))
            {
                return ((IMethod)definition).GenericInfo.ConstructMethod(arguments);
            }

            // Should never be reached - if definition is neither a generic type nor a generic method,
            // CheckGenericConstruction would've indicated this
            return TypeSystemServices.ErrorEntity;
        }
Beispiel #10
0
 void WriteGenericArguments(TypeReferenceCollection arguments)
 {
     Write("[of ");
     WriteCommaSeparatedList(arguments);
     Write("]");
 }
Beispiel #11
0
 public Boo.Lang.Compiler.Ast.TypeReferenceCollection PopRange(int begin)
 {
     Boo.Lang.Compiler.Ast.TypeReferenceCollection range = new Boo.Lang.Compiler.Ast.TypeReferenceCollection(_parent);
     range.InnerList.Extend(InternalPopRange(begin));
     return(range);
 }
 public void type_reference_list(TypeReferenceCollection typeReferences)
 {
     try
     {
         TypeReference reference = this.type_reference();
         if (base.inputState.guessing == 0)
         {
             typeReferences.Add(reference);
         }
         while (this.LA(1) == 0x43)
         {
             this.match(0x43);
             reference = this.type_reference();
             if (base.inputState.guessing == 0)
             {
                 typeReferences.Add(reference);
             }
         }
     }
     catch (RecognitionException exception)
     {
         if (base.inputState.guessing != 0)
         {
             throw;
         }
         this.reportError(exception);
         this.recover(exception, tokenSet_36_);
     }
 }
 private void ResolveTypeReferenceCollection(TypeReferenceCollection collection)
 {
     foreach (TypeReference tr in collection)
     {
         ResolveTypeReference(tr);
     }
 }
Beispiel #14
0
 private IType[] GetTypes(TypeReferenceCollection typeReferences)
 {
     return Array.ConvertAll<TypeReference, IType>(
         typeReferences.ToArray(),
         TypeSystemServices.GetType);
 }