public AstMetaProperty(MetaVisibility visibility, AstExpression optionalType, AstIdentifier name, IReadOnlyList <AstMetaPropertyDefinition> definitions) { Visibility = visibility; OptionalType = optionalType; Name = name; Definitions = definitions; }
public AstMetaProperty(MetaVisibility visibility, AstExpression optionalType, AstIdentifier name, params AstMetaPropertyDefinition[] definitions) { Visibility = visibility; OptionalType = optionalType; Name = name; Definitions = definitions; }
public PartialExpression TryResolveLocalIdentifier(AstIdentifier id) { // Check if it is a local variable for (int i = VariableScopeStack.Count - 1; i >= 0; i--) { Variable var; if (VariableScopeStack[i].Variables.TryGetValue(id.Symbol, out var)) { return(var.IsConstant && var.OptionalValue != null ? (PartialExpression) new PartialValue(var.OptionalValue) : new PartialVariable(id.Source, var)); } } foreach (var lambda in Lambdas) { for (int i = 0; i < lambda.Parameters.Length; i++) { if (lambda.Parameters[i].Name == id.Symbol) { return(new PartialParameter(id.Source, lambda, i)); } } } for (int i = 0; i < Function.Parameters.Length; i++) { if (Function.Parameters[i].Name == id.Symbol) { return(new PartialParameter(id.Source, Function, i)); } } return(null); }
public PartialExpression TryResolveCapturedLocalIdentifier(BlockBase block, AstIdentifier id) { var db = block.TryFindDrawBlockParent(); if (db != null) { var em = db.Method; Variable var; if (db.CapturedLocals.TryGetValue(id.Symbol, out var)) { return(var.IsConstant && var.OptionalValue != null ? new PartialValue(var.OptionalValue) : var.ValueType is FixedArrayType ? new PartialValue(new AddressOf(new CapturedLocal(id.Source, em, var))) : new PartialValue(new CapturedLocal(id.Source, em, var))); } for (int i = 0; i < em.Parameters.Length; i++) { if (em.Parameters[i].Name == id.Symbol) { return(em.Parameters[i].Type is FixedArrayType ? new PartialValue(new AddressOf(new CapturedArgument(id.Source, em, i), em.Parameters[i].Modifier == ParameterModifier.Const ? AddressType.Const : 0)) : new PartialValue(new CapturedArgument(id.Source, em, i))); } } } return(null); }
public AstLiteral(string comment, IReadOnlyList <AstAttribute> attrs, AstIdentifier name, AstExpression optionalValue) { DocComment = comment; Attributes = attrs ?? AstAttribute.Empty; Name = name; OptionalValue = optionalValue; }
DataType TryResolveDataTypeIdentifier(AstIdentifier identifier) { var pi = NameResolver.TryResolveMemberRecursive(Namescope, identifier, null) ?? NameResolver.TryResolveUsingNamespace(Namescope, identifier, null); return((pi as PartialType)?.Type); }
public AstFixedArrayDeclaration(AstFixedArray type, AstIdentifier name, AstExpression value) : base(name.Source) { Type = type; Name = name; OptionalValue = value; }
public AstForeach(Source src, AstExpression dt, AstIdentifier iterator, AstExpression collection, AstStatement body) : base(src) { ElementType = dt; ElementName = iterator; Collection = collection; OptionalBody = body; }
public PartialExpression TryResolveMemberRecursive(Namescope nameScope, AstIdentifier id, int?typeParamCount) { return(TryResolveMember(nameScope, id, typeParamCount, null) ?? (nameScope.IsRoot ? null : TryResolveMemberRecursive(nameScope.Parent, id, typeParamCount))); }
public AstConstraint(AstIdentifier parameter, AstConstraintType type, IReadOnlyList <AstExpression> baseTypes, Source optionalCtor = null) { Parameter = parameter; Type = type; BaseTypes = baseTypes; OptionalConstructor = optionalCtor; }
public PartialExpression TryResolveUsingNamespace(Namescope namescope, AstIdentifier id, int?typeParamCount) { var usings = TryGetUsings(namescope, id.Source); if (usings == null || usings.Namespaces.Count == 0) { return(null); } var pil = new List <PartialExpression>(); foreach (var ns in usings.Namespaces) { var pi = TryResolveMember(ns, id, typeParamCount, null); if (pi == null) { continue; } if (pi.ExpressionType == PartialExpressionType.Type || pi.ExpressionType == PartialExpressionType.Block) { pil.Add(pi); } } if (pil.Count == 1) { return(pil[0]); } if (pil.Count > 1) { // Check if it is an overloadable generic type if (pil[0].ExpressionType == PartialExpressionType.Type) { var parent = (pil[0] as PartialType).Type.Parent; bool allEqual = true; for (int i = 1; i < pil.Count; i++) { if (!(pil[i] is PartialType) || (pil[i] as PartialType).Type.Parent != parent) { allEqual = false; break; } } if (allEqual) { return(pil[0]); } } Log.Error(id.Source, ErrorCode.E3109, id.GetParameterizedSymbol(typeParamCount).Quote() + " is ambiguous" + SuggestCandidates(pil)); return(PartialExpression.Invalid); } return(null); }
static string SuggestGlobalAlternatives(Compiler compiler, AstIdentifier id, int?typeParamCount, IEnumerable <string> extraSymbols) { var msg = "There is nothing named " + id.GetParameterizedSymbol(typeParamCount).Quote() + " accessible in this scope. "; if (id.Symbol.Length < 2) { return(msg); } var similars = FindSimilarSymbols(compiler, id.Symbol); if (extraSymbols != null) { similars = FindSimilarSymbols(extraSymbols, id.Symbol).Concat(similars); } if (similars.Any()) { msg += SuggestDidYouMisspell(compiler, id.Symbol, similars); return(msg + " Could you be missing a package reference?"); } else { msg += "Are you missing a package reference?"; } return(msg); }
public AstReqStatement(Source src, uint offset, AstIdentifier name, AstExpression type, string tag) : base(src) { Name = name; Type = type; Offset = offset; Tag = tag; }
public AstDelegate(string comment, IReadOnlyList <AstAttribute> attrs, Modifiers modifiers, string cond, AstExpression retType, AstIdentifier name, IReadOnlyList <AstParameter> parameters, AstGenericSignature optionalGenericSig) : base(comment, attrs, modifiers, cond, name, null) { ReturnType = retType; Parameters = parameters; OptionalGenericSignature = optionalGenericSig; }
public static void SetIdentifier(this IAstIdentifierSite identifierSite, AstIdentifier identifier) { if (!identifierSite.TrySetIdentifier(identifier)) { throw new InternalErrorException( "Identifier is already set or null."); } }
public AstParameter(IReadOnlyList <AstAttribute> attributes, ParameterModifier modifier, AstExpression optionalType, AstIdentifier name, AstExpression value = null) { Attributes = attributes ?? AstAttribute.Empty; OptionalType = optionalType; Name = name; OptionalValue = value; Modifier = modifier; }
public AstEvent(string comment, IReadOnlyList <AstAttribute> attrs, Modifiers modifiers, string cond, AstExpression delegateType, AstExpression optionalInterfaceType, AstIdentifier name, AstAccessor add, AstAccessor remove) : base(comment, attrs, modifiers, cond) { DelegateType = delegateType; OptionalInterfaceType = optionalInterfaceType; Name = name; Add = add; Remove = remove; }
public static AstSymbol?FindSymbol(this AstSymbolTable symbolTable, AstIdentifier identifier, AstSymbolKind kind = AstSymbolKind.NotSet) { if (kind == AstSymbolKind.NotSet) { kind = identifier.IdentifierKind.ToSymbolKind(); } return(symbolTable.FindSymbol(identifier.SymbolName.CanonicalName, kind)); }
private static EvalValue CalcIdentifier(IEnvironment env, AstIdentifier ast) { var val = env.Get(ast.name); if (val == null) { throw new RunTimeException("未定义的标识符", ast); } return(val); }
public static string GetTypeMemberNotFoundError(this Compiler compiler, AstIdentifier id, DataType dt) { return(dt.FullName.Quote() + " does not contain a member called " + id.Symbol.Quote() + ". " + SuggestDidYouMisspell( compiler, id.Symbol, FindSimilarSymbols( dt.EnumerateMembers().Select(x => x.UnoName).Concat( dt.NestedTypes.Select(x => x.FullName)).ToArray(), id.Symbol)) + "Could you be missing a package reference?"); }
public PartialExpression TryResolveMember(Namescope namescope, AstIdentifier id, int?typeParamCount, AstExpression qualifier) { var result = TryGetMemberCached(namescope, id.Symbol, typeParamCount); if (result != null) { var gt = result as GenericParameterType; if (gt != null) { return(qualifier == null ? new PartialType(id.Source, gt) : null); } var dt = result as DataType; if (dt != null) { return(dt.IsAccessibleFrom(id.Source) ? new PartialType(id.Source, dt) : null); } var block = result as Block; if (block != null) { return(block.IsAccessibleFrom(id.Source) ? new PartialBlock(id.Source, block) : null); } var ns = result as Namespace; if (ns != null) { return(ns.IsAccessibleFrom(id.Source) ? new PartialNamespace(id.Source, ns) : null); } } var ndt = namescope as DataType; if (ndt != null && qualifier == null) { ndt.AssignBaseType(); if (ndt.Base != null) { return(TryResolveMember(ndt.Base, id, typeParamCount, null)); } } return(null); }
public static string GetNamespaceMemberNotFoundError(this Compiler compiler, AstIdentifier id, Namespace ns) { return((ns.IsRoot ? "No such type or namespace " : ns.FullName.Quote() + " does not contain type or namespace " ) + id.Symbol.Quote() + ". " + SuggestDidYouMisspell( compiler, id.Symbol, FindSimilarSymbols( ns.Types.Select(x => x.UnoName).Concat( ns.Namespaces.Select(x => x.FullName)).ToArray(), id.Symbol)) + "Could you be missing a package reference?"); }
public AstIdentifier[] ReadIdentifiers() { int len = Read7BitEncodedInt() - 1; if (len == -1) { return(null); } var result = new AstIdentifier[len]; for (int i = 0; i < len; i++) { result[i] = ReadIdentifier(); } return(result); }
public AstClass( string comment, IReadOnlyList <AstAttribute> attrs, Modifiers modifiers, string cond, AstClassType type, AstIdentifier name, IReadOnlyList <AstExpression> bases, AstGenericSignature optionalGenericSig, IReadOnlyList <AstBlockMember> members, IReadOnlyList <AstExpression> swizzlers) : base(comment, attrs, modifiers, cond, name, members) { Type = type; Bases = bases; Swizzlers = swizzlers; OptionalGeneric = optionalGenericSig; }
public static string GetUnresolvedIdentifierError(this Compiler compiler, AstIdentifier id, int?typeParamCount, IEnumerable <string> extraSymbols = null) { string msg = "There is no identifier named " + id.GetParameterizedSymbol(typeParamCount).Quote() + " accessible in this scope. "; if (compiler.Environment.SkipVerboseErrors) { return(msg); } var syms = FindMatchingSymbols(compiler, id.Symbol).ToArray(); if (syms.Length > 0) { return(SuggestAlternatives(compiler, msg, syms, true)); } else { return(SuggestGlobalAlternatives(compiler, id, typeParamCount, extraSymbols)); } }
public bool TrySetIdentifier(AstIdentifier identifier) { Ast.Guard(identifier.IdentifierKind == AstIdentifierKind.Module, "Identifier must be of kind Module"); return(Ast.SafeSet(ref _identifier, identifier)); }
public PartialExpression TryResolveTypeMember(DataType dt, AstIdentifier id, int?typeParamCount, AstExpression qualifier, Expression instance) { var result = NameResolver.TryGetTypeMemberCached(dt, id.Symbol, typeParamCount); if (result == null || dt.Methods.Count == 1 && dt.Methods[0].GenericType == dt) { return(null); } if (dt.IsFlattenedDefinition) { return(PartialError(id.Source, ErrorCode.I0000, "Invalid member-access on non-parameterized type")); } var methods = result as IReadOnlyList <Method>; if (methods != null) { return(new PartialMethodGroup(id.Source, instance, !AllowStaticContext(qualifier, instance), methods)); } var literal = result as Literal; if (literal != null) { if (AllowStaticContext(qualifier, instance)) { ILVerifier.VerifyConstUsage(id.Source, literal, Function); return(new PartialValue(new Constant(id.Source, literal.ReturnType, literal.Value is AstExpression ? Compiler.CompileConstant((AstExpression)literal.Value, literal.DeclaringType, literal.ReturnType).Value : literal.Value))); } return(PartialError(id.Source, ErrorCode.E0000, literal.Quote() + " is a constant -- qualify with the type name")); } var field = result as Field; if (field != null) { if (field.IsStatic) { if (instance != null) { return(AllowStaticContext(qualifier, instance) ? new PartialField(id.Source, field, null) : PartialError(id.Source, ErrorCode.E3117, field.Quote() + " is static -- qualify with the type name")); } } else { if (instance == null) { return(qualifier == null && TryResolveDataTypeIdentifier(id) == field.ReturnType ? new PartialType(id.Source, field.ReturnType) : PartialError(id.Source, ErrorCode.E3118, field.Quote() + " is non-static and cannot be accessed from a static context")); } } return(new PartialField(id.Source, field, instance)); } var ev = result as Event; if (ev != null) { if (ev.IsStatic) { if (instance != null) { return(AllowStaticContext(qualifier, instance) ? new PartialEvent(id.Source, ev, null) : PartialError(id.Source, ErrorCode.E3119, ev.Quote() + " is static -- qualify with the type name")); } } else { if (instance == null) { return(qualifier == null && TryResolveDataTypeIdentifier(id) == ev.ReturnType ? new PartialType(id.Source, ev.ReturnType) : PartialError(id.Source, ErrorCode.E3120, ev.Quote() + " is non-static and cannot be accessed from a static context")); } } return(new PartialEvent(id.Source, ev, instance)); } var prop = result as Property; if (prop != null) { if (prop.IsStatic) { if (instance != null) { return(AllowStaticContext(qualifier, instance) ? new PartialProperty(id.Source, prop, null) : PartialError(id.Source, ErrorCode.E3121, prop.Quote() + " is static -- qualify with the type name")); } } else { if (instance == null) { return(qualifier == null && TryResolveDataTypeIdentifier(id) == prop.ReturnType ? new PartialType(id.Source, prop.ReturnType) : PartialError(id.Source, ErrorCode.E3122, prop.Quote() + " is non-static and cannot be accessed from a static context")); } } return(new PartialProperty(id.Source, prop, instance)); } var genericParam = result as GenericParameterType; if (genericParam != null) { return(qualifier == null ? new PartialType(id.Source, genericParam) : null); } var innerType = result as DataType; var innerBlock = result as Block; if (innerType != null || innerBlock != null) { return(AllowStaticContext(qualifier, instance) ? (innerType != null ? (PartialExpression) new PartialType(id.Source, innerType) : new PartialBlock(id.Source, innerBlock)) : PartialError(id.Source, ErrorCode.E0000, "Cannot reference block or type " + result.Quote() + " through an expression -- qualify with the type name")); } return(result is List <object> ?PartialError(id.Source, ErrorCode.E0000, (dt + "." + id.GetParameterizedSymbol(typeParamCount)).Quote() + " is ambiguous. This can be resolved using an explicit cast to a more specific interface type") : result as PartialExpression ?? PartialError(id.Source, ErrorCode.I0000, "Unknown type member: " + result)); }
protected AstBlockBase(string comment, IReadOnlyList <AstAttribute> attributes, Modifiers modifiers, string cond, AstIdentifier name, IReadOnlyList <AstBlockMember> members) : base(comment, attributes, modifiers, cond) { Name = name ?? new AstInvalid(Source.Unknown); Members = members; }
public AstEnum(string comment, IReadOnlyList <AstAttribute> attrs, Modifiers modifiers, string cond, AstIdentifier name, AstExpression optionalBaseType, IReadOnlyList <AstLiteral> literals) : base(comment, attrs, modifiers, cond, name, null) { OptionalBaseType = optionalBaseType; Literals = literals; }
public AstLocal(AstIdentifier name) : base(name.Source) { Name = name; }