Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Record destructor calls on the "delete" keyword #829

Closed
archtur opened this issue Dec 4, 2019 · 3 comments
Closed

Record destructor calls on the "delete" keyword #829

archtur opened this issue Dec 4, 2019 · 3 comments

Comments

@archtur
Copy link

archtur commented Dec 4, 2019

Versions

Platform version: Windows 10 Pro Update 1903
Sourcetrail version: 2019.4.61 - 64bit Windows, database version 25

Description of the problem

Method calls to instance methods are not recognized by sourcetrail.

Steps to reproduce the problem:

  1. Save the following code to a .cpp file and create a new sourcetrail project which indexes the file:
    #include <string>
    #include <stdio.h>
    
    
    class AbstractSpaceship
    {
    protected:
    	AbstractSpaceship(){};
    	
    	std::string name;
    	
    public:
    	virtual ~AbstractSpaceship(){};
    
    	virtual void prepareForWarp()
    	{
    		printf("Prepare for warp on %s\n", name.c_str());
    		
    		activateAlarm();
    		loadWarpCoils();
    		giveInstructionToAccelerate();
    	};
    
    	virtual void loadWarpCoils()
    	{
    		printf("Basic warp coil loading procedure started...\n");
    	}
    
    	virtual void activateAlarm() = 0; 
    	virtual void giveInstructionToAccelerate() = 0; 
    };
    
    
    class EnterpriseNx01 : public AbstractSpaceship
    {
    public:
    	EnterpriseNx01()
    	{
    		name = "Enterprise NX-01";
    	}
    	virtual ~EnterpriseNx01() {}
    	
    public:
    	virtual void loadWarpCoils()
    	{	
    		// Overrides AbstractSpaceship::loadWarpCoils() and has to extend it
    		AbstractSpaceship::loadWarpCoils();
    		
    		printf("Additional warp coil loading procedures for old space ship versions\n");
    	}
    	
    	virtual void activateAlarm()
    	{
    		printf("Quite old beeping alarm\n");
    	}
    	virtual void giveInstructionToAccelerate()
    	{
    		printf("Archer: *Saying-something--cannot-remember*\n");
    	}
    };
    
    
    class EnterpriseNcc1701d : public AbstractSpaceship
    {
    public:
    	EnterpriseNcc1701d() 
    	{
    		name = "Enterprise NCC-1701-D";
    	}
    	virtual ~EnterpriseNcc1701d() {}
    	
    public:
    	virtual void activateAlarm()
    	{
    		printf("No alarm needed any more\n");
    	}
    	virtual void giveInstructionToAccelerate()
    	{
    		printf("Picard: \"Energie!\"\n");
    	}
    };
    
    
    void test_superclasscalls()
    {
    	EnterpriseNx01 		oldSpaceship = EnterpriseNx01();
    	EnterpriseNcc1701d 	newSpaceship = EnterpriseNcc1701d();
    	
    	printf("=============================================\n");
    	oldSpaceship.prepareForWarp();
    	printf("\n");
    	
    	printf("=============================================\n");
    	newSpaceship.prepareForWarp();
    	printf("\n");
    }
    
    void test_superclasscalls_withpointers()
    {
    	EnterpriseNx01 		* oldSpaceship = new EnterpriseNx01();
    	EnterpriseNcc1701d 	* newSpaceship = new EnterpriseNcc1701d();
    	
    	printf("=============================================\n");
    	oldSpaceship->prepareForWarp();
    	printf("\n");
    	
    	printf("=============================================\n");
    	newSpaceship->prepareForWarp();
    	printf("\n");
    	
    	delete oldSpaceship;
    	delete newSpaceship;
    }
  2. After indexing chosse in the sourcetrail graph Functions --> test_superclasscalls_withpointers. (The same issue happens on the graph for test_superclasscalls - The function does the same. The only difference is that the ..._withpointers function creates objects on the heap with new and calls with dereferencing operator -> after the pointer variable, instead of holding the objects on the stack and calling the methods with . operator.)
  3. --> Issue --> The calls to the instance methods oldSpaceship->prepareForWarp() and newSpaceship->prepareForWarp() are not shown in the graph. Only the constructor calls are shown there. The destructor calls are also not shown (the destructors are called in the lines delete oldSpaceship; and delete newSpaceship;). On hovering over the code oldSpaceship->prepareForWarp() and newSpaceship->prepareForWarp() in the right side source window, there is no effect, like it was not indexed.
    2019-12-04 16_39_59-Sourcetrail - test_superclasscalls srctrlprj
@mlangkabel
Copy link
Contributor

Thanks for providing the sample code. I tried to reproduce the issue. The calls to prepareForWarp are shown. So having those ones missing in your graph is likely caused by the fatal indexing error that you still have. Please fix that issue and the graph should be fine.

The calls to the destructor are missing for me as well. Usually destructors of objects on the stack are called implicitly by the objects going out of scope. So there is not real source location for that. But I think you are right: When there is an explicit "call" to a destructor, we should record and show it!

@mlangkabel mlangkabel changed the title C++ instance method and destructor calls not recognized Record destructor calls on the "delete" keyword Dec 4, 2019
@archtur
Copy link
Author

archtur commented Dec 5, 2019

Thank you for your help. You are right, exactly like in the other open issue from me, after fixing the fatal issue the calls to the methods are shown.
After-fixing-include-directives_2
I will try to solve this in my productive environment also and retry. If I have other issues there I will contact you.

The destructor calls are still missing.
In my opinion sourcetrail could also record implicit calls to the destructor because it is already recording declarations of variables and it already knows the context of variables.
Please if you add the feature record the implicit calls as well.

@mlangkabel
Copy link
Contributor

implemented with merge of pull request #863

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants