blob: d76a8ae4ef96dc06066182bf8908f74d55eaf9b6 (
plain) (
blame)
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
58
59
60
61
62
63
64
65
66
67
68
|
package com.modulus.qbar.core;
import java.util.Arrays;
import java.util.Collections;
import com.modulus.dataread.expressions.Statement;
import com.modulus.qbar.core.exceptions.ParseException;
import com.modulus.qbar.core.interpreter.QBInterpreter;
import com.modulus.qbar.core.parser.QBParser;
import com.modulus.qbar.lang.QBArrayList;
import com.modulus.qbar.lang.QBList;
public class QBSyntheticStruct extends QBStruct{
private static final long serialVersionUID = -1080935988322343396L;
// This maps an instance variable to its default value, if the struct is null
// the instance will be null defaultly
// private Map<String, QBStruct> instanceVars = new HashMap<String, QBStruct>();
private Statement code;
public QBSyntheticStruct( Statement code, QBParser parser, QBNamespace sup ) {
super(false);
this.setSuper(sup);
this.code = code;
if( !code.getHeader().startsWith("Struct") ){
throw new ParseException("Syntax error while creating struct, expected `Struct`", code);
}
// code header should be in the form of `Struct someStruct = `
String[] split = code.getHeader().split("\\s+");
if( code.getHeader().contains("extends") ){
QBList supers = new QBArrayList();
this.set( "supers", supers );
String header = code.getHeader();
String ext = header.split("\\s+extends\\s+")[1];
String[] extending = ext.split("\\s*,\\s*");
Collections.reverse(Arrays.asList(extending));
for(String s : extending){
QBStruct obj = (QBStruct) get(s);
this.addSuperStruct(obj);
supers.add(obj);
}
}
String name = split[1];
this.setName(name);
for(Statement child : code.getChildren())
parser.readStatement(child, this);
}
@Override
public QBObject newInstance() {
// TODO Auto-generated method stub
return null;
}
public String toString(){
return code.toString();
}
}
|