Inheritance: Boo.Lang.Compiler.Ast.SimpleTypeReference
コード例 #1
0
 B.TypeReference ConvertTypeReference(TypeReference t)
 {
     if (t == null || t.IsNull)
     {
         return(null);
     }
     B.TypeReference r;
     if (t.GenericTypes.Count > 0)
     {
         r = new B.GenericTypeReference(GetLexicalInfo(t), GetIntrinsicTypeName(t.Type));
         foreach (TypeReference ta in t.GenericTypes)
         {
             ((B.GenericTypeReference)r).GenericArguments.Add(ConvertTypeReference(ta));
         }
     }
     else
     {
         r = new B.SimpleTypeReference(GetLexicalInfo(t), GetIntrinsicTypeName(t.Type));
     }
     if (t.IsArrayType)
     {
         for (int i = t.RankSpecifier.Length - 1; i >= 0; --i)
         {
             r = new B.ArrayTypeReference(GetLexicalInfo(t), r, new B.IntegerLiteralExpression(t.RankSpecifier[i] + 1));
         }
     }
     if (t.PointerNestingLevel != 0)
     {
         AddError(t, "Pointers are not supported by boo.");
     }
     return(r);
 }
コード例 #2
0
ファイル: TypeReference.cs プロジェクト: HaKDMoDz/GNet
		private static TypeReference LiftGenericTypeDefinition(TypeDefinition node)
		{
			var typeRef = new GenericTypeReference(node.LexicalInfo, node.QualifiedName);
			foreach (GenericParameterDeclaration parameter in node.GenericParameters)
				typeRef.GenericArguments.Add(Lift(parameter.Name));
			return typeRef;
		}
コード例 #3
0
        public static TypeReference Lift(GenericReferenceExpression e)
        {
            GenericTypeReference typeRef = new GenericTypeReference(e.LexicalInfo);

            typeRef.Name = TypeNameFor(e.Target);
            typeRef.GenericArguments.ExtendWithClones(e.GenericArguments);
            return(typeRef);
        }
コード例 #4
0
        private static TypeReference LiftGenericTypeDefinition(TypeDefinition node)
        {
            GenericTypeReference typeRef = new GenericTypeReference(node.LexicalInfo, node.QualifiedName);

            foreach (GenericParameterDeclaration parameter in node.GenericParameters)
            {
                typeRef.GenericArguments.Add(Lift(parameter.Name));
            }
            return(typeRef);
        }
コード例 #5
0
ファイル: TypeReference.cs プロジェクト: richardbang83/GNet
        private static TypeReference LiftGenericType(Type type)
        {
            var genericTypeRef = new GenericTypeReference {
                Name = FullNameOf(type)
            };

            foreach (var arg in type.GetGenericArguments())
            {
                genericTypeRef.GenericArguments.Add(Lift(arg));
            }
            return(genericTypeRef);
        }
コード例 #6
0
        override public object Clone()
        {
            GenericTypeReference clone = (GenericTypeReference)FormatterServices.GetUninitializedObject(typeof(GenericTypeReference));

            clone._lexicalInfo       = _lexicalInfo;
            clone._endSourceLocation = _endSourceLocation;
            clone._documentation     = _documentation;
            clone._entity            = _entity;
            if (_annotations != null)
            {
                clone._annotations = (Hashtable)_annotations.Clone();
            }

            clone._isPointer = _isPointer;
            clone._name      = _name;
            if (null != _genericArguments)
            {
                clone._genericArguments = _genericArguments.Clone() as TypeReferenceCollection;
                clone._genericArguments.InitializeParent(clone);
            }
            return(clone);
        }
コード例 #7
0
        override public object Clone()
        {
            GenericTypeReference clone = new GenericTypeReference();

            clone._lexicalInfo       = _lexicalInfo;
            clone._endSourceLocation = _endSourceLocation;
            clone._documentation     = _documentation;
            clone._isSynthetic       = _isSynthetic;
            clone._entity            = _entity;
            if (_annotations != null)
            {
                clone._annotations = (Hashtable)_annotations.Clone();
            }
            clone._isPointer = _isPointer;
            clone._name      = _name;
            if (null != _genericArguments)
            {
                clone._genericArguments = _genericArguments.Clone() as TypeReferenceCollection;
                clone._genericArguments.InitializeParent(clone);
            }
            return(clone);
        }
