More fiddling and improvements to code generation.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4411 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -88,7 +88,7 @@ public class ActionScriptSource
|
|||||||
while (comment.startsWith("\n")) {
|
while (comment.startsWith("\n")) {
|
||||||
comment = comment.substring(1);
|
comment = comment.substring(1);
|
||||||
}
|
}
|
||||||
this.comment = comment;
|
this.comment = StringUtil.isBlank(comment) ? "" : comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write (PrintWriter writer) {
|
public void write (PrintWriter writer) {
|
||||||
@@ -411,6 +411,7 @@ public class ActionScriptSource
|
|||||||
Mode mode = Mode.PREAMBLE;
|
Mode mode = Mode.PREAMBLE;
|
||||||
Matcher m;
|
Matcher m;
|
||||||
int braceCount = 0;
|
int braceCount = 0;
|
||||||
|
boolean seenOpenBrace = false;
|
||||||
StringBuilder accum = new StringBuilder();
|
StringBuilder accum = new StringBuilder();
|
||||||
while ((line = bin.readLine()) != null) {
|
while ((line = bin.readLine()) != null) {
|
||||||
line = line.replaceAll("\\s+$", "");
|
line = line.replaceAll("\\s+$", "");
|
||||||
@@ -532,6 +533,7 @@ public class ActionScriptSource
|
|||||||
|
|
||||||
// switch to METHODBODY to absorb the method
|
// switch to METHODBODY to absorb the method
|
||||||
braceCount = (line.indexOf("{") == -1) ? 0 : 1;
|
braceCount = (line.indexOf("{") == -1) ? 0 : 1;
|
||||||
|
seenOpenBrace = (braceCount > 0);
|
||||||
mode = Mode.METHODBODY;
|
mode = Mode.METHODBODY;
|
||||||
|
|
||||||
// see if we match a method declaration
|
// see if we match a method declaration
|
||||||
@@ -578,6 +580,7 @@ public class ActionScriptSource
|
|||||||
|
|
||||||
// switch to METHODBODY to absorb the method
|
// switch to METHODBODY to absorb the method
|
||||||
braceCount = (line.indexOf("{") == -1) ? 0 : 1;
|
braceCount = (line.indexOf("{") == -1) ? 0 : 1;
|
||||||
|
seenOpenBrace = (braceCount > 0);
|
||||||
mode = Mode.METHODBODY;
|
mode = Mode.METHODBODY;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -600,12 +603,13 @@ public class ActionScriptSource
|
|||||||
|
|
||||||
case METHODBODY:
|
case METHODBODY:
|
||||||
if (line.indexOf("{") != -1) {
|
if (line.indexOf("{") != -1) {
|
||||||
|
seenOpenBrace = true;
|
||||||
braceCount++;
|
braceCount++;
|
||||||
}
|
}
|
||||||
if (line.indexOf("}") != -1) {
|
if (line.indexOf("}") != -1) {
|
||||||
braceCount--;
|
braceCount--;
|
||||||
}
|
}
|
||||||
if (braceCount == 0) {
|
if (seenOpenBrace && braceCount == 0) {
|
||||||
mode = Mode.CLASSBODY;
|
mode = Mode.CLASSBODY;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -635,6 +639,7 @@ public class ActionScriptSource
|
|||||||
Mode mode = Mode.PREAMBLE;
|
Mode mode = Mode.PREAMBLE;
|
||||||
Matcher m;
|
Matcher m;
|
||||||
int braceCount = 0;
|
int braceCount = 0;
|
||||||
|
boolean seenOpenBrace = false;
|
||||||
StringBuilder accum = new StringBuilder();
|
StringBuilder accum = new StringBuilder();
|
||||||
Member curmem = null;
|
Member curmem = null;
|
||||||
while ((line = bin.readLine()) != null) {
|
while ((line = bin.readLine()) != null) {
|
||||||
@@ -718,6 +723,7 @@ public class ActionScriptSource
|
|||||||
|
|
||||||
// switch to METHODBODY to absorb the method
|
// switch to METHODBODY to absorb the method
|
||||||
braceCount = (line.indexOf("{") == -1) ? 0 : 1;
|
braceCount = (line.indexOf("{") == -1) ? 0 : 1;
|
||||||
|
seenOpenBrace = (braceCount > 0);
|
||||||
mode = Mode.METHODBODY;
|
mode = Mode.METHODBODY;
|
||||||
|
|
||||||
// see if we match a method declaration
|
// see if we match a method declaration
|
||||||
@@ -728,34 +734,40 @@ public class ActionScriptSource
|
|||||||
line = line + "\n" + slurpUntil(bin, ")", false);
|
line = line + "\n" + slurpUntil(bin, ")", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ArrayList<Member> list = publicMethods;
|
||||||
|
boolean isProtected = (line.indexOf("protected ") != -1);
|
||||||
|
boolean isStatic = (line.indexOf("static ") != -1);
|
||||||
|
list = isProtected ?
|
||||||
|
(isStatic ? protectedStaticMethods : protectedMethods) :
|
||||||
|
(isStatic ? publicStaticMethods : publicMethods);
|
||||||
|
|
||||||
// extract the name, replace the declaration
|
// extract the name, replace the declaration
|
||||||
String funcName = m.group(1);
|
String funcName = m.group(1);
|
||||||
curmem = getMember(publicMethods, funcName);
|
curmem = getMember(list, funcName);
|
||||||
if (curmem == null) {
|
|
||||||
curmem = getMember(protectedMethods, funcName);
|
|
||||||
}
|
|
||||||
if (curmem == null) {
|
if (curmem == null) {
|
||||||
System.err.println(
|
System.err.println(
|
||||||
"Have ActionScript method with no " +
|
"Have ActionScript method with no " +
|
||||||
"Java equivalent: " + funcName + "().");
|
"Java equivalent: " + funcName + "().");
|
||||||
} else {
|
curmem = new Member(funcName, "");
|
||||||
// update the definition and comment with the
|
list.add(curmem);
|
||||||
// ActionScript versions (unless it's readObject or
|
}
|
||||||
// writeObject in which case we want always to use the
|
|
||||||
// generated versions)
|
// update the definition and comment with the ActionScript
|
||||||
if (!funcName.equals("readObject") &&
|
// versions (unless it's readObject or writeObject in which
|
||||||
!funcName.equals("writeObject")) {
|
// case we want always to use the generated versions)
|
||||||
curmem.definition = line.trim();
|
if (!funcName.equals("readObject") &&
|
||||||
}
|
!funcName.equals("writeObject")) {
|
||||||
String ncomment = accum.toString();
|
curmem.definition = line.trim();
|
||||||
if (!StringUtil.isBlank(ncomment)) {
|
}
|
||||||
curmem.setComment(ncomment);
|
String ncomment = accum.toString();
|
||||||
}
|
if (!StringUtil.isBlank(ncomment)) {
|
||||||
|
curmem.setComment(ncomment);
|
||||||
}
|
}
|
||||||
accum.setLength(0);
|
accum.setLength(0);
|
||||||
|
|
||||||
// switch to METHODBODY to absorb the method
|
// switch to METHODBODY to absorb the method
|
||||||
braceCount = (line.indexOf("{") == -1) ? 0 : 1;
|
braceCount = (line.indexOf("{") == -1) ? 0 : 1;
|
||||||
|
seenOpenBrace = (braceCount > 0);
|
||||||
mode = Mode.METHODBODY;
|
mode = Mode.METHODBODY;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -778,13 +790,14 @@ public class ActionScriptSource
|
|||||||
|
|
||||||
case METHODBODY:
|
case METHODBODY:
|
||||||
if (line.indexOf("{") != -1) {
|
if (line.indexOf("{") != -1) {
|
||||||
|
seenOpenBrace = true;
|
||||||
braceCount++;
|
braceCount++;
|
||||||
}
|
}
|
||||||
if (line.indexOf("}") != -1) {
|
if (line.indexOf("}") != -1) {
|
||||||
braceCount--;
|
braceCount--;
|
||||||
}
|
}
|
||||||
accum.append(line).append("\n");
|
accum.append(line).append("\n");
|
||||||
if (braceCount == 0) {
|
if (seenOpenBrace && braceCount == 0) {
|
||||||
// update the method body of our currently matched member
|
// update the method body of our currently matched member
|
||||||
if (curmem != null) {
|
if (curmem != null) {
|
||||||
curmem.body = accum.toString();
|
curmem.body = accum.toString();
|
||||||
@@ -996,6 +1009,7 @@ public class ActionScriptSource
|
|||||||
|
|
||||||
protected static Pattern ASFUNCTION = Pattern.compile(
|
protected static Pattern ASFUNCTION = Pattern.compile(
|
||||||
".*(?:public|protected)" +
|
".*(?:public|protected)" +
|
||||||
|
"(?:\\s+static)?" +
|
||||||
"(?:\\s+/\\*\\s*abstract\\s*\\*/)?" +
|
"(?:\\s+/\\*\\s*abstract\\s*\\*/)?" +
|
||||||
"\\s+function\\s+([a-zA-Z]\\w*) \\(.*");
|
"\\s+function\\s+([a-zA-Z]\\w*) \\(.*");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user