Skip to content

Commit da98dc7

Browse files
committed
SONARPY-208 Symbol table
1 parent f4cebed commit da98dc7

7 files changed

Lines changed: 656 additions & 0 deletions

File tree

python-squid/src/main/java/org/sonar/python/PythonVisitorContext.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,21 @@
2121

2222
import com.sonar.sslr.api.AstNode;
2323
import com.sonar.sslr.api.RecognitionException;
24+
import org.sonar.python.semantic.SymbolTable;
25+
import org.sonar.python.semantic.SymbolTableBuilderVisitor;
2426

2527
public class PythonVisitorContext {
2628

2729
private final AstNode rootTree;
2830
private final PythonFile pythonFile;
2931
private final RecognitionException parsingException;
32+
private SymbolTable symbolTable = null;
3033

3134
public PythonVisitorContext(AstNode rootTree, PythonFile pythonFile) {
3235
this(rootTree, pythonFile, null);
36+
SymbolTableBuilderVisitor symbolTableBuilderVisitor = new SymbolTableBuilderVisitor();
37+
symbolTableBuilderVisitor.scanFile(this);
38+
symbolTable = symbolTableBuilderVisitor.symbolTable();
3339
}
3440

3541
public PythonVisitorContext(PythonFile pythonFile, RecognitionException parsingException) {
@@ -54,4 +60,7 @@ public RecognitionException parsingException() {
5460
return parsingException;
5561
}
5662

63+
public SymbolTable symbolTable() {
64+
return symbolTable;
65+
}
5766
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* SonarQube Python Plugin
3+
* Copyright (C) 2011-2017 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package org.sonar.python.semantic;
21+
22+
import com.sonar.sslr.api.AstNode;
23+
24+
import java.util.Set;
25+
26+
public interface Symbol {
27+
28+
String name();
29+
30+
AstNode scopeTree();
31+
32+
Set<AstNode> writeUsages();
33+
34+
Set<AstNode> readUsages();
35+
}
36+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* SonarQube Python Plugin
3+
* Copyright (C) 2011-2017 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package org.sonar.python.semantic;
21+
22+
import com.sonar.sslr.api.AstNode;
23+
24+
import java.util.Set;
25+
26+
public interface SymbolTable {
27+
28+
Set<Symbol> symbols(AstNode scopeTree);
29+
30+
}

0 commit comments

Comments
 (0)