Ejemplo n.º 1
0
        public static ImmutableHashSet <VariableSymbol> GetVariablesToInline(SemanticModel.SemanticModel model)
        {
            var visitor = new InlineDependencyVisitor(model);

            visitor.Visit(model.Root.Syntax);

            return(visitor.shouldInlineCache
                   .Where(kvp => kvp.Value)
                   .Select(kvp => kvp.Key)
                   .ToImmutableHashSet());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks if the specified variable needs to be inlined due to runtime limitations. In cases where the inlining is caused by accessing a variable that must be inlined,
        /// the variable access chain is returned. Otherwise, an empty chain is returned.
        /// </summary>
        /// <param name="model">The semantic model</param>
        /// <param name="variable">The variable to check</param>
        /// <param name="variableAccessChain">The variable access chain that leads to inlining or empty if not available.</param>
        public static bool ShouldInlineVariable(SemanticModel model, VariableDeclarationSyntax variable, out ImmutableArray <string> variableAccessChain)
        {
            variableAccessChain = ImmutableArray <string> .Empty;
            if (model.GetSymbolInfo(variable) is not VariableSymbol variableSymbol)
            {
                // we have errors - assume this is not meant to be inlined
                return(false);
            }

            var visitor = new InlineDependencyVisitor(model, variable);

            visitor.Visit(variable);

            if (!visitor.shouldInlineCache.TryGetValue(variableSymbol, out var shouldInline) || shouldInline != Decision.Inline)
            {
                return(false);
            }

            variableAccessChain = visitor.capturedSequence?.Reverse().ToImmutableArray() ?? ImmutableArray <string> .Empty;
            return(true);
        }