-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathNBlock.java
More file actions
57 lines (47 loc) · 1.38 KB
/
NBlock.java
File metadata and controls
57 lines (47 loc) · 1.38 KB
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
57
/**
* Copyright 2009, Google Inc. All rights reserved.
* Licensed to PSF under a Contributor Agreement.
*/
package org.python.indexer.ast;
import org.python.indexer.Indexer;
import org.python.indexer.Scope;
import org.python.indexer.types.NType;
import java.util.ArrayList;
import java.util.List;
public class NBlock extends NNode {
static final long serialVersionUID = -9096405259154069107L;
public List<NNode> seq;
public NBlock(List<NNode> seq) {
this(seq, 0, 1);
}
public NBlock(List<NNode> seq, int start, int end) {
super(start, end);
if (seq == null) {
seq = new ArrayList<NNode>();
}
this.seq = seq;
addChildren(seq);
}
@Override
public NType resolve(Scope scope) throws Exception {
for (NNode n : seq) {
// XXX: This works for inferring lambda return types, but needs
// to be fixed for functions (should be union of return stmt types).
NType returnType = resolveExpr(n, scope);
if (returnType != Indexer.idx.builtins.None) {
setType(returnType);
}
}
return getType();
}
@Override
public String toString() {
return "<Block:" + seq + ">";
}
@Override
public void visit(NNodeVisitor v) {
if (v.visit(this)) {
visitNodeList(seq, v);
}
}
}