Skip to content

Commit

Permalink
odb: generating a default constructor for classes without destructibl…
Browse files Browse the repository at this point in the history
…e fields

Signed-off-by: Felipe Garay <[email protected]>
  • Loading branch information
fgaray committed Nov 21, 2023
1 parent 28892de commit fbb3099
Show file tree
Hide file tree
Showing 62 changed files with 108 additions and 147 deletions.
6 changes: 6 additions & 0 deletions src/odb/src/codeGenerator/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ def get_json_files(directory):
else:
field["setterArgumentType"] = field["getterReturnType"] = field["type"]

if field["name"] == '_name' and 'no-destruct' not in field["flags"]:
klass["has_destructible_fields"] = True

if "table" in field:
klass["has_destructible_fields"] = True

klass["fields"] = [field for field in klass["fields"] if "bits" not in field]

klass["hasBitFields"] = False
Expand Down
5 changes: 5 additions & 0 deletions src/odb/src/codeGenerator/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,8 @@ def get_ref_type(type_name):
return None

return type_name[6:-1] + "*"

def has_destructible_field(klass):
for field in klass["fields"]:
return True
return False
34 changes: 18 additions & 16 deletions src/odb/src/codeGenerator/templates/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,21 +291,23 @@ namespace odb {
}
{% endif %}

_{{klass.name}}::~_{{klass.name}}()
{
{% for field in klass.fields %}
{% if field.name == '_name' and 'no-destruct' not in field.flags %}
if (_name) {
free((void*) _name);
}
{% endif %}
{% if field.table %}
delete {{field.name}};
{% endif %}
{% endfor %}
//User Code Begin Destructor
//User Code End Destructor
}
{% if klass.has_destructible_fields %}
_{{klass.name}}::~_{{klass.name}}()
{
{% for field in klass.fields %}
{% if field.name == '_name' and 'no-destruct' not in field.flags %}
if (_name) {
free((void*) _name);
}
{% endif %}
{% if field.table %}
delete {{field.name}};
{% endif %}
{% endfor %}
//User Code Begin Destructor
//User Code End Destructor
}
{% endif %}

//User Code Begin PrivateMethods
//User Code End PrivateMethods
Expand Down Expand Up @@ -404,5 +406,5 @@ namespace odb {

//User Code Begin {{klass.name}}PublicMethods
//User Code End {{klass.name}}PublicMethods
}
} // namespace odb
// Generator Code End Cpp
9 changes: 7 additions & 2 deletions src/odb/src/codeGenerator/templates/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ namespace odb {

_{{klass.name}}(_dbDatabase*, const _{{klass.name}}& r);
_{{klass.name}}(_dbDatabase*);
~_{{klass.name}}();

{% if klass.has_destructible_fields %}
~_{{klass.name}}();
{% else %}
~_{{klass.name}}() = default;
{% endif %}

bool operator==(const _{{klass.name}}& rhs) const;
bool operator!=(const _{{klass.name}}& rhs) const { return !operator==(rhs); }
Expand Down Expand Up @@ -121,5 +126,5 @@ dbIStream& operator>>(dbIStream& stream, _{{klass.name}}& obj);
dbOStream& operator<<(dbOStream& stream, const _{{klass.name}}& obj);
// User Code Begin General
// User Code End General
}
} // namespace odb
//Generator Code End Header
6 changes: 1 addition & 5 deletions src/odb/src/db/dbAccessPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,6 @@ dbOStream& operator<<(dbOStream& stream, const _dbAccessPoint& obj)
return stream;
}

_dbAccessPoint::~_dbAccessPoint()
{
}

// User Code Begin PrivateMethods
void _dbAccessPoint::setMPin(_dbMPin* mpin)
{
Expand Down Expand Up @@ -483,4 +479,4 @@ void dbAccessPoint::destroy(dbAccessPoint* ap)
}
// User Code End dbAccessPointPublicMethods
} // namespace odb
// Generator Code End Cpp
// Generator Code End Cpp
3 changes: 2 additions & 1 deletion src/odb/src/db/dbAccessPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class _dbAccessPoint : public _dbObject
public:
_dbAccessPoint(_dbDatabase*, const _dbAccessPoint& r);
_dbAccessPoint(_dbDatabase*);
~_dbAccessPoint();

~_dbAccessPoint() = default;

