B.ExplicitMemberInfo ConvertInterfaceImplementations(List <InterfaceImplementation> implementations, AttributedNode node, B.TypeMember targetMember)
 {
     if (implementations.Count == 0)
     {
         return(null);
     }
     if (implementations.Count > 1)
     {
         AddError(node, "Multiple explicit interface implementations are not supported");
     }
     if (implementations[0].MemberName != targetMember.Name)
     {
         AddError(node, "Explicit interface implementation: Implementing member with different name is not supported");
     }
     if (targetMember.Modifiers == B.TypeMemberModifiers.Private)
     {
         targetMember.Modifiers = B.TypeMemberModifiers.None;
     }
     else
     {
         AddError(node, "Explicit interface implementation: Only private methods can explicitly implement interfaces");
     }
     B.TypeReference tr = ConvertTypeReference(implementations[0].InterfaceType);
     if (tr is B.SimpleTypeReference)
     {
         B.ExplicitMemberInfo explicitInfo = new B.ExplicitMemberInfo(GetLexicalInfo(node));
         explicitInfo.InterfaceType = (B.SimpleTypeReference)tr;
         return(explicitInfo);
     }
     else
     {
         AddError(node, "Explicit interface implementation: invalid base type, expecting SimpleTypeReference");
         return(null);
     }
 }
예제 #2
0
 public object VisitTryCatchStatement(TryCatchStatement tryCatchStatement, object data)
 {
     B.TryStatement t = new B.TryStatement(GetLexicalInfo(tryCatchStatement));
     t.EndSourceLocation = GetLocation(tryCatchStatement.EndLocation);
     t.ProtectedBlock    = ConvertBlock(tryCatchStatement.StatementBlock);
     t.EnsureBlock       = ConvertBlock(tryCatchStatement.FinallyBlock);
     foreach (CatchClause clause in tryCatchStatement.CatchClauses)
     {
         B.ExceptionHandler handler = new B.ExceptionHandler(GetLexicalInfo(clause));
         handler.Block = ConvertBlock(clause.StatementBlock);
         B.TypeReference typeRef = ConvertTypeReference(clause.TypeReference);
         string          name    = clause.VariableName;
         if (typeRef != null)
         {
             if (name == null || name.Length == 0)
             {
                 name = GenerateName();
             }
             handler.Declaration = new B.Declaration(name, typeRef);
         }
         else
         {
             if (name != null && name.Length > 0)
             {
                 handler.Declaration = new B.Declaration(name, null);
             }
         }
         t.ExceptionHandlers.Add(handler);
     }
     return(t);
 }
예제 #3
0
		CodeTypeReference ConvTypeRef(TypeReference tr)
		{
			if (tr == null) return null;
			string name = tr.ToString();
			if (BooAmbience.ReverseTypeConversionTable.ContainsKey(name))
				name = BooAmbience.ReverseTypeConversionTable[name];
			return new CodeTypeReference(name);
		}
예제 #4
0
 void ConvertTypeReferences(List <TypeReference> input, B.TypeReferenceCollection output)
 {
     foreach (TypeReference t in input)
     {
         B.TypeReference r = ConvertTypeReference(t);
         if (r != null)
         {
             output.Add(r);
         }
     }
 }
예제 #5
0
        IReturnType CreateReturnType(AST.TypeReference reference, IMethod method)
        {
            IClass c = OuterClass;

            if (c == null)
            {
                return(CreateReturnType(reference, new DefaultClass(_cu, "___DummyClass"), method, 1, 1, _cu.ProjectContent));
            }
            else
            {
                return(CreateReturnType(reference, c, method, c.Region.BeginLine + 1, 1, _cu.ProjectContent));
            }
        }
		static bool IsSameType(TypeReference a, TypeReference b, StringComparer nameComparer)
		{
			ArrayTypeReference arr1 = a as ArrayTypeReference;
			ArrayTypeReference arr2 = b as ArrayTypeReference;
			SimpleTypeReference s1 = a as SimpleTypeReference;
			SimpleTypeReference s2 = b as SimpleTypeReference;
			if (arr1 != null && arr2 != null) {
				if (arr1.Rank.Value != arr2.Rank.Value)
					return false;
				return IsSameType(arr1.ElementType, arr2.ElementType, nameComparer);
			} else if (s1 != null && s2 != null) {
				return nameComparer.Equals(s1.Name, s2.Name);
			} else {
				return false;
			}
		}
        void ResolveInterfaceMembers(ClassDefinition node,
			TypeReference baseTypeRef,
			IType baseType)
        {
            foreach (IType entity in baseType.GetInterfaces())
            {
                ResolveInterfaceMembers(node, baseTypeRef, entity);
            }

            foreach (IMember entity in baseType.GetMembers())
            {
                ResolveAbstractMember(node, baseTypeRef, entity);
            }
        }
