1 //---------------------------------------------------------------------
2 // <copyright file="SymbolTable.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
11 using System.Collections.Generic;
12 using System.Diagnostics;
15 using System.Data.SqlClient;
16 using System.Data.Metadata.Edm;
17 using System.Data.Common.CommandTrees;
19 namespace System.Data.SqlClient.SqlGen
22 /// The symbol table is quite primitive - it is a stack with a new entry for
23 /// each scope. Lookups search from the top of the stack to the bottom, until
24 /// an entry is found.
26 /// The symbols are of the following kinds
27 /// <list type="bullet">
28 /// <item><see cref="Symbol"/> represents tables (extents/nested selects/unnests)</item>
29 /// <item><see cref="JoinSymbol"/> represents Join nodes</item>
30 /// <item><see cref="Symbol"/> columns.</item>
33 /// Symbols represent names <see cref="SqlGenerator.Visit(DbVariableReferenceExpression)"/> to be resolved,
34 /// or things to be renamed.
36 internal sealed class SymbolTable
38 private List<Dictionary<string, Symbol>> symbols = new List<Dictionary<string, Symbol>>();
40 internal void EnterScope()
42 symbols.Add(new Dictionary<string, Symbol>(StringComparer.OrdinalIgnoreCase));
45 internal void ExitScope()
47 symbols.RemoveAt(symbols.Count - 1);
50 internal void Add(string name, Symbol value)
52 symbols[symbols.Count - 1][name] = value;
55 internal Symbol Lookup(string name)
57 for (int i = symbols.Count - 1; i >= 0; --i)
59 if (symbols[i].ContainsKey(name))
61 return symbols[i][name];