コード例 #8
0
ファイル: TypeDefinitionTest.cs プロジェクト: 0xb1dd1e/boo
		public void MergeIgnoresMatchingBaseTypes()
		{
			var foo = new SimpleTypeReference("Foo");
			var bar = new SimpleTypeReference("Bar");
			var fooOfBar = new GenericTypeReference("Foo", bar);
			var barOfFoo = new GenericTypeReference("Bar", foo);
			
			var subject = new ClassDefinition();
			subject.BaseTypes.Add(bar);
			subject.BaseTypes.Add(fooOfBar);

			var node = new ClassDefinition();
			node.BaseTypes.Add(foo);
			node.BaseTypes.Add(bar.CloneNode());
			node.BaseTypes.Add(fooOfBar.CloneNode());
			node.BaseTypes.Add(barOfFoo);

			subject.Merge(node);

			Assert.AreEqual(new[] { bar, fooOfBar, foo, barOfFoo }, subject.BaseTypes.ToArray());

		}
コード例 #9
0
 public override void OnGenericTypeReference(GenericTypeReference node)
 {
     if (node.LexicalInfo != null)
         results.MapParsedNode(new MappedTypeReference(results, node));
     base.OnGenericTypeReference(node);
 }
コード例 #10
0
 private static TypeReference GetTypeReference(Type type)
 {
     TypeReference typeReference;
     if (type.IsGenericType)
     {
         var genericArguments = type.GetGenericArguments();
         typeReference = new GenericTypeReference(
             TypeUtilities.GetFullName(type),
             genericArguments.Select(a => GetTypeReference(a)).ToArray());
     }
     else
     {
         typeReference = new SimpleTypeReference(TypeUtilities.GetFullName(type));
     }
     return typeReference;
 }
コード例 #11
0
 public override void OnGenericTypeReference(GenericTypeReference node)
 {
     NameResolutionService.ResolveSimpleTypeReference(node);
 }
コード例 #12
0
 public override void OnGenericTypeReference(GenericTypeReference node)
 {
     OnSimpleTypeReference(node);
     WriteGenericArguments(node.GenericArguments);
 }
