private void AddCycleInformation(Stack <DeclaredSymbol> symbolStack, DeclaredSymbol referencedDeclaration, IDictionary <SyntaxBase, ImmutableArray <DeclaredSymbol> > shortestCycleBySyntax) { var cycle = symbolStack .TakeWhile(x => x != referencedDeclaration) .Concat(new [] { referencedDeclaration }) .Reverse() .ToImmutableArray(); var cyclicSyntaxBySymbol = cycle .SelectMany(s => declarationAccessDict[s]) .ToLookup(s => bindings[s]); foreach (var symbol in cycle) { foreach (var syntax in cyclicSyntaxBySymbol[symbol]) { if (shortestCycleBySyntax.TryGetValue(syntax, out var otherCycle) && otherCycle.Length <= cycle.Length) { // we've already found a shorter cycle continue; } shortestCycleBySyntax[syntax] = cycle; } } }
private void EmitDependsOn(DeclaredSymbol declaredSymbol) { var dependencies = context.ResourceDependencies[declaredSymbol]; if (!dependencies.Any()) { return; } writer.WritePropertyName("dependsOn"); writer.WriteStartArray(); // need to put dependencies in a deterministic order to generate a deterministic template foreach (var dependency in dependencies.OrderBy(x => x.Name)) { switch (dependency) { case ResourceSymbol resourceDependency: var typeReference = EmitHelpers.GetTypeReference(resourceDependency); emitter.EmitResourceIdReference(resourceDependency.DeclaringResource, typeReference); break; case ModuleSymbol moduleDependency: emitter.EmitModuleResourceIdExpression(moduleDependency); break; default: throw new InvalidOperationException($"Found dependency '{dependency.Name}' of unexpected type {dependency.GetType()}"); } } writer.WriteEndArray(); }
private void Substitute(DeclaredSymbol localSymbol, Dictionary <string, Expr> symbolExprs, bool src) { if (!(localSymbol is DeclaredVariableSymbol localVarSymbol)) { return; } foreach ((string _, DeclaredSymbol symbol) in src ? this.srcSymbols : this.dstSymbols) { Expr replacement = localSymbol.GetInitSymbolValue(symbolExprs); switch (symbol) { case DeclaredVariableSymbol var: var.SymbolicInitializer = var.SymbolicInitializer?.Substitute(localSymbol.Identifier, replacement); break; case DeclaredArraySymbol arr: // TODO break; case DeclaredFunctionSymbol f: // TODO break; } } }
private SymbolKind SelectSymbolKind(DeclaredSymbol symbol) { switch (symbol) { case ImportedNamespaceSymbol _: return(SymbolKind.Namespace); case ParameterSymbol _: return(SymbolKind.Field); case VariableSymbol _: return(SymbolKind.Variable); case ResourceSymbol resource: return(SymbolKind.Object); case ModuleSymbol module: return(SymbolKind.Module); case OutputSymbol output: return(SymbolKind.Interface); default: return(SymbolKind.Key); } }
private DocumentSymbol CreateDocumentSymbol(DeclaredSymbol symbol, ImmutableArray <int> lineStarts) => new DocumentSymbol { Name = symbol.Name, Kind = SelectSymbolKind(symbol), Detail = FormatDetail(symbol), Range = symbol.DeclaringSyntax.ToRange(lineStarts), // use the name node span with fallback to entire declaration span SelectionRange = symbol.NameSyntax.ToRange(lineStarts) };
public Members(DeclaredSymbol symbol, SymbolCompletionState state, ImmutableArray <Symbol> nonTypeMembers, ImmutableArray <NamedTypeSymbol> typeMembers) { Debug.Assert(!nonTypeMembers.IsDefault); Debug.Assert(!typeMembers.IsDefault); Debug.Assert(!nonTypeMembers.Any(s => s is ITypeSymbol)); Debug.Assert(!typeMembers.Any(s => !(s is ITypeSymbol))); _symbol = symbol; _state = state; this.NamedNonTypeMembers = nonTypeMembers.WhereAsArray(m => m.Name != null); this.NamedTypeMembers = typeMembers.WhereAsArray(m => m.Name != null); this.AnonymousNonTypeMembers = nonTypeMembers.WhereAsArray(m => m.Name == null); this.AnonymousTypeMembers = typeMembers.WhereAsArray(m => m.Name == null); }
protected void CompareSymbols(Dictionary <string, DeclaredSymbol> srcSymbols, Dictionary <string, DeclaredSymbol> dstSymbols) { Log.Debug("Testing declarations..."); foreach ((string identifier, DeclaredSymbol srcSymbol) in srcSymbols) { if (identifier.StartsWith("tmp__")) { continue; } if (!dstSymbols.ContainsKey(identifier)) { this.Issues.AddWarning(new MissingDeclarationWarning(srcSymbol.Specifiers, srcSymbol.Declarator)); continue; } DeclaredSymbol dstSymbol = dstSymbols[identifier]; if (srcSymbol.Specifiers != dstSymbol.Specifiers) { this.Issues.AddWarning(new DeclSpecsMismatchWarning(dstSymbol.Declarator, srcSymbol.Specifiers, dstSymbol.Specifiers)); } var declComparer = new DeclNodeComparer(srcSymbol, dstSymbol); this.Issues.Add(declComparer.Compare(srcSymbol.Declarator, dstSymbol.Declarator)); } foreach (string identifier in dstSymbols.Keys.Except(srcSymbols.Keys)) { if (!identifier.StartsWith("tmp__")) { DeclaredSymbol extra = dstSymbols[identifier]; this.Issues.AddWarning(new ExtraDeclarationWarning(extra.Specifiers, extra.Declarator)); } } if (!this.Issues.NoSeriousIssues) { Log.Error("Failed to match found declarations to all expected declarations."); } else { Log.Debug("Matched all expected top-level declarations."); } }
private Dictionary <string, DeclaredSymbol> GetDeclaredSymbols(DeclStatNode node) { var symbols = new Dictionary <string, DeclaredSymbol>(); foreach (DeclNode decl in node.DeclaratorList.Declarators) { var symbol = DeclaredSymbol.From(node.Specifiers, decl); if (symbol is DeclaredFunctionSymbol df && symbols.ContainsKey(df.Identifier)) { if (!df.AddOverload(df.FunctionDeclarator)) { throw new SemanticErrorException($"Multiple overloads with same parameters found for function: {df.Identifier}", decl.Line); } } symbols.Add(decl.Identifier, symbol); } return(symbols); }
public SourceMemberContainerTypeSymbol( DeclaredSymbol containingSymbol, MergedDeclaration declaration, DiagnosticBag diagnostics) { _containingSymbol = containingSymbol; _declaration = declaration; if (declaration.Kind != null) { _modelObject = declaration.GetModelObject(containingSymbol?.ModelObject as MutableObjectBase, containingSymbol.ModelBuilder, diagnostics); Debug.Assert(_modelObject != null); } foreach (var singleDeclaration in declaration.Declarations) { diagnostics.AddRange(singleDeclaration.Diagnostics); } _state = SymbolCompletionState.Create(containingSymbol.Language); }
private string FormatDetail(DeclaredSymbol symbol) { switch (symbol) { case ParameterSymbol parameter: return(parameter.Type.Name); case VariableSymbol variable: return(variable.Type.Name); case ResourceSymbol resource: return(resource.Type.Name); case OutputSymbol output: return(output.Type.Name); default: return(string.Empty); } }
public ResourceDependency(DeclaredSymbol resource, SyntaxBase?indexExpression, ResourceDependencyKind kind) { this.Resource = resource; this.IndexExpression = indexExpression; this.Kind = kind; }
public ResourceDependency(DeclaredSymbol resource, SyntaxBase? indexExpression) { this.Resource = resource; this.IndexExpression = indexExpression; }
protected virtual void SetPropertyValues(DeclaredSymbol symbol, DiagnosticBag diagnostics, CancellationToken cancellationToken) { var properties = this.GetProperties(null, cancellationToken); var modelObject = (MutableObjectBase)symbol.ModelObject; if (modelObject == null) { return; } foreach (var boundProperty in properties) { string name = boundProperty.Name; var prop = modelObject.MGetProperty(name); if (prop == null) { diagnostics.Add(ModelErrorCode.ERR_PropertyDoesNotExist, boundProperty.Location, modelObject, name); continue; } //if (prop.IsBaseScope) continue; var propValues = ArrayBuilder <BoundValues> .GetInstance(); boundProperty.AddValues(propValues, boundProperty, boundProperty, cancellationToken); foreach (var boundValue in propValues) { //if (boundValue is BoundSymbolDef) continue; // TODO:MetaDslx - prevent values to be added multiple times if (prop.IsCollection) { var values = boundValue.Values.Select(v => v is Symbol symbolValue ? symbolValue.ModelObject : v).ToArray(); try { modelObject.MAddRange(prop, values); } catch (ModelException me) { diagnostics.Add(ModelErrorCode.ERR_CannotAddValuesToProperty, this.Location, prop, modelObject, me.ToString()); } } else { if (boundValue.Values.Length == 1) { var value = boundValue.Values[0]; if (value is Symbol symbolValue) { value = symbolValue.ModelObject; } try { modelObject.MSet(prop, value); } catch (ModelException me) { diagnostics.Add(ModelErrorCode.ERR_CannotSetValueToProperty, this.Location, prop, modelObject, me.ToString()); } } else if (boundValue.Values.Length > 1) { diagnostics.Add(ModelErrorCode.ERR_CannotAddMultipleValuesToNonCollectionProperty, this.Location, prop, modelObject); } } } propValues.Free(); } }
public MembersBuilder(DeclaredSymbol symbol, SymbolCompletionState state) { _symbol = symbol; _state = state; }
public SourceNamedTypeSymbol(DeclaredSymbol containingSymbol, MergedDeclaration declaration, DiagnosticBag diagnostics) : base(containingSymbol, declaration, diagnostics) { Debug.Assert(!declaration.IsImplicit && !declaration.IsSubmission && !declaration.IsScript); }
public DeclNodeComparer(DeclaredSymbol sym1, DeclaredSymbol sym2) { this.Symbol1 = sym1; this.Symbol2 = sym2; }
private static string?TryGetDescriptionMarkdown(SymbolResolutionResult result, DeclaredSymbol symbol) { if (symbol.DeclaringSyntax is StatementSyntax statementSyntax && SemanticModelHelper.TryGetDescription(result.Context.Compilation.GetEntrypointSemanticModel(), statementSyntax) is { } description) { return(description); } return(null); }
public SourceAnonymousTypeSymbol(DeclaredSymbol containingSymbol, MergedDeclaration declaration, DiagnosticBag diagnostics) : base(containingSymbol, declaration, diagnostics) { }
private TypeSymbol HandleSymbolType(string symbolName, TextSpan symbolNameSpan, DeclaredSymbol declaringType) { // symbols are responsible for doing their own type checking // the error from that should not be propagated to expressions that have type errors // unless we're dealing with a cyclic expression error, then propagate away! if (declaringType.Type is ErrorTypeSymbol errorType) { // replace the original error with a different one // we may consider suppressing this error in the future as well return(new ErrorTypeSymbol(DiagnosticBuilder.ForPosition(symbolNameSpan).ReferencedSymbolHasErrors(symbolName))); } return(declaringType.Type); }
public SourceDeclaration(DeclaredSymbol symbol, MergedDeclaration declaration, SymbolCompletionState state) { _symbol = symbol; _state = state; _declaration = declaration; }