本文整理汇总了C#中ResolutionContext.LogError方法的典型用法代码示例。如果您正苦于以下问题:C# ResolutionContext.LogError方法的具体用法?C# ResolutionContext.LogError怎么用?C# ResolutionContext.LogError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ResolutionContext
的用法示例。
在下文中一共展示了ResolutionContext.LogError方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: DeduceEponymousTemplate
static AbstractType DeduceEponymousTemplate(EponymousTemplateType ept, ResolutionContext ctxt)
{
if (ept.Definition.Initializer == null) {
ctxt.LogError (ept.Definition, "Can't deduce type from empty initializer!");
return null;
}
// Introduce the deduced params to the current resolution context
ctxt.CurrentContext.IntroduceTemplateParameterTypes(ept);
// Get actual overloads
AbstractType deducedType = null;
deducedType = new MemberSymbol (ept.Definition, Evaluation.EvaluateType (ept.Definition.Initializer, ctxt), null, ept.DeducedTypes); //ept; //Evaluation.EvaluateType (ept.Definition.Initializer, ctxt);
// Undo context-related changes
ctxt.CurrentContext.RemoveParamTypesFromPreferredLocals(ept);
return deducedType;
}
示例3: 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.ResolveSingle(tde.Declaration, ctxt);
// Might be a simple symbol without any applied template arguments that is then passed to an template alias parameter
if (res == null && tde.Declaration is IdentifierDeclaration)
res = TypeDeclarationResolver.ResolveSingle(tde.Declaration as IdentifierDeclaration, ctxt, null, false);
var amb = res as AmbiguousType;
if (amb != null)
{
// Error
res = amb.Overloads[0];
}
var mr = res 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 ?? (ISemantic)mr);
}
else{
if(!hasNonFinalArgument)
hasNonFinalArgument = IsNonFinalArgument(res);
templateArguments.Add(res);
}
}
else
{
ISemantic 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);
v = DResolver.StripValueTypeWrappers(v);
templateArguments.Add(v);
}
}
return templateArguments;
}
示例4: DeduceEponymousTemplate
static AbstractType DeduceEponymousTemplate(EponymousTemplateType ept, ResolutionContext ctxt)
{
if (ept.Definition.Initializer == null &&
ept.Definition.Type == null) {
ctxt.LogError(ept.Definition, "Can't deduce type from empty initializer!");
return null;
}
// Introduce the deduced params to the current resolution context
ctxt.CurrentContext.IntroduceTemplateParameterTypes(ept);
// Get actual overloads
AbstractType deducedType = null;
var def = ept.Definition;
deducedType = new MemberSymbol(def, def.Type != null ?
TypeDeclarationResolver.ResolveSingle(def.Type, ctxt) :
ExpressionTypeEvaluation.EvaluateType(def.Initializer, ctxt), null, ept.DeducedTypes); //ept; //ExpressionTypeEvaluation.EvaluateType (ept.Definition.Initializer, ctxt);
deducedType.Tag = ept.Tag; // Currently requried for proper UFCS resolution - sustain ept's Tag
// Undo context-related changes
ctxt.CurrentContext.RemoveParamTypesFromPreferredLocals(ept);
return deducedType;
}
示例5: GetForeachIteratorType
//.........这里部分代码省略.........
}
var aggregateType = Evaluation.EvaluateType(fe.Aggregate, ctxt);
aggregateType = DResolver.StripMemberSymbols(aggregateType);
if (aggregateType == null)
return null;
// The most common way to do a foreach
if (aggregateType is AssocArrayType)
{
var ar = (AssocArrayType)aggregateType;
return keyIsSearched ? ar.KeyType : ar.ValueType;
}
else if (aggregateType is UserDefinedType)
{
var tr = (UserDefinedType)aggregateType;
if (keyIsSearched || !(tr.Definition is IBlockNode))
continue;
bool foundIterPropertyMatch = false;
#region Foreach over Structs and Classes with Ranges
// Enlist all 'back'/'front' members
var t_l = new List<AbstractType>();
foreach (var n in (IBlockNode)tr.Definition)
if (fe.IsReverse ? n.Name == "back" : n.Name == "front")
t_l.Add(HandleNodeMatch(n, ctxt));
// Remove aliases
var iterPropertyTypes = DResolver.StripAliasSymbols(t_l);
foreach (var iterPropType in iterPropertyTypes)
if (iterPropType is MemberSymbol)
{
foundIterPropertyMatch = true;
var itp = (MemberSymbol)iterPropType;
// Only take non-parameterized methods
if (itp.Definition is DMethod && ((DMethod)itp.Definition).Parameters.Count != 0)
continue;
// Handle its base type [return type] as iterator type
if (itp.Base != null)
r.Add(itp.Base);
foundIterPropertyMatch = true;
}
if (foundIterPropertyMatch)
continue;
#endregion
#region Foreach over Structs and Classes with opApply
t_l.Clear();
r.Clear();
foreach (var n in (IBlockNode)tr.Definition)
if (n is DMethod &&
(fe.IsReverse ? n.Name == "opApplyReverse" : n.Name == "opApply"))
t_l.Add(HandleNodeMatch(n, ctxt));
iterPropertyTypes = DResolver.StripAliasSymbols(t_l);
foreach (var iterPropertyType in iterPropertyTypes)
if (iterPropertyType is MemberSymbol)
{
var mr = (MemberSymbol)iterPropertyType;
var dm = mr.Definition as DMethod;
if (dm == null || dm.Parameters.Count != 1)
continue;
var dg = dm.Parameters[0].Type as DelegateDeclaration;
if (dg == null || dg.Parameters.Count != fe.ForeachTypeList.Length)
continue;
var paramType = Resolve(dg.Parameters[iteratorIndex].Type, ctxt);
if (paramType != null && paramType.Length > 0)
r.Add(paramType[0]);
}
#endregion
}
if (r.Count > 1)
ctxt.LogError(new ResolutionError(curStmt, "Ambigous iterator type"));
return r.Count != 0 ? r[0] : null;
}
}
return null;
}
示例6: HandleClassLikeMatch
static AbstractType HandleClassLikeMatch (DClassLike dc, ResolutionContext ctxt, object typeBase, bool canResolveBase)
{
AbstractType ret;
UserDefinedType udt = null;
var invisibleTypeParams = GetInvisibleTypeParameters (dc, ctxt);
switch (dc.ClassType) {
case DTokens.Struct:
ret = new StructType (dc, typeBase as ISyntaxRegion, invisibleTypeParams);
break;
case DTokens.Union:
ret = new UnionType (dc, typeBase as ISyntaxRegion, invisibleTypeParams);
break;
case DTokens.Class:
udt = new ClassType (dc, typeBase as ISyntaxRegion, null, null, invisibleTypeParams);
ret = null;
break;
case DTokens.Interface:
udt = new InterfaceType (dc, typeBase as ISyntaxRegion, null, invisibleTypeParams);
ret = null;
break;
case DTokens.Template:
if (dc.ContainsAttribute (DTokens.Mixin))
ret = new MixinTemplateType (dc, typeBase as ISyntaxRegion, invisibleTypeParams);
else
ret = new TemplateType (dc, typeBase as ISyntaxRegion, invisibleTypeParams);
break;
default:
ret = null;
ctxt.LogError (new ResolutionError (dc, "Unknown type (" + DTokens.GetTokenString (dc.ClassType) + ")"));
break;
}
if (dc.ClassType == DTokens.Class || dc.ClassType == DTokens.Interface)
ret = canResolveBase ? DResolver.ResolveBaseClasses (udt, ctxt) : udt;
return ret;
}
示例7: 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;
}
示例8: Resolve
public static AbstractType Resolve(ArrayDecl ad, ResolutionContext ctxt)
{
var valueTypes = Resolve(ad.ValueType, ctxt);
ctxt.CheckForSingleResult(valueTypes, ad);
AbstractType valueType = null;
AbstractType keyType = null;
int fixedArrayLength = -1;
if (valueTypes != null && valueTypes.Length != 0)
valueType = valueTypes[0];
ISymbolValue val;
keyType = ResolveKey(ad, out fixedArrayLength, out val, ctxt);
if (keyType == null || (keyType is PrimitiveType &&
((PrimitiveType)keyType).TypeToken == DTokens.Int)) {
if (fixedArrayLength >= 0) {
// D Magic: One might access tuple items directly in the pseudo array declaration - so stuff like Tup[0] i; becomes e.g. int i;
var dtup = DResolver.StripMemberSymbols (valueType) as DTuple;
if (dtup == null)
return new ArrayType (valueType, fixedArrayLength, ad);
if (fixedArrayLength < dtup.Items.Length)
return AbstractType.Get(dtup.Items [fixedArrayLength]);
else {
ctxt.LogError (ad, "TypeTuple only consists of " + dtup.Items.Length + " items. Can't access item at index " + fixedArrayLength);
return null;
}
}
return new ArrayType (valueType, ad);
}
return new AssocArrayType(valueType, keyType, ad);
}
示例9: 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;
}