コード例 #13
0
        public Expression Linqify(BlockExpression nodeToConvert, BlockExpression originalNode)
        {
            //assert on param
            //assert one expression statement
            if (nodeToConvert.Parameters.Count > 1)
            {
                throw new NotSupportedException("Only lambdas with zero or one parameter are supported");
            }
            if (nodeToConvert.Body.Statements.Count != 1 &&
                nodeToConvert.Body.FirstStatement as ExpressionStatement == null)
            {
                throw new NotSupportedException("A lambda expression with a statement body cannot be converted to an expression tree");
            }

            var closureReturnType = CodeBuilder.CreateTypeReference((originalNode.ExpressionType as ICallableType).GetSignature().ReturnType);
            var bodyReturnType = CodeBuilder.CreateTypeReference((originalNode.Body.FirstStatement as ReturnStatement).Expression.ExpressionType);
            var hasParameters = nodeToConvert.Parameters.Count == 1;
            if (hasParameters)
            {
                var closureParameter = originalNode.Parameters[0];

                var exprP1Init = new DeclarationStatement(new Declaration(nodeToConvert.LexicalInfo, CompilerContext.Current.GetUniqueName(closureParameter.Name)),
                    new MethodInvocationExpression(ReferenceExpression.Lift("System.Linq.Expressions.Expression.Parameter"),
                        new TypeofExpression() { Type = closureParameter.Type },
                        new StringLiteralExpression(closureParameter.Name)));
                var exprP1Ref = new ReferenceExpression(exprP1Init.Declaration.Name);

                var visitor = new GeneratorExpressionTrees(closureParameter.Name, exprP1Ref, NameResolutionService, CodeBuilder);
                visitor.Visit(nodeToConvert.Body);
                var constructedExpression = visitor.Expression;
                constructedExpression = AddOptionalConvert(closureReturnType, bodyReturnType, constructedExpression);
                var exprLambdaGenericArg = new GenericTypeReference("System.Func", closureParameter.Type, closureReturnType);
                var exprLambdaCall = new GenericReferenceExpression()
                {
                    Target = ReferenceExpression.Lift("System.Linq.Expressions.Expression.Lambda"),
                    GenericArguments = { exprLambdaGenericArg }
                };
                var resultExpr = new MethodInvocationExpression(exprLambdaCall,
                    constructedExpression,
                    exprP1Ref);

                var linqify = new BlockExpression();
                var returnType = new GenericTypeReference("System.Linq.Expressions.Expression", exprLambdaGenericArg);
                NameResolutionService.ResolveSimpleTypeReference(returnType);
                //this must be set to allow proper type inference
                originalNode.ExpressionType = returnType.Entity as IType;

                linqify.ReturnType = returnType;
                linqify.Body.Add(exprP1Init);
                linqify.Body.Add(new ReturnStatement(resultExpr));
                return new MethodInvocationExpression(linqify);
            }
            else
            {
                var visitor = new GeneratorExpressionTrees(null, null, NameResolutionService, CodeBuilder);
                visitor.Visit(nodeToConvert.Body);
                var constructedExpression = visitor.Expression;
                constructedExpression = AddOptionalConvert(closureReturnType, bodyReturnType, constructedExpression);
                var exprLambdaGenericArg = new GenericTypeReference("System.Func", closureReturnType);
                var exprLambdaCall = new GenericReferenceExpression()
                {
                    Target = ReferenceExpression.Lift("System.Linq.Expressions.Expression.Lambda"),
                    GenericArguments = { exprLambdaGenericArg }
                };
                var resultExpr = new MethodInvocationExpression(exprLambdaCall,
                    constructedExpression);

                var linqify = new BlockExpression();
                var returnType = new GenericTypeReference("System.Linq.Expressions.Expression", exprLambdaGenericArg);
                NameResolutionService.ResolveSimpleTypeReference(returnType);
                //this must be set to allow proper type inference
                originalNode.ExpressionType = returnType.Entity as IType;

                linqify.ReturnType = returnType;
                linqify.Body.Add(new ReturnStatement(resultExpr));
                return new MethodInvocationExpression(linqify);
            }
        }
コード例 #14
0
ファイル: CodeFactory.cs プロジェクト: 0xb1dd1e/boo
		public static TypeReference EnumerableTypeReferenceFor(TypeReference tr)
		{
			var result = new GenericTypeReference(tr.LexicalInfo, "System.Collections.Generic.IEnumerable");
			result.GenericArguments.Add(tr);
			return result;
		}
コード例 #15
0
ファイル: TypeReference.cs プロジェクト: HaKDMoDz/GNet
		private static TypeReference LiftGenericType(Type type)
		{
			var genericTypeRef = new GenericTypeReference { Name = FullNameOf(type) };
			foreach (var arg in type.GetGenericArguments())
				genericTypeRef.GenericArguments.Add(Lift(arg));
			return genericTypeRef;
		}
コード例 #16
0
 public TypeReference simple_type_reference()
 {
     TypeReference reference = null;
     try
     {
         Token token = this.qname();
         if ((this.LA(1) == 0x41) && (this.LA(2) == 0x5b))
         {
             TypeReferenceCollection references;
             this.match(0x41);
             this.match(0x5b);
             if (base.inputState.guessing == 0)
             {
                 GenericTypeReference reference2;
                 reference = reference2 = new GenericTypeReference(ToLexicalInfo(token), token.getText());
                 references = reference2.get_GenericArguments();
             }
             this.type_reference_list(references);
             this.match(0x5f);
             return reference;
         }
         if (!tokenSet_35_.member(this.LA(1)) || !tokenSet_25_.member(this.LA(2)))
         {
             throw new NoViableAltException(this.LT(1), this.getFilename());
         }
         if (base.inputState.guessing == 0)
         {
             SimpleTypeReference reference3;
             SimpleTypeReference reference1 = reference3 = new SimpleTypeReference(ToLexicalInfo(token));
             reference3.set_Name(token.getText());
             reference = reference3;
         }
         return reference;
     }
     catch (RecognitionException exception)
     {
         if (base.inputState.guessing != 0)
         {
             throw;
         }
         this.reportError(exception);
         this.recover(exception, tokenSet_35_);
         return reference;
     }
     return reference;
 }
