本文整理汇总了C#中ResolutionContext.PushNewScope方法的典型用法代码示例。如果您正苦于以下问题:C# ResolutionContext.PushNewScope方法的具体用法?C# ResolutionContext.PushNewScope怎么用?C# ResolutionContext.PushNewScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ResolutionContext
的用法示例。
在下文中一共展示了ResolutionContext.PushNewScope方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMixinContent
static string GetMixinContent(MixinStatement mx, ResolutionContext ctxt, bool takeStmtCache ,out ISyntaxRegion cachedContent)
{
cachedContent = null;
if(!CheckAndPushAnalysisStack(mx))
return null;
bool pop;
if(pop = (ctxt.ScopedBlock != mx.ParentNode && mx.ParentNode != null))
ctxt.PushNewScope(mx.ParentNode as IBlockNode, mx);
bool hadCachedItem;
if(takeStmtCache)
{
BlockStatement stmt;
hadCachedItem = mixinStmtCache.TryGet(ctxt, mx, out stmt);
cachedContent = stmt;
}
else
{
DModule mod;
hadCachedItem = mixinDeclCache.TryGet(ctxt, mx, out mod);
cachedContent = mod;
}
if(hadCachedItem)
{
stmtsBeingAnalysed.Remove(mx);
if(pop)
ctxt.Pop();
return null;
}
var x = mx.MixinExpression;
ISemantic v = null;
try // 'try' because there is always a risk of e.g. not having something implemented or having an evaluation exception...
{
// Evaluate the mixin expression
v = Evaluation.EvaluateValue(x, ctxt);
}
catch{}
stmtsBeingAnalysed.Remove(mx);
if(pop)
ctxt.Pop();
// Ensure it's a string literal
var av = v as ArrayValue;
if(av != null && av.IsString)
return av.StringValue;
if(takeStmtCache)
mixinStmtCache.Add(ctxt, mx, null);
else
mixinDeclCache.Add(ctxt, mx, null);
return null;
}
示例2: TryResolveUFCS
public static MemberSymbol[] TryResolveUFCS(
ISemantic firstArgument,
PostfixExpression_Access acc,
ResolutionContext ctxt)
{
if (ctxt == null)
return null;
int name=0;
if (acc.AccessExpression is IdentifierExpression)
name = ((IdentifierExpression)acc.AccessExpression).ValueStringHash;
else if (acc.AccessExpression is TemplateInstanceExpression)
name = ((TemplateInstanceExpression)acc.AccessExpression).TemplateIdHash;
else
return null;
var methodMatches = new List<MemberSymbol>();
if(ctxt.ParseCache!=null)
foreach (var pc in ctxt.ParseCache)
{
var tempResults=pc.UfcsCache.FindFitting(ctxt, acc.Location, firstArgument, name);
if (tempResults != null)
foreach (var m in tempResults)
{
ctxt.PushNewScope(m);
if (m.TemplateParameters != null && m.TemplateParameters.Length != 0)
{
var ov = TemplateInstanceHandler.DeduceParamsAndFilterOverloads(
new[] { new MemberSymbol(m, null, acc) },
new[] { firstArgument }, true, ctxt);
if (ov == null || ov.Length == 0)
continue;
var ms = (DSymbol)ov[0];
ctxt.CurrentContext.IntroduceTemplateParameterTypes(ms);
}
var mr = TypeDeclarationResolver.HandleNodeMatch(m, ctxt, null, acc) as MemberSymbol;
if (mr!=null)
{
mr.FirstArgument = firstArgument;
mr.DeducedTypes = ctxt.CurrentContext.DeducedTemplateParameters.ToReadonly();
mr.IsUFCSResult = true;
methodMatches.Add(mr);
}
ctxt.Pop();
}
}
return methodMatches.Count == 0 ? null : methodMatches.ToArray();
}
示例3: ResolveIdentifier
/// <summary>
/// Resolves an identifier and returns the definition + its base type.
/// Does not deduce any template parameters or nor filters out unfitting template specifications!
/// </summary>
public static AbstractType[] ResolveIdentifier(int idHash, ResolutionContext ctxt, object idObject, bool ModuleScope = false)
{
var loc = idObject is ISyntaxRegion ? ((ISyntaxRegion)idObject).Location : CodeLocation.Empty;
if (ModuleScope)
ctxt.PushNewScope(ctxt.ScopedBlock.NodeRoot as DModule);
// If there are symbols that must be preferred, take them instead of scanning the ast
else
{
TemplateParameterSymbol dedTemplateParam;
if (ctxt.GetTemplateParam(idHash, out dedTemplateParam))
return new[] { dedTemplateParam };
}
var res = NameScan.SearchAndResolve(ctxt, loc, idHash, idObject);
if (ModuleScope)
ctxt.Pop();
return /*res.Count == 0 ? null :*/ res.ToArray();
}
示例4: TryResolveFurtherIdViaOpDispatch
/// <summary>
/// http://dlang.org/operatoroverloading.html#Dispatch
/// Check for the existence of an opDispatch overload.
/// Important: Because static opDispatches are allowed as well, do check whether we can access non-static overloads from non-instance expressions or such
/// </summary>
public static IEnumerable<AbstractType> TryResolveFurtherIdViaOpDispatch(ResolutionContext ctxt, int nextIdentifierHash, UserDefinedType b)
{
// The usual SO prevention
if (nextIdentifierHash == opDispatchId || b == null)
yield break;
var pop = ctxt.ScopedBlock != b.Definition;
if (pop) {
// Mainly required for not resolving opDispatch's return type, as this will be performed later on in higher levels
var opt = ctxt.CurrentContext.ContextDependentOptions;
ctxt.PushNewScope (b.Definition as IBlockNode);
ctxt.CurrentContext.IntroduceTemplateParameterTypes (b);
ctxt.CurrentContext.ContextDependentOptions = opt;
}
// Look for opDispatch-Members inside b's Definition
var overloads = TypeDeclarationResolver.ResolveFurtherTypeIdentifier (opDispatchId, new[]{b}, ctxt);
if(pop)
ctxt.Pop ();
if (overloads == null || overloads.Length < 0)
yield break;
var av = new ArrayValue (Evaluation.GetStringType(ctxt), Strings.TryGet(nextIdentifierHash));
foreach (DSymbol o in overloads) {
var dn = o.Definition;
if (dn.TemplateParameters != null && dn.TemplateParameters.Length > 0 &&
dn.TemplateParameters[0] is TemplateValueParameter)
{
//TODO: Test parameter types for being a string value
o.DeducedTypes = new System.Collections.ObjectModel.ReadOnlyCollection<TemplateParameterSymbol> (
new[]{ new TemplateParameterSymbol(dn.TemplateParameters[0], av) } );
yield return o;
}
}
}
示例5: Scan
/// <summary>
/// </summary>
/// <param name="ast">The syntax tree to scan</param>
/// <param name="symbol">Might not be a child symbol of ast</param>
/// <param name="ctxt">The context required to search for symbols</param>
/// <returns></returns>
public static IEnumerable<ISyntaxRegion> Scan(DModule ast, INode symbol, ResolutionContext ctxt, bool includeDefinition = true)
{
if (ast == null || symbol == null || ctxt == null)
return null;
ctxt.PushNewScope(ast);
var f = new ReferencesFinder(symbol, ast, ctxt);
ast.Accept (f);
ctxt.Pop();
var nodeRoot = symbol.NodeRoot as DModule;
if (includeDefinition && nodeRoot != null && nodeRoot.FileName == ast.FileName)
{
var dc = symbol.Parent as DClassLike;
if (dc != null && dc.ClassType == D_Parser.Parser.DTokens.Template &&
dc.NameHash == symbol.NameHash)
{
f.l.Insert(0, new IdentifierDeclaration(dc.NameHash)
{
Location = dc.NameLocation,
EndLocation = new CodeLocation(dc.NameLocation.Column + dc.Name.Length, dc.NameLocation.Line)
});
}
f.l.Insert(0, new IdentifierDeclaration(symbol.NameHash)
{
Location = symbol.NameLocation,
EndLocation = new CodeLocation(symbol.NameLocation.Column + symbol.Name.Length, symbol.NameLocation.Line)
});
}
return f.l;
}
示例6: TryGetImplicitProperty
static AbstractType[] TryGetImplicitProperty(TemplateType template, ResolutionContext ctxt)
{
// Prepare a new context
bool pop = !ctxt.ScopedBlockIsInNodeHierarchy(template.Definition);
if (pop)
ctxt.PushNewScope(template.Definition);
// Introduce the deduced params to the current resolution context
ctxt.CurrentContext.IntroduceTemplateParameterTypes(template);
// Get actual overloads
var matchingChild = TypeDeclarationResolver.ResolveFurtherTypeIdentifier( template.NameHash, new[]{ template }, ctxt);
// Undo context-related changes
if (pop)
ctxt.Pop();
else
ctxt.CurrentContext.RemoveParamTypesFromPreferredLocals(template);
return matchingChild;
}
示例7: WaitForFinish
/*
public bool WaitForFinish(int millisecondsToWait = -1)
{
if(millisecondsToWait < 0)
return completedEvent.WaitOne();
return completedEvent.WaitOne(millisecondsToWait);
}*/
public void CacheModuleMethods(DModule ast, ResolutionContext ctxt)
{
foreach (var m in ast)
if (m is DMethod)
{
var dm = (DMethod)m;
if (dm.Parameters == null || dm.NameHash == 0 || dm.Parameters.Count == 0 || dm.Parameters[0].Type == null)
continue;
ctxt.PushNewScope(dm);
var firstArg_result = TypeDeclarationResolver.Resolve(dm.Parameters[0].Type, ctxt);
ctxt.Pop();
if (firstArg_result != null && firstArg_result.Length != 0)
CachedMethods[dm] = firstArg_result[0];
}
}
示例8: GetMethodReturnType
public static AbstractType GetMethodReturnType(DMethod method, ResolutionContext ctxt)
{
if ((ctxt.Options & ResolutionOptions.DontResolveBaseTypes) == ResolutionOptions.DontResolveBaseTypes)
return null;
/*
* If a method's type equals null, assume that it's an 'auto' function..
* 1) Search for a return statement
* 2) Resolve the returned expression
* 3) Use that one as the method's type
*/
bool pushMethodScope = ctxt.ScopedBlock != method;
if (method.Type != null)
{
if (pushMethodScope)
ctxt.PushNewScope(method);
//FIXME: Is it legal to explicitly return a nested type?
var returnType = TypeDeclarationResolver.Resolve(method.Type, ctxt);
if (pushMethodScope)
ctxt.Pop();
ctxt.CheckForSingleResult(returnType, method.Type);
if(returnType != null && returnType.Length > 0)
return returnType[0];
}
else if (method.Body != null)
{
ReturnStatement returnStmt = null;
var list = new List<IStatement> { method.Body };
var list2 = new List<IStatement>();
bool foundMatch = false;
while (!foundMatch && list.Count > 0)
{
foreach (var stmt in list)
{
if (stmt is ReturnStatement)
{
returnStmt = stmt as ReturnStatement;
var te = returnStmt.ReturnExpression as TokenExpression;
if (te == null || te.Token != DTokens.Null)
{
foundMatch = true;
break;
}
}
var statementContainingStatement = stmt as StatementContainingStatement;
if (statementContainingStatement != null)
list2.AddRange(statementContainingStatement.SubStatements);
}
list = list2;
list2 = new List<IStatement>();
}
if (returnStmt != null && returnStmt.ReturnExpression != null)
{
if (pushMethodScope)
{
var dedTypes = ctxt.CurrentContext.DeducedTemplateParameters;
ctxt.PushNewScope(method,returnStmt);
if (dedTypes.Count != 0)
foreach (var kv in dedTypes)
ctxt.CurrentContext.DeducedTemplateParameters[kv.Key] = kv.Value;
}
var t =DResolver.StripMemberSymbols(Evaluation.EvaluateType(returnStmt.ReturnExpression, ctxt));
if (pushMethodScope)
ctxt.Pop();
return t;
}
return new PrimitiveType (DTokens.Void);
}
return null;
}
示例9: HandleNodeMatch
/// <summary>
/// The variable's or method's base type will be resolved (if auto type, the intializer's type will be taken).
/// A class' base class will be searched.
/// etc..
/// </summary>
public static AbstractType HandleNodeMatch(
INode m,
ResolutionContext ctxt,
AbstractType resultBase = null,
object typeBase = null)
{
AbstractType ret = null;
// See https://github.com/aBothe/Mono-D/issues/161
int stkC;
if (stackCalls == null)
{
stackCalls = new Dictionary<INode, int>();
stackCalls[m] = stkC = 1;
}
else if (stackCalls.TryGetValue(m, out stkC))
stackCalls[m] = ++stkC;
else
stackCalls[m] = stkC = 1;
/*
* Pushing a new scope is only required if current scope cannot be found in the handled node's hierarchy.
* Edit: No, it is required nearly every time because of nested type declarations - then, we do need the
* current block scope.
*/
bool popAfterwards;
{
var newScope = m is IBlockNode ? (IBlockNode)m : m.Parent as IBlockNode;
popAfterwards = ctxt.ScopedBlock != newScope && newScope != null;
if (popAfterwards) {
var options = ctxt.CurrentContext.ContextDependentOptions;
var applyOptions = ctxt.ScopedBlockIsInNodeHierarchy (m);
ctxt.PushNewScope (newScope);
if (applyOptions)
ctxt.CurrentContext.ContextDependentOptions = options;
}
}
var canResolveBase = ((ctxt.Options & ResolutionOptions.DontResolveBaseTypes) != ResolutionOptions.DontResolveBaseTypes) &&
stkC < 10 && (m.Type == null || m.Type.ToString(false) != m.Name);
// To support resolving type parameters to concrete types if the context allows this, introduce all deduced parameters to the current context
if (resultBase is DSymbol)
ctxt.CurrentContext.IntroduceTemplateParameterTypes((DSymbol)resultBase);
var importSymbolNode = m as ImportSymbolNode;
var variable = m as DVariable;
// Only import symbol aliases are allowed to search in the parse cache
if (importSymbolNode != null)
ret = HandleImportSymbolMatch (importSymbolNode,ctxt);
else if (variable != null)
{
AbstractType bt = null;
if (!(variable is EponymousTemplate)) {
if (canResolveBase) {
var bts = TypeDeclarationResolver.Resolve (variable.Type, ctxt);
ctxt.CheckForSingleResult (bts, variable.Type);
if (bts != null && bts.Length != 0)
bt = bts [0];
// For auto variables, use the initializer to get its type
else if (variable.Initializer != null) {
bt = DResolver.StripMemberSymbols (Evaluation.EvaluateType (variable.Initializer, ctxt));
}
// Check if inside an foreach statement header
if (bt == null && ctxt.ScopedStatement != null)
bt = GetForeachIteratorType (variable, ctxt);
}
// Note: Also works for aliases! In this case, we simply try to resolve the aliased type, otherwise the variable's base type
ret = variable.IsAlias ?
new AliasedType (variable, bt, typeBase as ISyntaxRegion) as MemberSymbol :
new MemberSymbol (variable, bt, typeBase as ISyntaxRegion);
} else
ret = new EponymousTemplateType (variable as EponymousTemplate, GetInvisibleTypeParameters(variable, ctxt).AsReadOnly(), typeBase as ISyntaxRegion);
}
else if (m is DMethod)
{
ret = new MemberSymbol(m as DNode,canResolveBase ? GetMethodReturnType(m as DMethod, ctxt) : null, typeBase as ISyntaxRegion);
}
else if (m is DClassLike)
ret = HandleClassLikeMatch (m as DClassLike, ctxt, typeBase, canResolveBase);
else if (m is DModule)
{
var mod = (DModule)m;
if (typeBase != null && typeBase.ToString() != mod.ModuleName)
{
var pack = ctxt.ParseCache.LookupPackage(typeBase.ToString()).FirstOrDefault();
if (pack != null)
ret = new PackageSymbol(pack, typeBase as ISyntaxRegion);
}
//.........这里部分代码省略.........
示例10: ResolveFurtherTypeIdentifier
/// <summary>
/// Used for searching further identifier list parts.
///
/// a.b -- nextIdentifier would be 'b' whereas <param name="resultBases">resultBases</param> contained the resolution result for 'a'
/// </summary>
public static AbstractType[] ResolveFurtherTypeIdentifier(int nextIdentifierHash,
IEnumerable<AbstractType> resultBases,
ResolutionContext ctxt,
object typeIdObject = null)
{
MemberSymbol statProp;
if ((resultBases = DResolver.StripMemberSymbols(resultBases)) == null)
return null;
var r = new List<AbstractType>();
foreach(var b in resultBases)
{
if (b is UserDefinedType)
{
var udt = b as UserDefinedType;
var bn = udt.Definition as IBlockNode;
bool pop = !(b is MixinTemplateType);
if(!pop)
ctxt.PushNewScope(bn);
ctxt.CurrentContext.IntroduceTemplateParameterTypes(udt);
r.AddRange(SingleNodeNameScan.SearchChildrenAndResolve(ctxt, bn, nextIdentifierHash, typeIdObject));
List<TemplateParameterSymbol> dedTypes = null;
foreach (var t in r)
{
var ds = t as DSymbol;
if (ds != null && ds.DeducedTypes == null)
{
if (dedTypes == null)
dedTypes = ctxt.DeducedTypesInHierarchy;
ds.DeducedTypes = new System.Collections.ObjectModel.ReadOnlyCollection<TemplateParameterSymbol>(dedTypes);
}
}
statProp = StaticProperties.TryEvalPropertyType(ctxt, b, nextIdentifierHash);
if (statProp != null)
r.Add(statProp);
ctxt.CurrentContext.RemoveParamTypesFromPreferredLocals(udt);
if(!pop)
ctxt.Pop();
}
else if (b is PackageSymbol)
{
var pack = (b as PackageSymbol).Package;
var accessedModule = pack.GetModule(nextIdentifierHash);
if (accessedModule != null)
r.Add(new ModuleSymbol(accessedModule as DModule, typeIdObject as ISyntaxRegion, b as PackageSymbol));
else if ((pack = pack.GetPackage(nextIdentifierHash)) != null)
r.Add(new PackageSymbol(pack, typeIdObject as ISyntaxRegion));
}
else if (b is ModuleSymbol)
r.AddRange(SingleNodeNameScan.SearchChildrenAndResolve(ctxt, (b as ModuleSymbol).Definition, nextIdentifierHash, typeIdObject));
else
{
statProp = StaticProperties.TryEvalPropertyType(ctxt, b, nextIdentifierHash);
if (statProp != null)
r.Add(statProp);
}
// TODO: Search for UFCS symbols
}
return r.Count == 0 ? null : r.ToArray();
}