bool operator==(const _dbAccessPoint& rhs) const;
bool operator!=(const _dbAccessPoint& rhs) const { return !operator==(rhs); }
Expand Down
6 changes: 1 addition & 5 deletions src/odb/src/db/dbGCellGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,6 @@ dbOStream& operator<<(dbOStream& stream, const _dbGCellGrid& obj)
return stream;
}

_dbGCellGrid::~_dbGCellGrid()
{
}

// User Code Begin PrivateMethods

dbIStream& operator>>(dbIStream& stream, dbGCellGrid::GCellData& obj)
Expand Down Expand Up @@ -769,4 +765,4 @@ dbMatrix<dbGCellGrid::GCellData> dbGCellGrid::getCongestionMap(
}
// User Code End dbGCellGridPublicMethods
} // namespace odb
// Generator Code End Cpp
// Generator Code End Cpp
3 changes: 2 additions & 1 deletion src/odb/src/db/dbGCellGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class _dbGCellGrid : public _dbObject
public:
_dbGCellGrid(_dbDatabase*, const _dbGCellGrid& r);
_dbGCellGrid(_dbDatabase*);
~_dbGCellGrid();

~_dbGCellGrid() = default;

bool operator==(const _dbGCellGrid& rhs) const;
bool operator!=(const _dbGCellGrid& rhs) const { return !operator==(rhs); }
Expand Down
4 changes: 0 additions & 4 deletions src/odb/src/db/dbGlobalConnect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ dbOStream& operator<<(dbOStream& stream, const _dbGlobalConnect& obj)
return stream;
}

_dbGlobalConnect::~_dbGlobalConnect()
{
}

////////////////////////////////////////////////////////////////////
//
// dbGlobalConnect - Methods
Expand Down
3 changes: 2 additions & 1 deletion src/odb/src/db/dbGlobalConnect.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class _dbGlobalConnect : public _dbObject
public:
_dbGlobalConnect(_dbDatabase*, const _dbGlobalConnect& r);
_dbGlobalConnect(_dbDatabase*);
~_dbGlobalConnect();

~_dbGlobalConnect() = default;

bool operator==(const _dbGlobalConnect& rhs) const;
bool operator!=(const _dbGlobalConnect& rhs) const
Expand Down
2 changes: 1 addition & 1 deletion src/odb/src/db/dbGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,4 +573,4 @@ dbGroup* dbGroup::getGroup(dbBlock* block_, uint dbid_)

// User Code End dbGroupPublicMethods
} // namespace odb
// Generator Code End Cpp
// Generator Code End Cpp
1 change: 1 addition & 0 deletions src/odb/src/db/dbGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class _dbGroup : public _dbObject
public:
_dbGroup(_dbDatabase*, const _dbGroup& r);
_dbGroup(_dbDatabase*);

~_dbGroup();

bool operator==(const _dbGroup& rhs) const;
Expand Down
4 changes: 0 additions & 4 deletions src/odb/src/db/dbGuide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ dbOStream& operator<<(dbOStream& stream, const _dbGuide& obj)
return stream;
}

_dbGuide::~_dbGuide()
{
}

////////////////////////////////////////////////////////////////////
//
// dbGuide - Methods
Expand Down
3 changes: 2 additions & 1 deletion src/odb/src/db/dbGuide.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class _dbGuide : public _dbObject
public:
_dbGuide(_dbDatabase*, const _dbGuide& r);
_dbGuide(_dbDatabase*);
~_dbGuide();

~_dbGuide() = default;

bool operator==(const _dbGuide& rhs) const;
bool operator!=(const _dbGuide& rhs) const { return !operator==(rhs); }
Expand Down
1 change: 1 addition & 0 deletions src/odb/src/db/dbIsolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class _dbIsolation : public _dbObject
public:
_dbIsolation(_dbDatabase*, const _dbIsolation& r);
_dbIsolation(_dbDatabase*);

~_dbIsolation();

bool operator==(const _dbIsolation& rhs) const;
Expand Down
1 change: 1 addition & 0 deletions src/odb/src/db/dbLogicPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class _dbLogicPort : public _dbObject
public:
_dbLogicPort(_dbDatabase*, const _dbLogicPort& r);
_dbLogicPort(_dbDatabase*);

~_dbLogicPort();