コード例 #17
0
ファイル: BooParserBase.cs プロジェクト: hlizard/boo
	protected TypeReference  type_reference() //throws RecognitionException, TokenStreamException
{
		TypeReference tr;
		
		
				tr = null;
				IToken id = null;
				TypeReferenceCollection arguments = null;
				GenericTypeDefinitionReference gtdr = null;
			
		
		try {      // for error handling
			{
				switch ( LA(1) )
				{
				case SPLICE_BEGIN:
				{
					tr=splice_type_reference();
					break;
				}
				case LPAREN:
				{
					tr=array_type_reference();
					break;
				}
				default:
					bool synPredMatched251 = false;
					if (((LA(1)==CALLABLE) && (LA(2)==LPAREN)))
					{
						int _m251 = mark();
						synPredMatched251 = true;
						inputState.guessing++;
						try {
							{
								match(CALLABLE);
								match(LPAREN);
							}
						}
						catch (RecognitionException)
						{
							synPredMatched251 = false;
						}
						rewind(_m251);
						inputState.guessing--;
					}
					if ( synPredMatched251 )
					{
						{
							tr=callable_type_reference();
						}
					}
					else if ((tokenSet_43_.member(LA(1))) && (tokenSet_44_.member(LA(2)))) {
						{
							id=type_name();
							{
								if ((LA(1)==LBRACK) && (tokenSet_45_.member(LA(2))))
								{
									{
										match(LBRACK);
										{
											switch ( LA(1) )
											{
											case OF:
											{
												match(OF);
												break;
											}
											case CALLABLE:
											case CHAR:
											case THEN:
											case LPAREN:
											case ID:
											case MULTIPLY:
											case SPLICE_BEGIN:
											{
												break;
											}
											default:
											{
												throw new NoViableAltException(LT(1), getFilename());
											}
											 }
										}
										{
											switch ( LA(1) )
											{
											case MULTIPLY:
											{
												{
													match(MULTIPLY);
													if (0==inputState.guessing)
													{
														
																					gtdr = new GenericTypeDefinitionReference(ToLexicalInfo(id));
																					gtdr.Name = id.getText();
																					gtdr.GenericPlaceholders = 1;
																					tr = gtdr;										
																				
													}
													{    // ( ... )*
														for (;;)
														{
															if ((LA(1)==COMMA))
															{
																match(COMMA);
																match(MULTIPLY);
																if (0==inputState.guessing)
																{
																	
																									gtdr.GenericPlaceholders++;
																								
																}
															}
															else
															{
																goto _loop260_breakloop;
															}
															
														}
_loop260_breakloop:														;
													}    // ( ... )*
													match(RBRACK);
												}
												break;
											}
											case CALLABLE:
											case CHAR:
											case THEN:
											case LPAREN:
											case ID:
											case SPLICE_BEGIN:
											{
												{
													if (0==inputState.guessing)
													{
														
																					GenericTypeReference gtr = new GenericTypeReference(ToLexicalInfo(id), id.getText());
																					arguments = gtr.GenericArguments;
																					tr = gtr;
																				
													}
													type_reference_list(arguments);
													match(RBRACK);
												}
												break;
											}
											default:
											{
												throw new NoViableAltException(LT(1), getFilename());
											}
											 }
										}
									}
								}
								else if ((LA(1)==OF) && (LA(2)==MULTIPLY)) {
									{
										match(OF);
										match(MULTIPLY);
										if (0==inputState.guessing)
										{
											
																gtdr = new GenericTypeDefinitionReference(ToLexicalInfo(id));
																gtdr.Name = id.getText();
																gtdr.GenericPlaceholders = 1;
																tr = gtdr;
															
										}
									}
								}
								else if ((LA(1)==OF) && (tokenSet_46_.member(LA(2)))) {
									{
										match(OF);
										tr=type_reference();
										if (0==inputState.guessing)
										{
											
																GenericTypeReference gtr = new GenericTypeReference(ToLexicalInfo(id), id.getText());
																gtr.GenericArguments.Add(tr);
																tr = gtr;
															
										}
									}
								}
								else if ((tokenSet_44_.member(LA(1))) && (tokenSet_15_.member(LA(2)))) {
									if (0==inputState.guessing)
									{
										
														SimpleTypeReference str = new SimpleTypeReference(ToLexicalInfo(id));
														str.Name = id.getText();
														tr = str;
													
									}
								}
								else
								{
									throw new NoViableAltException(LT(1), getFilename());
								}
								
							}
							{
								if ((LA(1)==NULLABLE_SUFFIX) && (tokenSet_44_.member(LA(2))))
								{
									match(NULLABLE_SUFFIX);
									if (0==inputState.guessing)
									{
										
														GenericTypeReference ntr = new GenericTypeReference(tr.LexicalInfo, "System.Nullable");
														ntr.GenericArguments.Add(tr);
														tr = ntr;
													
									}
								}
								else if ((tokenSet_44_.member(LA(1))) && (tokenSet_15_.member(LA(2)))) {
								}
								else
								{
									throw new NoViableAltException(LT(1), getFilename());
								}
								
							}
						}
					}
				else
				{
					throw new NoViableAltException(LT(1), getFilename());
				}
				break; }
			}
			{    // ( ... )*
				for (;;)
				{
					if ((LA(1)==MULTIPLY) && (tokenSet_44_.member(LA(2))))
					{
						match(MULTIPLY);
						if (0==inputState.guessing)
						{
							tr = CodeFactory.EnumerableTypeReferenceFor(tr);
						}
					}
					else if ((LA(1)==EXPONENTIATION) && (tokenSet_44_.member(LA(2)))) {
						match(EXPONENTIATION);
						if (0==inputState.guessing)
						{
							tr = CodeFactory.EnumerableTypeReferenceFor(CodeFactory.EnumerableTypeReferenceFor(tr));
						}
					}
					else
					{
						goto _loop266_breakloop;
					}
					
				}
_loop266_breakloop:				;
			}    // ( ... )*
		}
		catch (RecognitionException ex)
		{
			if (0 == inputState.guessing)
			{
				reportError(ex, "type_reference");
				recover(ex,tokenSet_44_);
			}
			else
			{
				throw ex;
			}
		}
		return tr;
	}
