|
|
|
|
@ -1077,34 +1077,6 @@ public final class Parser
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Only a subset of expressions are parsed without coming after
|
|
|
|
|
* an assignment, functioncall parameters etc
|
|
|
|
|
*
|
|
|
|
|
* Therefore instead of mirroring a lot fo what is in expression, for now atleast
|
|
|
|
|
* I will support everything using discard
|
|
|
|
|
*
|
|
|
|
|
* TODO: Remove discard and implement the needed mirrors
|
|
|
|
|
*/
|
|
|
|
|
private DiscardStatement parseDiscard()
|
|
|
|
|
{
|
|
|
|
|
/* Consume the `discard` */
|
|
|
|
|
nextToken();
|
|
|
|
|
|
|
|
|
|
/* Parse the following expression */
|
|
|
|
|
Expression expression = parseExpression();
|
|
|
|
|
|
|
|
|
|
/* Expect a semi-colon */
|
|
|
|
|
expect(SymbolType.SEMICOLON, getCurrentToken());
|
|
|
|
|
nextToken();
|
|
|
|
|
|
|
|
|
|
/* Create a `discard` statement */
|
|
|
|
|
DiscardStatement discardStatement = new DiscardStatement(expression);
|
|
|
|
|
|
|
|
|
|
return discardStatement;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private CastedExpression parseCast()
|
|
|
|
|
{
|
|
|
|
|
CastedExpression castedExpression;
|
|
|
|
|
@ -2462,17 +2434,6 @@ public final class Parser
|
|
|
|
|
parentToContainer(container, [retStmt.getReturnExpression()]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* If we have a `DiscardStatement`
|
|
|
|
|
* then we must process its
|
|
|
|
|
* contained expression
|
|
|
|
|
*/
|
|
|
|
|
else if(cast(DiscardStatement)statement)
|
|
|
|
|
{
|
|
|
|
|
DiscardStatement dcrdStmt = cast(DiscardStatement)statement;
|
|
|
|
|
|
|
|
|
|
parentToContainer(container, [dcrdStmt.getExpression()]);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* If we have an `IfStatement`
|
|
|
|
|
* then extract its `Branch`
|
|
|
|
|
@ -2872,12 +2833,6 @@ public final class Parser
|
|
|
|
|
/* Parse the return statement */
|
|
|
|
|
statement = parseReturn();
|
|
|
|
|
}
|
|
|
|
|
/* If it is a `discard` statement */
|
|
|
|
|
else if(symbol == SymbolType.DISCARD)
|
|
|
|
|
{
|
|
|
|
|
/* Parse the discard statement */
|
|
|
|
|
statement = parseDiscard();
|
|
|
|
|
}
|
|
|
|
|
/* If it is a dereference assigment (a `*`) */
|
|
|
|
|
else if(symbol == SymbolType.STAR)
|
|
|
|
|
{
|
|
|
|
|
@ -3616,71 +3571,6 @@ class myClass2
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Discard statement test case
|
|
|
|
|
*/
|
|
|
|
|
unittest
|
|
|
|
|
{
|
|
|
|
|
string sourceCode = `
|
|
|
|
|
module parser_discard;
|
|
|
|
|
|
|
|
|
|
void function()
|
|
|
|
|
{
|
|
|
|
|
discard function();
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
File dummyFile;
|
|
|
|
|
Compiler compiler = new Compiler(sourceCode, "legitidk.t", dummyFile);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
compiler.doLex();
|
|
|
|
|
assert(true);
|
|
|
|
|
}
|
|
|
|
|
catch(LexerException e)
|
|
|
|
|
{
|
|
|
|
|
assert(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
compiler.doParse();
|
|
|
|
|
Program program = compiler.getProgram();
|
|
|
|
|
|
|
|
|
|
// There is only a single module in this program
|
|
|
|
|
Module modulle = program.getModules()[0];
|
|
|
|
|
|
|
|
|
|
/* Module name must be parser_discard */
|
|
|
|
|
assert(cmp(modulle.getName(), "parser_discard")==0);
|
|
|
|
|
TypeChecker tc = new TypeChecker(compiler);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Find the function named `function` */
|
|
|
|
|
Entity func = tc.getResolver().resolveBest(modulle, "function");
|
|
|
|
|
assert(func);
|
|
|
|
|
assert(cast(Function)func); // Ensure it is a Funciton
|
|
|
|
|
|
|
|
|
|
/* Get the function's body */
|
|
|
|
|
Container funcContainer = cast(Container)func;
|
|
|
|
|
assert(funcContainer);
|
|
|
|
|
Statement[] functionStatements = funcContainer.getStatements();
|
|
|
|
|
assert(functionStatements.length == 1);
|
|
|
|
|
|
|
|
|
|
/* First statement should be a discard */
|
|
|
|
|
DiscardStatement discard = cast(DiscardStatement)functionStatements[0];
|
|
|
|
|
assert(discard);
|
|
|
|
|
|
|
|
|
|
/* The statement being discarded should be a function call */
|
|
|
|
|
FunctionCall functionCall = cast(FunctionCall)discard.getExpression();
|
|
|
|
|
assert(functionCall);
|
|
|
|
|
}
|
|
|
|
|
catch(TError e)
|
|
|
|
|
{
|
|
|
|
|
assert(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Function definition test case
|
|
|
|
|
*/
|
|
|
|
|
|