bool operator==(const _dbLogicPort& rhs) const;
Expand Down
4 changes: 0 additions & 4 deletions src/odb/src/db/dbMetalWidthViaMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,6 @@ dbOStream& operator<<(dbOStream& stream, const _dbMetalWidthViaMap& obj)
return stream;
}

_dbMetalWidthViaMap::~_dbMetalWidthViaMap()
{
}

////////////////////////////////////////////////////////////////////
//
// dbMetalWidthViaMap - Methods
Expand Down
3 changes: 2 additions & 1 deletion src/odb/src/db/dbMetalWidthViaMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class _dbMetalWidthViaMap : public _dbObject
public:
_dbMetalWidthViaMap(_dbDatabase*, const _dbMetalWidthViaMap& r);
_dbMetalWidthViaMap(_dbDatabase*);
~_dbMetalWidthViaMap();

~_dbMetalWidthViaMap() = default;

bool operator==(const _dbMetalWidthViaMap& rhs) const;
bool operator!=(const _dbMetalWidthViaMap& rhs) const
Expand Down
2 changes: 1 addition & 1 deletion src/odb/src/db/dbModInst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,4 @@ std::string dbModInst::getHierarchicalName() const
}
// User Code End dbModInstPublicMethods
} // namespace odb
// Generator Code End Cpp
// Generator Code End Cpp
1 change: 1 addition & 0 deletions src/odb/src/db/dbModInst.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class _dbModInst : public _dbObject
public:
_dbModInst(_dbDatabase*, const _dbModInst& r);
_dbModInst(_dbDatabase*);

~_dbModInst();

bool operator==(const _dbModInst& rhs) const;
Expand Down
2 changes: 1 addition & 1 deletion src/odb/src/db/dbModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,4 @@ std::string dbModule::getHierarchicalName() const

// User Code End dbModulePublicMethods
} // namespace odb
// Generator Code End Cpp
// Generator Code End Cpp
1 change: 1 addition & 0 deletions src/odb/src/db/dbModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class _dbModule : public _dbObject
public:
_dbModule(_dbDatabase*, const _dbModule& r);
_dbModule(_dbDatabase*);

~_dbModule();

bool operator==(const _dbModule& rhs) const;
Expand Down
4 changes: 0 additions & 4 deletions src/odb/src/db/dbNetTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ dbOStream& operator<<(dbOStream& stream, const _dbNetTrack& obj)
return stream;
}

_dbNetTrack::~_dbNetTrack()
{
}

////////////////////////////////////////////////////////////////////
//
// dbNetTrack - Methods
Expand Down
3 changes: 2 additions & 1 deletion src/odb/src/db/dbNetTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class _dbNetTrack : public _dbObject
public:
_dbNetTrack(_dbDatabase*, const _dbNetTrack& r);
_dbNetTrack(_dbDatabase*);
~_dbNetTrack();

~_dbNetTrack() = default;

bool operator==(const _dbNetTrack& rhs) const;
bool operator!=(const _dbNetTrack& rhs) const { return !operator==(rhs); }
Expand Down
2 changes: 1 addition & 1 deletion src/odb/src/db/dbPowerDomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,4 +344,4 @@ bool dbPowerDomain::getArea(int& _x1, int& _y1, int& _x2, int& _y2)

// User Code End dbPowerDomainPublicMethods
} // namespace odb
// Generator Code End Cpp
// Generator Code End Cpp
1 change: 1 addition & 0 deletions src/odb/src/db/dbPowerDomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class _dbPowerDomain : public _dbObject
public:
_dbPowerDomain(_dbDatabase*, const _dbPowerDomain& r);
_dbPowerDomain(_dbDatabase*);

~_dbPowerDomain();

bool operator==(const _dbPowerDomain& rhs) const;
Expand Down
1 change: 1 addition & 0 deletions src/odb/src/db/dbPowerSwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class _dbPowerSwitch : public _dbObject
public:
_dbPowerSwitch(_dbDatabase*, const _dbPowerSwitch& r);
_dbPowerSwitch(_dbDatabase*);

~_dbPowerSwitch();

bool operator==(const _dbPowerSwitch& rhs) const;
Expand Down
1 change: 1 addition & 0 deletions src/odb/src/db/dbTechLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class _dbTechLayer : public _dbObject
public:
_dbTechLayer(_dbDatabase*, const _dbTechLayer& r);
_dbTechLayer(_dbDatabase*);

