Skip to content

Commit

Permalink
fix(zscript): don't only show singular deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyV99 committed Apr 3, 2024
1 parent 331bbd4 commit 88898e2
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 17 deletions.
4 changes: 0 additions & 4 deletions src/parser/ASTVisitors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,15 @@ void RecursiveVisitor::deprecWarn(Function* func, AST* host, std::string const&
case 0: //No warn
break;
case 2: //Error
//Only show once, if func is deprecated. Show error even if warn shown before.
if(func->shouldShowDepr(true))
{
handleError(CompileError::DeprecatedError(host, s1, s2), &func->getInfo());
func->ShownDepr(true);
}
break;
default: //Warn
//Only show once, if func is deprecated
if(func->shouldShowDepr(false))
{
handleError(CompileError::DeprecatedWarn(host, s1, s2), &func->getInfo());
func->ShownDepr(false);
}
break;
}
Expand Down
13 changes: 2 additions & 11 deletions src/parser/ZScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ Function::Function(DataType const* returnType, string const& name,
: returnType(returnType), name(name), hasPrefixType(false), isFromTypeTemplate(false),
extra_vargs(0), paramTypes(paramTypes), paramNames(paramNames), opt_vals(), id(id),
node(NULL), internalScope(NULL), thisVar(NULL), internal_flags(internal_flags), prototype(prototype),
defaultReturn(defaultReturn), label(std::nullopt), flags(flags), shown_depr(false),
defaultReturn(defaultReturn), label(std::nullopt), flags(flags),
aliased_func(nullptr), paramDatum()
{
assert(returnType);
Expand Down Expand Up @@ -646,16 +646,7 @@ bool Function::isTracing() const
//Return true the first time it is called, if func is deprecated
bool Function::shouldShowDepr(bool err) const
{
if(!getFlag(FUNCFLAG_DEPRECATED)) return false;
if(err) return shown_depr < 2;
return !shown_depr;
}
void Function::ShownDepr(bool err)
{
if(err)
shown_depr = 2;
else if(shown_depr < 2)
shown_depr = 1;
return getFlag(FUNCFLAG_DEPRECATED);
}

void Function::alias(Function* func, bool force)
Expand Down
2 changes: 0 additions & 2 deletions src/parser/ZScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,6 @@ namespace ZScript
optional<int32_t> defaultReturn;

bool shouldShowDepr(bool err) const;
void ShownDepr(bool err);

void alias(Function* func, bool force = false);
bool is_aliased() const {return bool(aliased_func);}
Expand Down Expand Up @@ -601,7 +600,6 @@ namespace ZScript
mutable std::optional<int32_t> altlabel;
int32_t flags, internal_flags;
FunctionScope* internalScope;
byte shown_depr;
string info;

// Code implementing this function.
Expand Down

0 comments on commit 88898e2

Please sign in to comment.