本文整理汇总了C#中ResolutionContext.CheckForSingleResult方法的典型用法代码示例。如果您正苦于以下问题:C# ResolutionContext.CheckForSingleResult方法的具体用法?C# ResolutionContext.CheckForSingleResult怎么用?C# ResolutionContext.CheckForSingleResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ResolutionContext
的用法示例。
在下文中一共展示了ResolutionContext.CheckForSingleResult方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PreResolveTemplateArgs
public static List<ISemantic> PreResolveTemplateArgs(TemplateInstanceExpression tix, ResolutionContext ctxt, out bool hasNonFinalArgument)
{
hasNonFinalArgument = false;
// Resolve given argument expressions
var templateArguments = new List<ISemantic>();
if (tix != null && tix.Arguments!=null)
foreach (var arg in tix.Arguments)
{
if (arg is TypeDeclarationExpression)
{
var tde = (TypeDeclarationExpression)arg;
var res = TypeDeclarationResolver.Resolve(tde.Declaration, ctxt);
if (ctxt.CheckForSingleResult(res, tde.Declaration) || res != null)
{
var mr = res[0] as MemberSymbol;
if (mr != null && mr.Definition is DVariable)
{
var dv = (DVariable)mr.Definition;
if (dv.IsAlias || dv.Initializer == null)
{
templateArguments.Add(mr);
continue;
}
ISemantic eval = null;
try
{
eval = new StandardValueProvider(ctxt)[dv];
}
catch(System.Exception ee) // Should be a non-const-expression error here only
{
ctxt.LogError(dv.Initializer, ee.Message);
}
templateArguments.Add(eval==null ? (ISemantic)mr : eval);
}
else{
if(!hasNonFinalArgument)
hasNonFinalArgument = IsNonFinalArgument(res[0]);
templateArguments.Add(res[0]);
}
}
}
else
{
var v = Evaluation.EvaluateValue(arg, ctxt, true);
if (v is VariableValue)
{
var vv = v as VariableValue;
if (vv.Variable.IsConst && vv.Variable.Initializer != null)
v = Evaluation.EvaluateValue(vv, new StandardValueProvider(ctxt));
}
if(!hasNonFinalArgument)
hasNonFinalArgument = IsNonFinalArgument(v);
templateArguments.Add(v);
}
}
return templateArguments;
}
示例2: ResolveSingle
/// <summary>
/// See <see cref="Resolve"/>
/// </summary>
public static AbstractType ResolveSingle(IdentifierDeclaration id, ResolutionContext ctxt, AbstractType[] resultBases = null, bool filterForTemplateArgs = true)
{
var r = Resolve(id, ctxt, resultBases, filterForTemplateArgs);
ctxt.CheckForSingleResult(r, id);
return r != null && r.Length != 0 ? r[0] : null;
}
示例3: HandleAccessExpressions
AbstractType HandleAccessExpressions(PostfixExpression_Access acc, ResolutionContext ctxt)
{
AbstractType pfType = null;
if (acc.PostfixForeExpression is PostfixExpression_Access)
pfType = HandleAccessExpressions((PostfixExpression_Access)acc.PostfixForeExpression, ctxt);
else
{
pfType = DResolver.StripAliasSymbol(Evaluation.EvaluateType(acc.PostfixForeExpression, ctxt));
if (acc.PostfixForeExpression is IdentifierExpression ||
acc.PostfixForeExpression is TemplateInstanceExpression ||
acc.PostfixForeExpression is PostfixExpression_Access)
HandleResult(acc.PostfixForeExpression, pfType);
}
var accessedMembers = Evaluation.GetAccessedOverloads(acc, ctxt, pfType);
ctxt.CheckForSingleResult(accessedMembers, acc);
if (accessedMembers != null && accessedMembers.Length != 0)
{
HandleResult(acc, accessedMembers[0]);
return accessedMembers[0];
}
return null;
}
示例4: 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;
}
示例5: HandleImportSymbolMatch
static AbstractType HandleImportSymbolMatch (ImportSymbolNode importSymbolNode,ResolutionContext ctxt)
{
AbstractType ret = null;
var modAlias = importSymbolNode is ModuleAliasNode;
if (modAlias ? importSymbolNode.Type != null : importSymbolNode.Type.InnerDeclaration != null) {
var mods = new List<DModule> ();
var td = modAlias ? importSymbolNode.Type : importSymbolNode.Type.InnerDeclaration;
foreach (var mod in ctxt.ParseCache.LookupModuleName (td.ToString ()))
mods.Add (mod);
if (mods.Count == 0)
ctxt.LogError (new NothingFoundError (importSymbolNode.Type));
else
if (mods.Count > 1) {
var m__ = new List<ISemantic> ();
foreach (var mod in mods)
m__.Add (new ModuleSymbol (mod, importSymbolNode.Type));
ctxt.LogError (new AmbiguityError (importSymbolNode.Type, m__));
}
var bt = mods.Count != 0 ? (AbstractType)new ModuleSymbol (mods [0], td) : null;
//TODO: Is this correct behaviour?
if (!modAlias) {
var furtherId = ResolveFurtherTypeIdentifier (importSymbolNode.Type.ToString (false), new[] {
bt
}, ctxt, importSymbolNode.Type);
ctxt.CheckForSingleResult (furtherId, importSymbolNode.Type);
if (furtherId != null && furtherId.Length != 0)
bt = furtherId [0];
else
bt = null;
}
ret = new AliasedType (importSymbolNode, bt, importSymbolNode.Type);
}
return ret;
}
示例6: 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);
}
//.........这里部分代码省略.........
示例7: Resolve
public static DelegateType Resolve(DelegateDeclaration dg, ResolutionContext ctxt)
{
var returnTypes = Resolve(dg.ReturnType, ctxt);
ctxt.CheckForSingleResult(returnTypes, dg.ReturnType);
if (returnTypes != null && returnTypes.Length != 0)
{
List<AbstractType> paramTypes=null;
if(dg.Parameters!=null &&
dg.Parameters.Count != 0)
{
paramTypes = new List<AbstractType>();
foreach(var par in dg.Parameters)
paramTypes.Add(ResolveSingle(par.Type, ctxt));
}
return new DelegateType(returnTypes[0], dg, paramTypes);
}
return null;
}
示例8: ResolveKey
public static AbstractType ResolveKey(ArrayDecl ad, out int fixedArrayLength, out ISymbolValue keyVal, ResolutionContext ctxt)
{
keyVal = null;
fixedArrayLength = -1;
AbstractType keyType = null;
if (ad.KeyExpression != null)
{
//TODO: Template instance expressions?
var id_x = ad.KeyExpression as IdentifierExpression;
if (id_x != null && id_x.IsIdentifier)
{
var id = new IdentifierDeclaration((string)id_x.Value)
{
Location = id_x.Location,
EndLocation = id_x.EndLocation
};
keyType = TypeDeclarationResolver.ResolveSingle(id, ctxt);
if (keyType != null)
{
var tt = DResolver.StripAliasSymbol(keyType) as MemberSymbol;
if (tt == null ||
!(tt.Definition is DVariable) ||
((DVariable)tt.Definition).Initializer == null)
return keyType;
}
}
try
{
keyVal = Evaluation.EvaluateValue(ad.KeyExpression, ctxt);
if (keyVal != null)
{
// Take the value's type as array key type
keyType = keyVal.RepresentedType;
// It should be mostly a number only that points out how large the final array should be
var pv = Evaluation.GetVariableContents(keyVal, new StandardValueProvider(ctxt)) as PrimitiveValue;
if (pv != null)
{
fixedArrayLength = System.Convert.ToInt32(pv.Value);
if (fixedArrayLength < 0)
ctxt.LogError(ad, "Invalid array size: Length value must be greater than 0");
}
//TODO Is there any other type of value allowed?
}
}
catch { }
}
else
{
var t = Resolve(ad.KeyType, ctxt);
ctxt.CheckForSingleResult(t, ad.KeyType);
if (t != null && t.Length != 0)
return t[0];
}
return keyType;
}