// ResMemberDecl public override IResMemberDecl CreateInheritedDeclImpl( ResolveContext resContext, IResContainerBuilderRef resContainer, ILazy <IResMemberLineDecl> resLine, SourceRange range, IResMemberRef memberRef) { var firstRef = (ResMethodRef)memberRef; var firstDecl = firstRef.Decl; var result = ResMethodDecl.Build( resContext.LazyFactory, resLine, range, firstDecl.Name, (builder) => { // \todo: More substitution needed? // \todo: Add back in inheritance-related validation checks? /* * if (firstRef.Body == null * && memberRefs.OfType<IResMethodRef>().Any((mr) => (mr.Body != null))) * { * throw new NotImplementedException(); * } */ var subst = new Substitution(); var newParams = new List <ResVarDecl>(); foreach (var oldParam in firstRef.Parameters) { var newParam = new ResVarDecl( range, oldParam.Name, oldParam.Type, oldParam.Decl.Flags); subst.Insert(oldParam.Decl, newParam); newParams.Add(newParam); } builder.Parameters = newParams; builder.ResultType = firstRef.ResultType; builder.LazyBody = resContext.LazyFactory.New(() => firstRef.Body == null ? null : firstRef.Body.Substitute(subst)); }); return(result); }
// ResMemberDecl public override IResMemberDecl CreateInheritedDeclImpl( ResolveContext resContext, IResContainerBuilderRef resContainer, ILazy <IResMemberLineDecl> resLine, SourceRange range, IResMemberRef memberRef) { var firstRef = (IResGenericRef)memberRef; var result = ResGenericDecl.Build( resContext.LazyFactory, resLine, range, firstRef.Decl.Name, (builder) => { var newParameters = new List <IResGenericParamDecl>(); var subst = new Substitution(); foreach (var p in firstRef.Parameters) { if (p is IResTypeParamRef) { var oldParameter = (IResTypeParamRef)p; var newParameter = new ResTypeParamDecl( oldParameter.Decl.Range, oldParameter.Name, oldParameter.Kind); newParameters.Add(newParameter); subst.Insert(oldParameter.Decl, (r) => new ResTypeVarRef(r, newParameter)); } else if (p is IResVarSpec) { var oldParameter = (IResVarSpec)p; var newParameter = new ResVarDecl( oldParameter.Decl.Range, oldParameter.Name, resContext.LazyFactory.New(() => oldParameter.Type.Substitute(subst)), oldParameter.Decl.Flags); newParameters.Add(newParameter); subst.Insert(oldParameter.Decl, (r) => new ResVarRef(r, newParameter)); } else { throw new NotImplementedException(); } } builder.Parameters = newParameters; var args = (from p in newParameters select p.MakeGenericArg()).ToArray(); var innerRef = firstRef.App(range, args); /* * var innerCategoryGroup = new ResMemberCategoryGroup( * result, * new ResMemberNameGroup(result, result.Name), * new ResMethodCategory()); * var innerLine = new ResMemberDeclLine( * innerCategoryGroup, * new ResLexicalID()); */ var thisGenericBuilderRef = new ResGenericBuilderRef( range, builder, resContainer); var innerDecl = CreateInheritedDecl( resContext, thisGenericBuilderRef, resLine, range, innerRef); builder.InnerDecl = innerDecl; }); return(result); }
public override IResMemberDecl CreateInheritedDeclImpl( ResolveContext resContext, IResContainerBuilderRef resContainer, ILazy <IResMemberLineDecl> resLine, SourceRange range, IResMemberRef originalRef) { var firstRef = originalRef as IResConceptClassRef; var firstDecl = (IResConceptClassDecl)firstRef.Decl; var result = ResConceptClassDecl.Build( resContext.LazyFactory, resLine, range, firstDecl.Name, (builder) => { var thisConceptClassBuilder = new ResConceptClassBuilderRef( range, builder); var thisConceptClass = (IResConceptClassRef)resContainer.CreateMemberRef( range, builder.Value); var thisParameter = new ResVarDecl( range, firstDecl.ThisParameter.Name, thisConceptClass); builder.ThisConceptClass = thisConceptClass; builder.ThisParameter = thisParameter; foreach (var ml in firstRef.MemberLines) { var memberLine = ml; // Freaking C# variable capture!!!! var memberNameGroupBuilder = builder.GetMemberNameGroup(memberLine.Name); var memberCategoryGroupBuilder = memberNameGroupBuilder.GetMemberCategoryGroup(memberLine.Category); var newMemberLineBuilder = new ResMemberLineDeclBuilder( memberCategoryGroupBuilder, builder.LazyFactory, memberLine.Name, memberLine.OriginalLexicalID, memberLine.Category); memberCategoryGroupBuilder.AddLine(newMemberLineBuilder); newMemberLineBuilder.AddAction(() => { var memberRef = memberLine.EffectiveSpec.Bind( range, new ResVarRef(range, thisParameter)); var newMemberDecl = CreateInheritedDecl( resContext, thisConceptClassBuilder, newMemberLineBuilder, range, memberRef); newMemberLineBuilder.DirectDecl = newMemberDecl; }); builder.AddDirectMemberLine(newMemberLineBuilder); } }); return(result); }