예제 #8
0
 void CheckParameterType(TypeReference type)
 {
     if (type.Entity != TypeSystemServices.VoidType) return;
     Error(CompilerErrorFactory.InvalidParameterType(type, type.Entity.ToString()));
 }
예제 #9
0
 public Method CreateRuntimeMethod(string name, TypeReference returnType)
 {
     Method method = CreateVirtualMethod(name, returnType);
     method.ImplementationFlags = MethodImplementationFlags.Runtime;
     return method;
 }
예제 #10
0
 public static CompilerError InvalidTypeConstraint(GenericParameterDeclaration gpd, TypeReference type)
 {
     return Instantiate("BCE0162", type, gpd.Name, type);
 }
예제 #11
0
 public IReturnType ConvertType(AST.TypeReference typeRef)
 {
     return(ConvertVisitor.CreateReturnType(typeRef, callingClass, callingMember,
                                            caretLine, caretColumn, pc));
 }
예제 #12
0
 void CheckParameterType(TypeReference type)
 {
     if (type.Entity != VoidType()) return;
     Error(CompilerErrorFactory.InvalidParameterType(type, VoidType()));
 }
예제 #13
0
파일: Field.cs 프로젝트: w4x/boolangstudio
 public Field(TypeReference type, Expression initializer)
 {
     this.Type = type;
     this.Initializer = initializer;
 }
예제 #14
0
		private void CheckForCycles(TypeReference baseTypeRef, AbstractInternalType baseType, List<TypeDefinition> visited)
		{
			if (visited.Contains(baseType.TypeDefinition))
			{
				BaseTypeError(CompilerErrorFactory.InheritanceCycle(baseTypeRef, baseType.FullName));
				return;
			}
			
			new BaseTypeResolution(Context, baseType.TypeDefinition, visited);
		}
예제 #15
0
 public static CompilerError MultipleBaseTypeConstraints(GenericParameterDeclaration gpd, TypeReference type, TypeReference other)
 {
     return Instantiate("BCE0163", type, gpd.Name, type, other);
 }
예제 #16
0
 public Declaration(string name, TypeReference type)
     : this(LexicalInfo.Empty, name, type)
 {
 }
예제 #17
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());
     }
 }
예제 #18
0
 bool CheckDeclarationType(TypeReference type)
 {
     if (type.Entity != TypeSystemServices.VoidType) return true;
     Error(CompilerErrorFactory.InvalidDeclarationType(type, type.Entity.ToString()));
     return false;
 }
예제 #19
0
 public ParameterDeclaration(string name, TypeReference type)
     : this(name, type, ParameterModifiers.None)
 {
 }
예제 #20
0
 public ParameterDeclaration(string name, TypeReference type, ParameterModifiers modifiers)
 {
     this.Name = name;
     this.Type = type;
     this.Modifiers = modifiers;
 }
예제 #21
0
 public static CompilerError TypeConstraintConflictsWithSpecialConstraint(GenericParameterDeclaration gpd, TypeReference type, string constraint)
 {
     return Instantiate("BCE0161", type, gpd.Name, type, constraint);
 }
예제 #22
0
 IReturnType CreateReturnType(AST.TypeReference reference)
 {
     return(CreateReturnType(reference, null));
 }
 private static bool IsUnknown(TypeReference typeRef)
 {
     return Unknown.Default == typeRef.Entity;
 }
