Merge pull request #1096 from mpilman/features/actor-forward-declarations
Allow forward declarations to be actors
This commit is contained in:
commit
0e5db1e7b7
|
@ -300,6 +300,13 @@ namespace actorcompiler
|
|||
}
|
||||
public void Write(TextWriter writer)
|
||||
{
|
||||
string fullReturnType =
|
||||
actor.returnType != null ? string.Format("Future<{0}>", actor.returnType)
|
||||
: "void";
|
||||
if (actor.isForwardDeclaration) {
|
||||
writer.WriteLine("{0} {3}{1}( {2} );", fullReturnType, actor.name, string.Join(", ", ParameterList()), actor.nameSpace==null ? "" : actor.nameSpace + "::");
|
||||
return;
|
||||
}
|
||||
for (int i = 0; ; i++)
|
||||
{
|
||||
className = string.Format("{0}{1}Actor{2}",
|
||||
|
@ -391,9 +398,6 @@ namespace actorcompiler
|
|||
if (isTopLevel) writer.WriteLine("}"); // namespace
|
||||
WriteTemplate(writer);
|
||||
LineNumber(writer, actor.SourceLine);
|
||||
string fullReturnType =
|
||||
actor.returnType != null ? string.Format("Future<{0}>", actor.returnType)
|
||||
: "void";
|
||||
if (actor.isStatic) writer.Write("static ");
|
||||
writer.WriteLine("{0} {3}{1}( {2} ) {{", fullReturnType, actor.name, string.Join(", ", ParameterList()), actor.nameSpace==null ? "" : actor.nameSpace + "::");
|
||||
LineNumber(writer, actor.SourceLine);
|
||||
|
@ -1233,4 +1237,4 @@ namespace actorcompiler
|
|||
return string.Format("std::max(0, loopDepth - {0})", subtract);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -166,6 +166,12 @@ namespace actorcompiler
|
|||
}
|
||||
public Token[] GetAllTokens() { return tokens; }
|
||||
|
||||
public int Length {
|
||||
get {
|
||||
return endPos - beginPos;
|
||||
}
|
||||
}
|
||||
|
||||
Token[] tokens;
|
||||
int beginPos;
|
||||
int endPos;
|
||||
|
@ -852,26 +858,38 @@ namespace actorcompiler
|
|||
|
||||
var toks = range(pos+1, tokens.Length);
|
||||
var heading = toks.TakeWhile(t => t.Value != "{");
|
||||
var body = range(heading.End+1, tokens.Length)
|
||||
.TakeWhile(t => t.BraceDepth > toks.First().BraceDepth);
|
||||
var toSemicolon = toks.TakeWhile(t => t.Value != ";");
|
||||
actor.isForwardDeclaration = toSemicolon.Length < heading.Length;
|
||||
if (actor.isForwardDeclaration) {
|
||||
heading = toSemicolon;
|
||||
if (head_token.Value == "ACTOR") {
|
||||
ParseActorHeading(actor, heading);
|
||||
} else {
|
||||
head_token.Assert("ACTOR expected!", t => false);
|
||||
}
|
||||
end = heading.End + 1;
|
||||
} else {
|
||||
var body = range(heading.End+1, tokens.Length)
|
||||
.TakeWhile(t => t.BraceDepth > toks.First().BraceDepth);
|
||||
|
||||
bool warnOnNoWait = false;
|
||||
if (head_token.Value == "ACTOR")
|
||||
{
|
||||
ParseActorHeading(actor, heading);
|
||||
warnOnNoWait = true;
|
||||
bool warnOnNoWait = false;
|
||||
if (head_token.Value == "ACTOR")
|
||||
{
|
||||
ParseActorHeading(actor, heading);
|
||||
warnOnNoWait = true;
|
||||
}
|
||||
else if (head_token.Value == "TEST_CASE")
|
||||
ParseTestCaseHeading(actor, heading);
|
||||
else
|
||||
head_token.Assert("ACTOR or TEST_CASE expected!", t => false);
|
||||
|
||||
actor.body = ParseCodeBlock(body);
|
||||
|
||||
if (!actor.body.containsWait() && warnOnNoWait)
|
||||
Console.Error.WriteLine("{0}:{1}: warning: ACTOR {2} does not contain a wait() statement", sourceFile, actor.SourceLine, actor.name);
|
||||
|
||||
end = body.End + 1;
|
||||
}
|
||||
else if (head_token.Value == "TEST_CASE")
|
||||
ParseTestCaseHeading(actor, heading);
|
||||
else
|
||||
head_token.Assert("ACTOR or TEST_CASE expected!", t => false);
|
||||
|
||||
actor.body = ParseCodeBlock(body);
|
||||
|
||||
if (!actor.body.containsWait() && warnOnNoWait)
|
||||
Console.Error.WriteLine("{0}:{1}: warning: ACTOR {2} does not contain a wait() statement", sourceFile, actor.SourceLine, actor.name);
|
||||
|
||||
end = body.End + 1;
|
||||
return actor;
|
||||
}
|
||||
|
||||
|
|
|
@ -233,6 +233,7 @@ namespace actorcompiler
|
|||
public bool isUncancellable = false;
|
||||
public string testCaseParameters = null;
|
||||
public string nameSpace = null;
|
||||
public bool isForwardDeclaration = false;
|
||||
};
|
||||
|
||||
class Descr
|
||||
|
@ -241,4 +242,4 @@ namespace actorcompiler
|
|||
public string superClassList;
|
||||
public List<Declaration> body;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue