Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / SqlClient / SqlGen / SymbolTable.cs
1 //---------------------------------------------------------------------
2 // <copyright file="SymbolTable.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner  Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
9
10 using System;
11 using System.Collections.Generic;
12 using System.Diagnostics;
13 using System.IO;
14 using System.Text;
15 using System.Data.SqlClient;
16 using System.Data.Metadata.Edm;
17 using System.Data.Common.CommandTrees;
18
19 namespace System.Data.SqlClient.SqlGen
20 {
21     /// <summary>
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.
25     /// 
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>
31     /// </list>
32     /// 
33     /// Symbols represent names <see cref="SqlGenerator.Visit(DbVariableReferenceExpression)"/> to be resolved, 
34     /// or things to be renamed.
35     /// </summary>
36     internal sealed class SymbolTable
37     {
38         private List<Dictionary<string, Symbol>> symbols = new List<Dictionary<string, Symbol>>();
39
40         internal void EnterScope()
41         {
42             symbols.Add(new Dictionary<string, Symbol>(StringComparer.OrdinalIgnoreCase));
43         }
44
45         internal void ExitScope()
46         {
47             symbols.RemoveAt(symbols.Count - 1);
48         }
49
50         internal void Add(string name, Symbol value)
51         {
52             symbols[symbols.Count - 1][name] = value;
53         }
54
55         internal Symbol Lookup(string name)
56         {
57             for (int i = symbols.Count - 1; i >= 0; --i)
58             {
59                 if (symbols[i].ContainsKey(name))
60                 {
61                     return symbols[i][name];
62                 }
63             }
64
65             return null;
66         }
67     }
68 }