Ejemplo n.º 1
0
        public VSharpTypeResolveContext GetTypeResolveContext(ICompilation compilation, Location loc)
        {
            var rctx = new VSharpTypeResolveContext(compilation.MainAssembly);

            rctx = rctx.WithUsingScope(GetUsingScope(loc).ResolveScope(compilation));
            var curDef = GetInnermostTypeDefinition(loc);

            if (curDef != null)
            {
                var resolvedDef = curDef.Resolve(rctx).GetDefinition();
                if (resolvedDef == null)
                {
                    return(rctx);
                }
                rctx = rctx.WithCurrentTypeDefinition(resolvedDef);

                var curMember = resolvedDef.Members.FirstOrDefault(m => m.Region.FileName == FileName && m.Region.Begin <= loc && loc < m.BodyRegion.End);
                if (curMember != null)
                {
                    rctx = rctx.WithCurrentMember(curMember);
                }
            }

            return(rctx);
        }
Ejemplo n.º 2
0
        IType ITypeReference.Resolve(ITypeResolveContext context)
        {
            // Strictly speaking, we might have to resolve the type in a nested compilation, similar
            // to what we're doing with ConstantExpression.
            // However, in almost all cases this will work correctly - if the resulting type is only available in the
            // nested compilation and not in this, we wouldn't be able to map it anyways.
            var ctx = context as VSharpTypeResolveContext;

            if (ctx == null)
            {
                ctx = new VSharpTypeResolveContext(context.CurrentAssembly ?? context.Compilation.MainAssembly, null, context.CurrentTypeDefinition, context.CurrentMember);
            }
            return(ResolveType(new ResolveContext(ctx, CompilerContext.report)));

            // A potential issue might be this scenario:

            // Assembly 1:
            //  class A { public class Nested {} }

            // Assembly 2: (references asm 1)
            //  class B : A {}

            // Assembly 3: (references asm 1 and 2)
            //  class C { public B.Nested Field; }

            // Assembly 4: (references asm 1 and 3, but not 2):
            //  uses C.Field;

            // Here we would not be able to resolve 'B.Nested' in the compilation of assembly 4, as type B is missing there.
        }
Ejemplo n.º 3
0
 VSharpTypeResolveContext MapToNestedCompilation(VSharpTypeResolveContext context, ICompilation nestedCompilation)
 {
     var nestedContext = new VSharpTypeResolveContext(nestedCompilation.MainAssembly);
     if (context.CurrentUsingScope != null)
     {
         nestedContext = nestedContext.WithUsingScope(context.CurrentUsingScope.UnresolvedUsingScope.ResolveScope(nestedCompilation));
     }
     if (context.CurrentTypeDefinition != null)
     {
         nestedContext = nestedContext.WithCurrentTypeDefinition(nestedCompilation.Import(context.CurrentTypeDefinition));
     }
     return nestedContext;
 }