Index: src/Common/Examine.cc
===================================================================
--- src/Common/Examine.cc	(revision 1c01c5836c12d14d4c519d76550c0381bc562aaf)
+++ src/Common/Examine.cc	(revision 18f7858ea013d58a6e3cd0b6bfc61801c6f018c1)
@@ -5,16 +5,18 @@
 // file "LICENCE" distributed with Cforall.
 //
-// Examine.h --
+// Examine.cc -- Helpers for examining AST code.
 //
 // Author           : Andrew Beach
 // Created On       : Wed Sept 2 14:02 2020
 // Last Modified By : Andrew Beach
-// Last Modified On : Wed Sep  8 12:15 2020
-// Update Count     : 0
+// Last Modified On : Fri Dec 10 10:27 2021
+// Update Count     : 1
 //
 
 #include "Common/Examine.h"
 
+#include "AST/Type.hpp"
 #include "CodeGen/OperatorTable.h"
+#include "InitTweak/InitTweak.h"
 
 DeclarationWithType * isMainFor( FunctionDecl * func, AggregateDecl::Aggregate kind ) {
@@ -36,4 +38,35 @@
 
 namespace {
+
+// getTypeofThis but does some extra checks used in this module.
+const ast::Type * getTypeofThisSolo( const ast::FunctionDecl * func ) {
+	if ( 1 != func->params.size() ) {
+		return nullptr;
+	}
+	auto ref = func->type->params.front().as<ast::ReferenceType>();
+	return (ref) ? ref->base : nullptr;
+}
+
+}
+
+const ast::DeclWithType * isMainFor(
+		const ast::FunctionDecl * func, ast::AggregateDecl::Aggregate kind ) {
+	if ( "main" != func->name ) return nullptr;
+	if ( 1 != func->params.size() ) return nullptr;
+
+	auto param = func->params.front();
+
+	auto type = dynamic_cast<const ast::ReferenceType *>( param->get_type() );
+	if ( !type ) return nullptr;
+
+	auto obj = type->base.as<ast::StructInstType>();
+	if ( !obj ) return nullptr;
+
+	if ( kind != obj->base->kind ) return nullptr;
+
+	return param;
+}
+
+namespace {
 	Type * getDestructorParam( FunctionDecl * func ) {
 		if ( !CodeGen::isDestructor( func->name ) ) return nullptr;
@@ -48,4 +81,11 @@
 		return nullptr;
 	}
+
+const ast::Type * getDestructorParam( const ast::FunctionDecl * func ) {
+	if ( !CodeGen::isDestructor( func->name ) ) return nullptr;
+	//return InitTweak::getParamThis( func )->type;
+	return getTypeofThisSolo( func );
+}
+
 }
 
@@ -57,2 +97,11 @@
 	return false;
 }
+
+bool isDestructorFor(
+		const ast::FunctionDecl * func, const ast::StructDecl * type_decl ) {
+	if ( const ast::Type * type = getDestructorParam( func ) ) {
+		auto stype = dynamic_cast<const ast::StructInstType *>( type );
+		return stype && stype->base.get() == type_decl;
+	}
+	return false;
+}
