summaryrefslogtreecommitdiff
path: root/src/ast/nodes/DottedNameNode.java
blob: 2698b1c6148eb3d1292a4ec8633590d3dc413582 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package ast.nodes;

import java.util.ArrayList;

import semanticanalysis.SemanticError;
import semanticanalysis.SymbolTable;
import ast.types.*;
import org.antlr.v4.runtime.tree.TerminalNode;

/**
 * Node for the `dooted_name` statement of the grammar.
 */
public class DottedNameNode implements Node {

    protected ArrayList<TerminalNode> names;

    public DottedNameNode(ArrayList<TerminalNode> names) {
        this.names = names;
    }

    @Override
    public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) {
        ArrayList<SemanticError> errors = new ArrayList<>();

        for (int i = 0; i < names.size(); ++i) {
            ST.insert(names.get(i).toString(), this.typeCheck(), _nesting, null);
        }

        return errors;
    }

    @Override
    public Type typeCheck() {
        return new ImportType();
    }

    // NOTE: we do not provide code generation for this node in the same way
    // we do not want to do this for the import stm.
    @Override
    public String codeGeneration() {
        return "";
    }

    @Override
    public String toPrint(String prefix) {
        String str = prefix + "DottedName\n";

        prefix += "  ";
        for (var name : names) {
            str += prefix + name.toString() + "\n";
        }

        return str;
    }

}