Skip to content

Commit

Permalink
can be builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
spookydonut committed Oct 10, 2020
1 parent f2dc9a4 commit 2ebcd2c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
32 changes: 18 additions & 14 deletions src/dreamchecker/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,17 +402,19 @@ struct ProcDirective<'o> {
can_be_disabled: bool,
set_at_definition: bool,
can_be_global: bool,
can_be_builtin: bool,
directive_string: &'static str,
}

impl<'o> ProcDirective<'o> {
pub fn new(directive_string: &'static str, can_be_disabled: bool, set_at_definition: bool, can_be_global: bool) -> ProcDirective<'o> {
pub fn new(directive_string: &'static str, can_be_disabled: bool, set_at_definition: bool, can_be_global: bool, can_be_builtin: bool) -> ProcDirective<'o> {
ProcDirective {
directive: Default::default(),
directive_string,
can_be_disabled,
set_at_definition,
can_be_global,
can_be_builtin,
}
}

Expand Down Expand Up @@ -584,14 +586,14 @@ impl<'o> AnalyzeObjectTree<'o> {
context,
objtree,
return_type,
must_call_parent: ProcDirective::new("SpacemanDMM_should_call_parent", true, false, false),
must_not_override: ProcDirective::new("SpacemanDMM_should_not_override", false, false, false),
private: ProcDirective::new("SpacemanDMM_private_proc", false, true, false),
protected: ProcDirective::new("SpacemanDMM_protected_proc", false, true, false),
must_not_sleep: ProcDirective::new("SpacemanDMM_should_not_sleep", false, true, true),
sleep_exempt: ProcDirective::new("SpacemanDMM_allowed_to_sleep", false, true, true),
must_be_pure: ProcDirective::new("SpacemanDMM_should_be_pure", false, true, true),
can_be_redefined: ProcDirective::new("SpacemanDMM_can_be_redefined", false, false, false),
must_call_parent: ProcDirective::new("SpacemanDMM_should_call_parent", true, false, false, true),
must_not_override: ProcDirective::new("SpacemanDMM_should_not_override", false, false, false, false),
private: ProcDirective::new("SpacemanDMM_private_proc", false, true, false, false),
protected: ProcDirective::new("SpacemanDMM_protected_proc", false, true, false, false),
must_not_sleep: ProcDirective::new("SpacemanDMM_should_not_sleep", false, true, true, true),
sleep_exempt: ProcDirective::new("SpacemanDMM_allowed_to_sleep", false, true, true, true),
must_be_pure: ProcDirective::new("SpacemanDMM_should_be_pure", false, true, true, true),
can_be_redefined: ProcDirective::new("SpacemanDMM_can_be_redefined", false, false, false, false),
used_kwargs: Default::default(),
call_tree: Default::default(),
sleeping_procs: Default::default(),
Expand Down Expand Up @@ -632,11 +634,13 @@ impl<'o> AnalyzeObjectTree<'o> {

if procdirective.set_at_definition {
if let Some(procdef) = &mut proc.get_declaration() {
if procdef.location != proc.get().location {
error(location, format!("Can't define procs {} outside their initial definition", directive))
.set_severity(Severity::Warning)
.register(self.context);
return
if !(procdef.location.is_builtins() && procdirective.can_be_builtin) {
if procdef.location != proc.get().location {
error(location, format!("Can't define procs {} outside their initial definition", directive))
.set_severity(Severity::Warning)
.register(self.context);
return
}
}
}
}
Expand Down
18 changes: 17 additions & 1 deletion src/dreamchecker/tests/directive_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,20 @@ fn no_can_be_redefined() {
return
"##.trim();
check_errors_match(code, NO_CAN_BE_REDEFINED_ERRORS);
}
}

pub const BUILT_IN_SLEEP: &[(u32, u16, &str)] = &[
(4, 17, "/mob/living/proc/Move sets SpacemanDMM_should_not_sleep but calls blocking built-in(s)"),
];

#[test]
fn built_in_sleep() {
let code = r##"
/mob/Move()
set SpacemanDMM_should_not_sleep = TRUE
/mob/living/Move()
sleep(1)
"##.trim();
check_errors_match(code, BUILT_IN_SLEEP);
}

0 comments on commit 2ebcd2c

Please sign in to comment.