Beispiel #1
0
 public TemplateParameterSymbol(TemplateParameter tpn, ISemantic typeOrValue, ISyntaxRegion paramIdentifier = null)
     : base(tpn != null ? tpn.Representation : null, AbstractType.Get(typeOrValue), paramIdentifier)
 {
     IsKnowinglyUndetermined = TemplateInstanceHandler.IsNonFinalArgument(typeOrValue);
     this.Parameter          = tpn;
     this.ParameterValue     = typeOrValue as ISymbolValue;
 }
        public bool HandleDecl(TemplateTypeParameter p, ITypeDeclaration td, ISemantic rr)
        {
            if (td is IdentifierDeclaration)
            {
                return(HandleDecl(p, (IdentifierDeclaration)td, rr));
            }

            if (TemplateInstanceHandler.IsNonFinalArgument(rr))
            {
                foreach (var tp in this.TargetDictionary.Keys.ToList())
                {
                    if (TargetDictionary[tp] == null)
                    {
                        TargetDictionary[tp] = new TemplateParameterSymbol(tp, null);
                    }
                }

                return(true);
            }

            //HACK Ensure that no information gets lost by using this function
            // -- getting a value but requiring an abstract type and just extract it from the value - is this correct behaviour?
            var at = AbstractType.Get(rr);

            if (td is ArrayDecl)
            {
                return(HandleDecl(p, (ArrayDecl)td, DResolver.StripMemberSymbols(at) as AssocArrayType));
            }
            else if (td is DTokenDeclaration)
            {
                return(HandleDecl((DTokenDeclaration)td, at));
            }
            else if (td is DelegateDeclaration)
            {
                return(HandleDecl(p, (DelegateDeclaration)td, DResolver.StripMemberSymbols(at) as DelegateType));
            }
            else if (td is PointerDecl)
            {
                return(HandleDecl(p, (PointerDecl)td, DResolver.StripMemberSymbols(at) as PointerType));
            }
            else if (td is MemberFunctionAttributeDecl)
            {
                return(HandleDecl(p, (MemberFunctionAttributeDecl)td, at));
            }
            else if (td is TypeOfDeclaration)
            {
                return(HandleDecl((TypeOfDeclaration)td, at));
            }
            else if (td is VectorDeclaration)
            {
                return(HandleDecl((VectorDeclaration)td, at));
            }
            else if (td is TemplateInstanceExpression)
            {
                return(HandleDecl(p, (TemplateInstanceExpression)td, at));
            }

            return(false);
        }
Beispiel #3
0
        /// <summary>
        /// Checks given results for type equality
        /// </summary>
        public static bool IsEqual(ISemantic r1, ISemantic r2)
        {
            if (r1 == r2)
            {
                return(true);
            }

            if (r1 is TemplateParameterSymbol)
            {
                var tps1 = r1 as TemplateParameterSymbol;
                var tps2 = r2 as TemplateParameterSymbol;
                if (tps2 != null && tps1.Parameter == tps2.Parameter)
                {
                    return((tps1.Base == null && tps2.Base == null) || IsEqual(tps1.Base, tps2.Base));
                }

                if (TemplateInstanceHandler.IsNonFinalArgument(r2))
                {
                    return(true);
                }
                r1 = tps1.Base;
            }
            if (r2 is TemplateParameterSymbol)
            {
                r2 = ((TemplateParameterSymbol)r2).Base;
            }

            if (r1 is ISymbolValue && r2 is ISymbolValue)
            {
                return(SymbolValueComparer.IsEqual((ISymbolValue)r1, (ISymbolValue)r2));
            }

            else if (r1 is TemplateIntermediateType && r2 is TemplateIntermediateType)
            {
                var tr1 = (TemplateIntermediateType)r1;
                var tr2 = (TemplateIntermediateType)r2;

                if (tr1.Definition != tr2.Definition)
                {
                    return(false);
                }

                //TODO: Compare deduced types
                return(true);
            }
            else if (r1 is PrimitiveType && r2 is PrimitiveType)
            {
                return(((PrimitiveType)r1).TypeToken == ((PrimitiveType)r2).TypeToken);
            }
            else if (r1 is ArrayType && r2 is ArrayType)
            {
                var ar1 = (ArrayType)r1;
                var ar2 = (ArrayType)r2;

                if (!IsEqual(ar1.KeyType, ar2.KeyType))
                {
                    return(false);
                }

                return(IsEqual(ar1.Base, ar2.Base));
            }
            else if (r1 is DelegateType && r2 is DelegateType)
            {
                var dg1 = r1 as DelegateType;
                var dg2 = r2 as DelegateType;

                if (dg1.IsFunctionLiteral != dg2.IsFunctionLiteral ||
                    !IsEqual(dg1.ReturnType, dg2.ReturnType))
                {
                    return(false);
                }

                if (dg1.Parameters == null || dg1.Parameters.Length == 0)
                {
                    return(dg2.Parameters == null || dg2.Parameters.Length == 0);
                }
                else if (dg2.Parameters == null)
                {
                    return(dg1.Parameters == null || dg1.Parameters.Length == 0);
                }
                else if (dg1.Parameters.Length == dg2.Parameters.Length)
                {
                    for (int i = dg1.Parameters.Length - 1; i != 0; i--)
                    {
                        if (!IsEqual(dg1.Parameters[i], dg2.Parameters[i]))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
            }

            //TODO: Handle other types

            return(false);
        }