コード例 #18
0
		override public object Clone()
		{
		
			GenericTypeReference clone = new GenericTypeReference();
			clone._lexicalInfo = _lexicalInfo;
			clone._endSourceLocation = _endSourceLocation;
			clone._documentation = _documentation;
			clone._isSynthetic = _isSynthetic;
			clone._entity = _entity;
			if (_annotations != null) clone._annotations = (Hashtable)_annotations.Clone();
			clone._isPointer = _isPointer;
			clone._name = _name;
			if (null != _genericArguments)
			{
				clone._genericArguments = _genericArguments.Clone() as TypeReferenceCollection;
				clone._genericArguments.InitializeParent(clone);
			}
			return clone;


		}
コード例 #19
0
		B.TypeReference ConvertTypeReference(TypeReference t)
		{
			if (t == null || t.IsNull)
				return null;
			B.TypeReference r;
			if (t.GenericTypes.Count > 0) {
				r = new B.GenericTypeReference(GetLexicalInfo(t), GetIntrinsicTypeName(t.Type));
				foreach (TypeReference ta in t.GenericTypes) {
					((B.GenericTypeReference)r).GenericArguments.Add(ConvertTypeReference(ta));
				}
			} else {
				r = new B.SimpleTypeReference(GetLexicalInfo(t), GetIntrinsicTypeName(t.Type));
			}
			if (t.IsArrayType) {
				for (int i = t.RankSpecifier.Length - 1; i >= 0; --i) {
					r = new B.ArrayTypeReference(GetLexicalInfo(t), r, new B.IntegerLiteralExpression(t.RankSpecifier[i] + 1));
				}
			}
			if (t.PointerNestingLevel != 0) {
				AddError(t, "Pointers are not supported by boo.");
			}
			return r;
		}