예제 #24
0
 public override bool Replace(Node existing, Node newNode)
 {
     if (base.Replace(existing, newNode))
     {
         return true;
     }
     if (_type == existing)
     {
         this.Type = (TypeReference)newNode;
         return true;
     }
     return false;
 }
 //returns true if a stub has been created, false otherwise.
 //TODO: add entity argument to the method to not need return type?
 bool AbstractMemberNotImplemented(ClassDefinition node, TypeReference baseTypeRef, IMember member)
 {
     if (IsValueType(node))
     {
         Error(CompilerErrorFactory.ValueTypeCantHaveAbstractMember(baseTypeRef, node.FullName, GetAbstractMemberSignature(member)));
         return false;
     }
     if (!node.IsAbstract)
     {
         //BEHAVIOR >= 0.7.7:	(see BOO-789 for details)
         //create a stub for this not implemented member
         //it will raise a NotImplementedException if called at runtime
         TypeMember m = CodeBuilder.CreateStub(member);
         CompilerWarning warning = null;
         if (null != m)
         {
             warning = CompilerWarningFactory.AbstractMemberNotImplementedStubCreated(baseTypeRef,
                                 node.FullName, GetAbstractMemberSignature(member));
             node.Members.Add(m);
         }
         else
         {
             warning = CompilerWarningFactory.AbstractMemberNotImplemented(baseTypeRef,
                                 node.FullName, GetAbstractMemberSignature(member));
             _newAbstractClasses.AddUnique(node);
         }
         Warnings.Add(warning);
         return (null != m);
     }
     return false;
 }
예제 #26
0
 public Declaration(LexicalInfo token, string name, TypeReference type)
     : base(token)
 {
     this.Name = name;
     this.Type = type;
 }
        Property CreateAbstractProperty(TypeReference reference, IProperty property)
        {
            Debug.Assert(0 == property.GetParameters().Length);
            Property p = CodeBuilder.CreateProperty(property.Name, property.Type);
            p.Modifiers |= TypeMemberModifiers.Abstract;

            IMethod getter = property.GetGetMethod();
            if (getter != null)
            {
                p.Getter = CodeBuilder.CreateAbstractMethod(reference.LexicalInfo, getter);
            }

            IMethod setter = property.GetSetMethod();
            if (setter != null)
            {
                p.Setter = CodeBuilder.CreateAbstractMethod(reference.LexicalInfo, setter);
            }
            return p;
        }
예제 #28
0
파일: Field.cs 프로젝트: w4x/boolangstudio
 public Field(LexicalInfo lexicalInfo, TypeReference type, Expression initializer)
     : base(lexicalInfo)
 {
     this.Type = type;
     this.Initializer = initializer;
 }
        void ResolveAbstractEvent(ClassDefinition node,
			TypeReference baseTypeRef,
			IEvent entity)
        {
            TypeMember member = node.Members[entity.Name];
            if (null != member)
            {
                Event ev = (Event)member;

                Method add = ev.Add;
                if (add != null)
                {
                    add.Modifiers |= TypeMemberModifiers.Final | TypeMemberModifiers.Virtual;
                }

                Method remove = ev.Remove;
                if (remove != null)
                {
                    remove.Modifiers |= TypeMemberModifiers.Final | TypeMemberModifiers.Virtual;
                }

                Method raise = ev.Remove;
                if (raise != null)
                {
                    raise.Modifiers |= TypeMemberModifiers.Final | TypeMemberModifiers.Virtual;
                }

                _context.TraceInfo("{0}: Event {1} implements {2}", ev.LexicalInfo, ev, entity);
                return;
            }
            if(CheckInheritsInterfaceImplementation(node, entity))
            {
                return;
            }
            foreach(SimpleTypeReference parent in node.BaseTypes)
            {
                if(_classDefinitionList.Contains(parent.Name))
                {
                    depth++;
                    ResolveAbstractEvent(_classDefinitionList[parent.Name] as ClassDefinition, baseTypeRef, entity);
                    depth--;
                }
            }
            if(depth == 0)
            {
                node.Members.Add(CodeBuilder.CreateAbstractEvent(baseTypeRef.LexicalInfo, entity));
                AbstractMemberNotImplemented(node, baseTypeRef, entity);
            }
        }
예제 #30
0
파일: Event.cs 프로젝트: 0xb1dd1e/boo
		public Event(LexicalInfo lexicalInfo, string name, TypeReference type) : base(lexicalInfo)
		{
			this.Name = name;
			this.Type = type;
		}
        void ResolveAbstractMember(ClassDefinition node,
			TypeReference baseTypeRef,
			IMember member)
        {
            switch (member.EntityType)
            {
                case EntityType.Method:
                {
                    ResolveAbstractMethod(node, baseTypeRef, (IMethod)member);
                    break;
                }

                case EntityType.Property:
                {
                    ResolveClassAbstractProperty(node, baseTypeRef, (IProperty)member);
                    break;
                }

                case EntityType.Event:
                {
                    ResolveAbstractEvent(node, baseTypeRef, (IEvent)member);
                    break;
                }

                default:
                {
                    NotImplemented(baseTypeRef, "abstract member: " + member);
                    break;
                }
            }
        }
