Skip to content

Feature Request: Allow options to make Should Call Parent more strictΒ #444

@Contrabang

Description

@Contrabang

TLDR:

  • Support for more complex SHOULD_CALL_PARENT behavior, like forcing a parent call at the top of the proc.

Reasoning

SHOULD_CALL_PARENT(TRUE) (aka set SpacemanDMM_should_call_parent = 1) has no options for where any parent calls should be placed. This can lead to awkward situations where uses in different subtypes implement parent calling in different ways. The 3 main ways I've identified is:

  • . = ..() at the top of the proc
  • return ..() at the end of the proc, with a bunch of early returns
  • return ..() at the end of every branch of the proc

Using different methods in different subtypes may lead to irregular/unexpected behavior.

Examples

/New() and /Initialize() are often implemented with a . = ..() at the top, and /Destroy() with return ..() at the bottom. But these could also be implemented for more dynamic functions, which may never return to the parent, either due to a else or an early return.

Proposal

Expose enum-like defines as possible arguments for SpacemanDMM_should_call_parent, with FALSE and TRUE grandfathered in as they previously worked.

#define SHOULD_CALL_PARENT(X) set SpacemanDMM_should_call_parent = X
	// Disables all Should Call Parent Calls
	// #define FALSE 0
	// Requires at least 1 parent call anywhere in the proc
	// #define TRUE 1
	/// Requires a ..() call at the top of the proc block
	#define SDMM_TOP_OF_PROC 2
	/// Requires ..() as the last instruction in the proc block
	#define SDMM_BOTTOM_OF_PROC 3
	/// Requires return ..() at the end of all branches
	#define SDMM_ALL_RETURNS 4

Alternatively, use separate but more line-filling (and possibly conflicting) separate calls

#define SHOULD_CALL_PARENT(X) set SpacemanDMM_should_call_parent = X
#define SHOULD_CALL_PARENT_TOP(X) set SpacemanDMM_should_call_parent_top = X
#define SHOULD_CALL_PARENT_BOTTOM(X) set SpacemanDMM_should_call_parent_bottom = X
#define SHOULD_CALL_PARENT_ALL_RETURNS(X) set SpacemanDMM_should_call_parent_all_returns = X

Implementation

Using SDMM_TOP_OF_PROC would require that the first instruction of a subtype proc be a ..() call.
Using SDMM_BOTTOM_OF_PROC would require that the last proc-block scope (i.e. not in the else of an if statement) instruction of a subtype proc be a ..() call.
Using SHOULD_CALL_PARENT_ALL_RETURNS requires that all returns (including implied ones) must be a ..() call, to make sure nothing fails to call the parent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions