From 276e96ac9502bc5a399d6cad9e818faac4372ae4 Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Tue, 3 Oct 2017 14:24:48 -0700 Subject: Add deprecated / obsolete variable support By calling the custom KATI_deprecated_var / KATI_obsolete_var functions, variables may be marked as deprecated or obsolete. When accessed or assigned, deprecated variables will print a warning. When accessed or assigned, obsolete variables will print an error and stop. Variables do not need to be set before calling the functions, and will persist the deprecation warning through a reassignment. This way we can easily mark variables that are sometimes passed via the environment as deprecated. Change-Id: Id04c974c446f471a18cc173f817760f4a02b9239 --- eval.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'eval.cc') diff --git a/eval.cc b/eval.cc index 7a08be7..ecfcd50 100644 --- a/eval.cc +++ b/eval.cc @@ -55,7 +55,9 @@ Var* Evaluator::EvalRHS(Symbol lhs, Value* rhs_v, StringPiece orig_rhs, is_override ? VarOrigin::OVERRIDE : VarOrigin::FILE)); Var* rhs = NULL; + Var* prev = LookupVarInCurrentScope(lhs); bool needs_assign = true; + switch (op) { case AssignOp::COLON_EQ: { SimpleVar* sv = new SimpleVar(origin); @@ -67,7 +69,6 @@ Var* Evaluator::EvalRHS(Symbol lhs, Value* rhs_v, StringPiece orig_rhs, rhs = new RecursiveVar(rhs_v, origin, orig_rhs); break; case AssignOp::PLUS_EQ: { - Var* prev = LookupVarInCurrentScope(lhs); if (!prev->IsDefined()) { rhs = new RecursiveVar(rhs_v, origin, orig_rhs); } else if (prev->ReadOnly()) { @@ -80,7 +81,6 @@ Var* Evaluator::EvalRHS(Symbol lhs, Value* rhs_v, StringPiece orig_rhs, break; } case AssignOp::QUESTION_EQ: { - Var* prev = LookupVarInCurrentScope(lhs); if (!prev->IsDefined()) { rhs = new RecursiveVar(rhs_v, origin, orig_rhs); } else { @@ -91,6 +91,13 @@ Var* Evaluator::EvalRHS(Symbol lhs, Value* rhs_v, StringPiece orig_rhs, } } + prev->Used(this, lhs); + if (prev->Deprecated()) { + if (needs_assign) { + rhs->SetDeprecated(prev->DeprecatedMessage()); + } + } + LOG("Assign: %s=%s", lhs.c_str(), rhs->DebugString().c_str()); if (needs_assign) { return rhs; -- cgit v1.2.3