예제 #32
0
 bool CheckDeclarationType(TypeReference type)
 {
     if (type.Entity != VoidType()) return true;
     Error(CompilerErrorFactory.InvalidDeclarationType(type, VoidType()));
     return false;
 }
        void ResolveAbstractMembers(ClassDefinition node,
			TypeReference baseTypeRef,
			IType baseType)
        {
            foreach (IEntity member in baseType.GetMembers())
            {
                switch (member.EntityType)
                {
                    case EntityType.Method:
                    {
                        IMethod method = (IMethod)member;
                        if (method.IsAbstract)
                        {
                            ResolveAbstractMethod(node, baseTypeRef, method);
                        }
                        break;
                    }

                    case EntityType.Property:
                    {
                        IProperty property = (IProperty)member;
                        if (IsAbstractAccessor(property.GetGetMethod()) ||
                            IsAbstractAccessor(property.GetSetMethod()))
                        {
                            ResolveClassAbstractProperty(node, baseTypeRef, property);
                        }
                        break;
                    }

                    case EntityType.Event:
                    {
                        IEvent ev = (IEvent)member;
                        if (ev.IsAbstract)
                        {
                            ResolveAbstractEvent(node, baseTypeRef, ev);
                        }
                        break;
                    }

                }
            }
        }
예제 #34
0
 public Method CreateMethod(string name, TypeReference returnType, TypeMemberModifiers modifiers)
 {
     Method method = new Method(name);
     method.Modifiers = modifiers;
     method.ReturnType = returnType;
     method.IsSynthetic = true;
     EnsureEntityFor(method);
     return method;
 }
        void ResolveAbstractMethod(ClassDefinition node,
			TypeReference baseTypeRef,
			IMethod entity)
        {
            if (entity.IsSpecialName)
                return;

            bool resolved = false;

            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 (GenericsServices.IsGenericParameter(method.ReturnType.Entity)
                                    == GenericsServices.IsGenericParameter(entity.ReturnType))
                        {
                            if (!entity.ReturnType.Equals(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);
                        resolved = true;
                    }
                }
            }

            if (resolved)
                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));
                }
            }
        }
예제 #36
0
 public Method CreateVirtualMethod(string name, TypeReference returnType)
 {
     return CreateMethod(name, returnType, TypeMemberModifiers.Public|TypeMemberModifiers.Virtual);
 }
        void ResolveClassAbstractProperty(ClassDefinition node,
			TypeReference baseTypeRef,
			IProperty entity)
        {
            bool resolved = false;

            foreach (TypeMember member in node.Members)
            {
                if (entity.Name != member.Name
                    || NodeType.Property != member.NodeType
                    || !IsCorrectExplicitMemberImplOrNoExplicitMemberAtAll(member, entity)
                    || !TypeSystemServices.CheckOverrideSignature(entity.GetParameters(), GetPropertyEntity(member).GetParameters()))
                    continue;

                Property p = (Property) member;
                ProcessPropertyAccessor(p, p.Getter, entity.GetGetMethod());
                ProcessPropertyAccessor(p, p.Setter, entity.GetSetMethod());
                if (null == p.Type)
                {
                    p.Type = CodeBuilder.CreateTypeReference(entity.Type);
                }
                else
                {
                    if (entity.Type != p.Type.Entity)
                        Error(CompilerErrorFactory.ConflictWithInheritedMember(p, p.FullName, entity.FullName));
                }
                resolved = true;
            }

            if (resolved)
                return;

            foreach(SimpleTypeReference parent in node.BaseTypes)
            {
                if(_classDefinitionList.Contains(parent.Name))
                {
                    depth++;
                    ResolveClassAbstractProperty(_classDefinitionList[parent.Name] as ClassDefinition, baseTypeRef, entity);
                    depth--;
                }
            }

            if(CheckInheritsInterfaceImplementation(node, entity))
                return;

            if(depth == 0)
            {
                node.Members.Add(CreateAbstractProperty(baseTypeRef, entity));
                AbstractMemberNotImplemented(node, baseTypeRef, entity);
            }
        }