public override void EnterExpressionName([NotNull] Java9Parser.ExpressionNameContext context) { var first = context.GetChild(0); if (first is Java9Parser.IdentifierContext) { var sy = first.GetChild(0) as TerminalNodeImpl; bool is_statement = false; for (var p = first.Parent; p != null; p = p.Parent) { if (p is Java9Parser.StatementContext) { is_statement = true; break; } } if (is_statement) { var id_name = sy.GetText(); var scope = GetScope(NearestScope(context)); var list_s = scope.LookupType(id_name); if (list_s.Any()) { var ref_list = new List <CombinedScopeSymbol>(); foreach (var s in list_s) { ref_list.Add((CombinedScopeSymbol) new RefSymbol(sy.Symbol, s)); } if (ref_list.Any()) { _pd.Attributes[first] = ref_list; } } } } else if (first is Java9Parser.AmbiguousNameContext) { //bool is_statement = false; //for (var p = first.Parent; p != null; p = p.Parent) //{ // if (p is Java9Parser.StatementContext) // { // is_statement = true; // break; // } //} //if (is_statement) //{ // var id_name = first.GetText(); // var s = _current_scope.Peek().resolve(id_name); // if (s != null) _symbols[first] = s; //} } }
public override void ExitExpressionName([NotNull] Java9Parser.ExpressionNameContext context) { // Synthesize attributes. var first = context.GetChild(0); if (first is Java9Parser.IdentifierContext) { bool is_statement = false; for (var p = first.Parent; p != null; p = p.Parent) { if (p is Java9Parser.StatementContext) { is_statement = true; break; } if (p is Java9Parser.BlockStatementContext) { is_statement = true; break; } } if (is_statement) { var id_name = first.GetText(); if (id_name == "this") { var scope = GetScope(NearestScope(context)); var sc = scope; for (; sc != null; sc = sc.EnclosingScope) { if (sc is ClassSymbol) { break; } } if (sc != null) { _pd.Attributes[first] = new List <CombinedScopeSymbol>() { (CombinedScopeSymbol)sc } } ; } else { var scope = GetScope(NearestScope(context)); var sy = first.GetChild(0) as TerminalNodeImpl; var list_s = scope.LookupType(id_name); var ref_list = new List <CombinedScopeSymbol>(); foreach (var s in list_s) { ref_list.Add((CombinedScopeSymbol) new RefSymbol(sy.Symbol, s)); } if (ref_list.Any()) { _pd.Attributes[first] = ref_list; } } } } else if (first is Java9Parser.ExpressionNameContext) { bool is_statement = false; for (var p = first.Parent; p != null; p = p.Parent) { if (p is Java9Parser.StatementContext) { is_statement = true; break; } if (p is Java9Parser.BlockStatementContext) { is_statement = true; break; } } if (is_statement) { _pd.Attributes.TryGetValue(first, out IList <CombinedScopeSymbol> list_v); var ref_list = new List <CombinedScopeSymbol>(); foreach (var v in list_v) { if (v is SymbolWithScope) { var sy = context.GetChild(2) as TerminalNodeImpl; var id_name = context.GetChild(2).GetText(); var w = v as SymbolWithScope; var list_s = w.LookupType(id_name); if (list_s == null || !list_s.Any()) { continue; } foreach (var s in list_s) { ref_list.Add((CombinedScopeSymbol) new RefSymbol(sy.Symbol, s)); } } } if (ref_list.Any()) { _pd.Attributes[context.GetChild(0)] = ref_list; _pd.Attributes[context] = ref_list; } } } }