Skip to content

Commit 2f52564

Browse files
committed
Added externally_called declaration
To suppress unused predicate warnings for predicates that are intended to be called from the repl or from C#
1 parent 1fb7c4a commit 2f52564

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

BotL/Compiler/Compiler.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ private static bool ProcessDeclaration(object maybeDeclaration)
178178
}
179179
break;
180180

181+
case "externally_called":
182+
{
183+
var spec = arg as Call;
184+
if (spec == null || !spec.IsFunctor(Symbol.Slash, 2))
185+
throw new ArgumentException("Invalid predicate specified in externally_called declaration");
186+
KB.Predicate((Symbol)spec.Arguments[0], (int)spec.Arguments[1]).IsExternallyCalled = true;
187+
}
188+
break;
189+
181190
default:
182191
return false;
183192
}

BotL/Compiler/Lint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private static void PrintClauseWarnings(TextWriter output)
2929
private static void WarnUnreferenced(TextWriter output, Dictionary<Predicate, List<Predicate>> refs)
3030
{
3131
foreach (var p in KB.AllRulePredicates)
32-
if (p.IsUserDefined && !refs.ContainsKey(p))
32+
if (p.IsUserDefined && !refs.ContainsKey(p) && !p.IsExternallyCalled)
3333
Warn(output, "unused predicate {0}", p);
3434
}
3535

BotL/Engine/Predicate.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ internal IEnumerable<Predicate> ReferencedUserPredicates
157157

158158
public bool IsUserDefined => (IsRulePredicate && !IsLocked) || IsTable;
159159
public bool IsTable => Table != null;
160+
public bool IsExternallyCalled;
160161

161162
#endregion
162163

BotL/Parser/ExpressionParser.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static ExpressionParser()
5252
DefinePrefixOperator("signature", 25);
5353
DefinePrefixOperator("trace", 25);
5454
DefinePrefixOperator("notrace", 25);
55+
DefinePrefixOperator("externally_called", 25);
5556

5657
DefineBinaryOperator("=", 30);
5758
DefineBinaryOperator("+=", 30);

BotL/Repl.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ public static bool RunCommand(string command)
117117
}
118118
else if (command.StartsWith("table ") || command.StartsWith("function ")
119119
|| command.StartsWith("trace ") || command.StartsWith("notrace ")
120-
|| command.StartsWith("global ") || command.StartsWith("require "))
120+
|| command.StartsWith("global ") || command.StartsWith("require ")
121+
|| command.StartsWith("externally_called "))
121122
{
122123
// Process a declaration
123124
try

0 commit comments

Comments
 (0)