~_dbTechLayer();

bool operator==(const _dbTechLayer& rhs) const;
Expand Down
6 changes: 1 addition & 5 deletions src/odb/src/db/dbTechLayerAreaRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,6 @@ dbOStream& operator<<(dbOStream& stream, const _dbTechLayerAreaRule& obj)
return stream;
}

_dbTechLayerAreaRule::~_dbTechLayerAreaRule()
{
}

////////////////////////////////////////////////////////////////////
//
// dbTechLayerAreaRule - Methods
Expand Down Expand Up @@ -351,4 +347,4 @@ void dbTechLayerAreaRule::destroy(dbTechLayerAreaRule* rule)

// User Code End dbTechLayerAreaRulePublicMethods
} // namespace odb
// Generator Code End Cpp
// Generator Code End Cpp
3 changes: 2 additions & 1 deletion src/odb/src/db/dbTechLayerAreaRule.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class _dbTechLayerAreaRule : public _dbObject
public:
_dbTechLayerAreaRule(_dbDatabase*, const _dbTechLayerAreaRule& r);
_dbTechLayerAreaRule(_dbDatabase*);
~_dbTechLayerAreaRule();

~_dbTechLayerAreaRule() = default;

bool operator==(const _dbTechLayerAreaRule& rhs) const;
bool operator!=(const _dbTechLayerAreaRule& rhs) const
Expand Down
4 changes: 0 additions & 4 deletions src/odb/src/db/dbTechLayerArraySpacingRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,6 @@ dbOStream& operator<<(dbOStream& stream,
return stream;
}

_dbTechLayerArraySpacingRule::~_dbTechLayerArraySpacingRule()
{
}

////////////////////////////////////////////////////////////////////
//
// dbTechLayerArraySpacingRule - Methods
Expand Down
3 changes: 2 additions & 1 deletion src/odb/src/db/dbTechLayerArraySpacingRule.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class _dbTechLayerArraySpacingRule : public _dbObject
_dbTechLayerArraySpacingRule(_dbDatabase*,
const _dbTechLayerArraySpacingRule& r);
_dbTechLayerArraySpacingRule(_dbDatabase*);
~_dbTechLayerArraySpacingRule();

~_dbTechLayerArraySpacingRule() = default;

bool operator==(const _dbTechLayerArraySpacingRule& rhs) const;
bool operator!=(const _dbTechLayerArraySpacingRule& rhs) const
Expand Down
6 changes: 1 addition & 5 deletions src/odb/src/db/dbTechLayerCornerSpacingRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,6 @@ dbOStream& operator<<(dbOStream& stream,
return stream;
}

_dbTechLayerCornerSpacingRule::~_dbTechLayerCornerSpacingRule()
{
}

////////////////////////////////////////////////////////////////////
//
// dbTechLayerCornerSpacingRule - Methods
Expand Down Expand Up @@ -573,4 +569,4 @@ void dbTechLayerCornerSpacingRule::destroy(dbTechLayerCornerSpacingRule* rule)
}
// User Code End dbTechLayerCornerSpacingRulePublicMethods
} // namespace odb
// Generator Code End Cpp
// Generator Code End Cpp
3 changes: 2 additions & 1 deletion src/odb/src/db/dbTechLayerCornerSpacingRule.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class _dbTechLayerCornerSpacingRule : public _dbObject
_dbTechLayerCornerSpacingRule(_dbDatabase*,
const _dbTechLayerCornerSpacingRule& r);
_dbTechLayerCornerSpacingRule(_dbDatabase*);
~_dbTechLayerCornerSpacingRule();

~_dbTechLayerCornerSpacingRule() = default;

bool operator==(const _dbTechLayerCornerSpacingRule& rhs) const;
bool operator!=(const _dbTechLayerCornerSpacingRule& rhs) const
Expand Down
2 changes: 1 addition & 1 deletion src/odb/src/db/dbTechLayerCutClassRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,4 @@ void dbTechLayerCutClassRule::destroy(dbTechLayerCutClassRule* rule)
}
// User Code End dbTechLayerCutClassRulePublicMethods
} // namespace odb
// Generator Code End Cpp
// Generator Code End Cpp
Loading

0 comments on commit fbb3099

Please sign in to comment.