1
3 package jminusminus;
4
5
9 class JVariableDeclarator extends JAST {
10 private String name;
12
13 private Type type;
15
16 private JExpression initializer;
18
19
27 public JVariableDeclarator(int line, String name, Type type, JExpression initializer) {
28 super(line);
29 this.name = name;
30 this.type = type;
31 this.initializer = initializer;
32 }
33
34
39 public String name() {
40 return name;
41 }
42
43
48 public Type type() {
49 return type;
50 }
51
52
57 public void setType(Type type) {
58 this.type = type;
59 }
60
61
66 public JExpression initializer() {
67 return initializer;
68 }
69
70
75 public void setInitializer(JExpression initializer) {
76 this.initializer = initializer;
77 }
78
79
82 public JVariableDeclarator analyze(Context context) {
83 return this;
85 }
86
87
90 public void codegen(CLEmitter output) {
91 }
93
94
97 public void toJSON(JSONElement json) {
98 JSONElement e = new JSONElement();
99 json.addChild("JVariableDeclarator:" + line, e);
100 e.addAttribute("name", name());
101 e.addAttribute("type", type == null ? "" : type.toString());
102 if (initializer != null) {
103 JSONElement e1 = new JSONElement();
104 e.addChild("Initializer", e1);
105 initializer.toJSON(e1);
106 }
107 }
108 }
109