コード例 #20
0
ファイル: TypeReference.cs プロジェクト: w4x/boolangstudio
 public static TypeReference Lift(GenericReferenceExpression e)
 {
     GenericTypeReference typeRef = new GenericTypeReference(e.LexicalInfo);
     typeRef.Name = TypeNameFor(e.Target);
     typeRef.GenericArguments.ExtendWithClones(e.GenericArguments);
     return typeRef;
 }
コード例 #21
0
        public Module ConvertModule(Module module, CompilerContext context) {
            var dir = Path.GetDirectoryName(module.LexicalInfo.FileName);
            
            var clsname = Path.GetFileNameWithoutExtension(module.LexicalInfo.FileName).Replace("-", "_").Replace(".",
                                                                                                                  "__");
            var prefix = "L0_";
            if(dir.like(@"(?ix)[\\/]sys[\\/]?(extensions[\\/]?)$")) {
                prefix = "L1_";
            }
            else if(dir.like(@"(?ix)[\\/]mod[\\/]?(extensions[\\/]?)$")) {
                prefix = "L2_";
            }
            else if(dir.like(@"(?ix)[\\/]usr[\\/]?(extensions[\\/]?)$")) {
                prefix = "L3_";
            }
            prefix += Path.GetFileName(dir) + "_";
            clsname = prefix + clsname;
            //clsname - имя класса, который инкапсулирует в себе тело модуля и является настройщиком реестра
            var methodbody = (Block) module.Globals.Clone();
            //method body - участок модуля с выполняемым кодом
            module.Globals = new Block();
            foreach (var n in getmacronamespaces(context))
            {
                module.Imports.Add(new Import(n.Item2, new ReferenceExpression(n.Item1.GetName().Name), null));
            }
            //зачищаем глобальную область модуля
            module.Imports.Add(new Import("Comdiv.Extensibility.IRegistryLoader", new ReferenceExpression("Comdiv.Core"),
                                          new ReferenceExpression("_IRL_")));
            module.Imports.Add(new Import("System.Collections.Generic",
                                          new ReferenceExpression("System"), null));
            //гарантируем присутствие интерфейса IRegistryLoader в импорте и IDictionary<string,string>
            var newclass = new ClassDefinition();
            newclass.Name = clsname;
            newclass.BaseTypes.Add(new SimpleTypeReference("_IRL_"));
            //класс реализует интерфейс IRegistryLoader
            var method = new Method("Load");
            var dictref = new GenericTypeReference();
            dictref.Name = "System.Collections.Generic.IDictionary";
            dictref.GenericArguments.Add(new SimpleTypeReference("string"));
            dictref.GenericArguments.Add(new SimpleTypeReference("object"));
            method.Parameters.Add(new ParameterDeclaration("registry", dictref));
            method.Body = methodbody;
            //формируем соотвествующий метод

            //теперь отправляем все глобальные функции в наш класс
            foreach (var function in module.Members.OfType<Method>().ToArray()) {
                newclass.Members.Add((Method) function.Clone());
                module.Members.Remove(function);
            }


            newclass.Members.Add(method);


            //добавляем его в класс
            module.Members.Add(newclass);
            //отправляем готовый класс обратно в модуль

            module.Annotate("regmethod", method.Body);

            return module;
        }
コード例 #22
0
ファイル: CheckIdentifiers.cs プロジェクト: w4x/boolangstudio
 public override void OnGenericTypeReference(GenericTypeReference node)
 {
     CheckName(node,node.Name);
 }
コード例 #23
0
        public IType ResolveGenericTypeReference(GenericTypeReference gtr, IEntity definition)
        {
            ResolveTypeReferenceCollection(gtr.GenericArguments);

            return (IType)_context.TypeSystemServices.GenericsServices.ConstructEntity(definition, gtr, gtr.GenericArguments);
        }