Skip to content

Commit

Permalink
test: make some test scripts emit no warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed Apr 25, 2024
1 parent 1af434d commit 6720fc5
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 13 deletions.
14 changes: 14 additions & 0 deletions src/parser/ASTVisitors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ void RecursiveVisitor::deprecWarn(Function* func, AST* host, std::string const&
break;
}
}
void RecursiveVisitor::deprecWarn(AST* host, std::string const& s1, std::string const& s2, std::string const& info)
{
switch(*ZScript::lookupOption(*scope, CompileOption::OPT_WARN_DEPRECATED)/10000)
{
case 0: //No warn
break;
case 2: //Error
handleError(CompileError::DeprecatedError(host, s1, s2), info.empty() ? nullptr : &info);
break;
default: //Warn
handleError(CompileError::DeprecatedWarn(host, s1, s2), info.empty() ? nullptr : &info);
break;
}
}
void RecursiveVisitor::visit(AST& node, void* param)
{
if(node.isDisabled()) return; //Don't visit disabled nodes.
Expand Down
6 changes: 3 additions & 3 deletions src/parser/ASTVisitors.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,9 @@ namespace ZScript
void handleError(CompileError const& error, std::string const* inf = nullptr) /*override*/;
bool hasError() const /*override*/ {return failure;}

void deprecWarn(AST* host, std::string const& s1, std::string const& s2);

void deprecWarn(Function* func, AST* host, std::string const& s1, std::string const& s2);
void deprecWarn(AST* host, std::string const& s1, std::string const& s2, std::string const& info = "");

// Visits a single node. The only virtual visit function as all others
// defer to this one.
virtual void visit(AST& node, void* param = NULL);
Expand Down Expand Up @@ -369,7 +370,6 @@ namespace ZScript
AST* node = NULL,
bool twoWay = false);
protected:
void deprecWarn(Function* func, AST* host, std::string const& s1, std::string const& s2);
// Returns true if we have failed or for some other reason must break out
// of recursion. Should be called with the current node and param between
// each action that can fail.
Expand Down
2 changes: 1 addition & 1 deletion src/parser/BuildVisitors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2456,7 +2456,7 @@ void BuildOpcodes::caseExprDelete(ASTExprDelete& host, void* param)
{
VISIT_USEVAL(host.operand.get(), param);
addOpcode(new OFreeObject(new VarArgument(EXP1)));
handleError(CompileError::DeprecatedDelete(&host));
deprecWarn(&host, "The operator", "delete", "This operator no longer does anything. Objects are freed automatically when they become unreachable");
}

void BuildOpcodes::caseExprNot(ASTExprNot& host, void* param)
Expand Down
1 change: 0 additions & 1 deletion src/parser/CompileError.xtable
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ X( BadTempVal, T, A, E, VOID, VOID, "Temporary literals cannot be stored!"
X( MissingReturnWarn, S, A, W, STR, VOID, "Function '%s' is not void, and should return a value!" )
X( MissingReturnError, S, A, E, STR, VOID, "Function '%s' is not void, and must return a value!" )
X( NegSqrt, T, A, E, VOID, VOID, "Attempting to take the square root of a negative number!" )
X( DeprecatedDelete, G, A, W, VOID, VOID, "The 'delete' operator no longer does anything. Objects are freed automatically when they become unreachable" )
X( ReadOnly, C, A, W, STR, VOID, "'%s' is read-only, and cannot be written to!" )
X( BadInternal, S, A, E, STR, VOID, "%s" )

Expand Down
4 changes: 2 additions & 2 deletions tests/replays/playground.qst
Git LFS file not shown
1 change: 0 additions & 1 deletion tests/scripts/classes_expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Pass 3: Registration
Pass 4: Analyzing Code
Pass 5: Checking code paths
Pass 6: Generating object code
ZQ_BUFFER Line 28 @ Columns 3-15 - Warning G104: The 'delete' operator no longer does anything. Objects are freed automatically when they become unreachable
Pass 7: Assembling
Success!
Compile finished with exit code '0' (success)
Expand Down
1 change: 0 additions & 1 deletion tests/scripts/gc_expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Pass 3: Registration
Pass 4: Analyzing Code
Pass 5: Checking code paths
Pass 6: Generating object code
ZQ_BUFFER Line 439 @ Columns 4-12 - Warning G104: The 'delete' operator no longer does anything. Objects are freed automatically when they become unreachable
Pass 7: Assembling
Success!
Compile finished with exit code '0' (success)
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/maths.zs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ffc script Maths
{
doMaths(firstTime, i);
doMaths(firstTime, i * 10000);
doMaths(firstTime, i * 10000000);
doMaths(firstTime, i * 100000);
}

Waitframe();
Expand Down
3 changes: 0 additions & 3 deletions tests/scripts/maths_expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ Pass 3: Registration
Pass 4: Analyzing Code
Pass 5: Checking code paths
Pass 6: Generating object code
ZQ_BUFFER Line 12 @ Columns 40-48 - Warning C020: Constant 10000000 is too long and has been truncated.
ZQ_BUFFER Line 12 @ Columns 40-48 - Warning C020: Constant 10000000 is too long and has been truncated.
ZQ_BUFFER Line 12 @ Columns 40-48 - Warning C020: Constant 10000000 is too long and has been truncated.
Pass 7: Assembling
Success!
Compile finished with exit code '0' (success)
Expand Down

0 comments on commit 6720fc5

Please sign in to comment.