Skip to content

Commit

Permalink
refactor : use std::unreachable()
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaslepoix committed Sep 12, 2024
1 parent 2d5eb42 commit 3a07ab5
Show file tree
Hide file tree
Showing 23 changed files with 302 additions and 140 deletions.
4 changes: 2 additions & 2 deletions src/microstrip/element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ string Element::getSubst() const {

//******************************************************************************
long double Element::getX(bool const apply_shift) const {
return(m_shift_x && apply_shift ? m_x+m_shift_x : m_x); // Avoid useless float calcul.
return m_shift_x && apply_shift ? m_x+m_shift_x : m_x;
}

//******************************************************************************
long double Element::getY(bool const apply_shift) const {
return(m_shift_y && apply_shift ? m_y+m_shift_y : m_y); // Avoid useless float calcul.
return m_shift_y && apply_shift ? m_y+m_shift_y : m_y;
}

//******************************************************************************
Expand Down
28 changes: 23 additions & 5 deletions src/microstrip/mcorn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ int Mcorn::getNpoint() const {

//******************************************************************************
long double Mcorn::getP(int const _n, axis_t const _xy, orientation_t const /*_r*/, origin_t const _abs, bool const /*apply_shift*/) const {
return(_abs ? tab_p[_n][_xy]+(_xy ? m_y : m_x) : tab_p[_n][_xy]);
return _abs ? tab_p[_n][_xy]+(_xy ? m_y : m_x)
: tab_p[_n][_xy];
}

//******************************************************************************
Expand Down Expand Up @@ -143,6 +144,8 @@ void Mcorn::getStep(int const _net, long double& xstep, long double& ystep) cons
xstep= + m_w/2;
ystep=0;
}
} else {
unreachable();
}
}

Expand All @@ -155,6 +158,7 @@ void Mcorn::getEdge(int const _net, long double& edge, short& dir) const {
case 90: dir=YMAX; break;
case 180: dir=XMAX; break;
case 270: dir=YMIN; break;
default: unreachable();
}
} else if(_net==2) {
if(m_mirrorx==0) {
Expand All @@ -163,14 +167,18 @@ void Mcorn::getEdge(int const _net, long double& edge, short& dir) const {
case 90: dir=XMAX; break;
case 180: dir=YMIN; break;
case 270: dir=XMIN; break;
default: unreachable();
}
} else if(m_mirrorx==1) {
switch(m_r) {
case 0: dir=YMIN; break;
case 90: dir=XMIN; break;
case 180: dir=YMAX; break;
case 270: dir=XMAX; break;
default: unreachable();
}
} else {
unreachable();
}
}
}
Expand All @@ -188,6 +196,7 @@ int Mcorn::getOemsMeshCore(int const _n, OemsLine& line) const {
case 90: line.position=getP(2, Y, R, ABS); line.direction=YMIN; break;
case 180: line.position=getP(2, X, R, ABS); line.direction=XMIN; break;
case 270: line.position=getP(2, Y, R, ABS); line.direction=YMAX; break;
default: unreachable();
}
} else if(_n==1) {
if(m_mirrorx==0) {
Expand All @@ -196,14 +205,18 @@ int Mcorn::getOemsMeshCore(int const _n, OemsLine& line) const {
case 90: line.position=getP(2, X, R, ABS); line.direction=XMIN; break;
case 180: line.position=getP(2, Y, R, ABS); line.direction=YMAX; break;
case 270: line.position=getP(2, X, R, ABS); line.direction=XMAX; break;
default: unreachable();
}
} else if(m_mirrorx==1) {
switch(m_r) {
case 0: line.position=getP(2, Y, R, ABS); line.direction=YMAX; break;
case 90: line.position=getP(2, X, R, ABS); line.direction=XMAX; break;
case 180: line.position=getP(2, Y, R, ABS); line.direction=YMIN; break;
case 270: line.position=getP(2, X, R, ABS); line.direction=XMIN; break;
default: unreachable();
}
} else {
unreachable();
}
} else {
return 1;
Expand All @@ -225,6 +238,7 @@ int Mcorn::getOemsMeshInterface(int const _net, OemsLine& line) const {
case 90: line.position=getP(0, Y, R, ABS); line.direction=YMAX; break;
case 180: line.position=getP(0, X, R, ABS); line.direction=XMAX; break;
case 270: line.position=getP(0, Y, R, ABS); line.direction=YMIN; break;
default: unreachable();
}
} else if(_net==2
&&(adjacent2.first==nullptr
Expand All @@ -235,14 +249,18 @@ int Mcorn::getOemsMeshInterface(int const _net, OemsLine& line) const {
case 90: line.position=getP(0, X, R, ABS); line.direction=XMAX; break;
case 180: line.position=getP(0, Y, R, ABS); line.direction=YMIN; break;
case 270: line.position=getP(0, X, R, ABS); line.direction=XMIN; break;
default: unreachable();
}
} else if(m_mirrorx==1) {
switch(m_r) {
case 0: line.position=getP(0, Y, R, ABS); line.direction=YMIN; break;
case 90: line.position=getP(0, X, R, ABS); line.direction=XMIN; break;
case 180: line.position=getP(0, Y, R, ABS); line.direction=YMAX; break;
case 270: line.position=getP(0, X, R, ABS); line.direction=XMAX; break;
default: unreachable();
}
} else {
unreachable();
}
} else {
return 1;
Expand All @@ -256,10 +274,10 @@ int Mcorn::getOemsMeshInterface(int const _net, OemsLine& line) const {

//******************************************************************************
bool Mcorn::isOemsMeshInterface(int const _port, long double const _w) const {
if(_port==1 || _port==2) {
return(_w>m_w ? true : false);
} else {
return false;
switch(_port) {
case 1: [[fallthrough]];
case 2: return _w>m_w ? true : false;
default: return false;
}
}

Expand Down
38 changes: 26 additions & 12 deletions src/microstrip/mcoupled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,16 @@ int Mcoupled::getNpoint() const {

//******************************************************************************
long double Mcoupled::getP(int const _n, axis_t const _xy, orientation_t const _r, origin_t const _abs, bool const /*apply_shift*/) const {
long double coord;
if(_r) {
coord= _xy ? rotateY(tab_p[_n][X], tab_p[_n][Y])
: rotateX(tab_p[_n][X], tab_p[_n][Y]);
} else {
coord=tab_p[_n][_xy];
}
return(_abs ? coord+(_xy ? m_y : m_x) : coord);
long double const coord= [&]() {
switch(_r) {
case NOR: return tab_p[_n][_xy];
case R: return _xy ? rotateY(tab_p[_n][X], tab_p[_n][Y])
: rotateX(tab_p[_n][X], tab_p[_n][Y]);
default: unreachable();
}
} ();
return _abs ? coord+(_xy ? m_y : m_x)
: coord;
}

//******************************************************************************
Expand Down Expand Up @@ -242,6 +244,8 @@ void Mcoupled::getStep(int const _net, long double& xstep, long double& ystep) c
xstep= + (m_w+m_s)/2;
ystep= - m_l/2;
}
} else {
unreachable();
}
}

Expand All @@ -254,13 +258,15 @@ void Mcoupled::getEdge(int const _net, long double& edge, short& dir) const {
case 90: dir=YMAX; break;
case 180: dir=XMAX; break;
case 270: dir=YMIN; break;
default: unreachable();
}
} else if(_net==2 || _net==3) {
switch(m_r) {
case 0: dir=XMAX; break;
case 90: dir=YMIN; break;
case 180: dir=XMIN; break;
case 270: dir=YMAX; break;
default: unreachable();
}
}
}
Expand All @@ -278,27 +284,31 @@ int Mcoupled::getOemsMeshCore(int const _n, OemsLine& line) const {
case 90: line.position=getP(0, X, R, ABS); line.direction=XMAX; break;
case 180: line.position=getP(0, Y, R, ABS); line.direction=YMIN; break;
case 270: line.position=getP(0, X, R, ABS); line.direction=XMIN; break;
default: unreachable();
}
} else if(_n==1) {
switch(m_r) {
case 0: line.position=getP(2, Y, R, ABS); line.direction=YMIN; break;
case 90: line.position=getP(2, X, R, ABS); line.direction=XMIN; break;
case 180: line.position=getP(2, Y, R, ABS); line.direction=YMAX; break;
case 270: line.position=getP(2, X, R, ABS); line.direction=XMAX; break;
default: unreachable();
}
} else if(_n==2) {
switch(m_r) {
case 0: line.position=getP(4, Y, R, ABS); line.direction=YMAX; break;
case 90: line.position=getP(4, X, R, ABS); line.direction=XMAX; break;
case 180: line.position=getP(4, Y, R, ABS); line.direction=YMIN; break;
case 270: line.position=getP(4, X, R, ABS); line.direction=XMIN; break;
default: unreachable();
}
} else if(_n==3) {
switch(m_r) {
case 0: line.position=getP(6, Y, R, ABS); line.direction=YMIN; break;
case 90: line.position=getP(6, X, R, ABS); line.direction=XMIN; break;
case 180: line.position=getP(6, Y, R, ABS); line.direction=YMAX; break;
case 270: line.position=getP(6, X, R, ABS); line.direction=XMAX; break;
default: unreachable();
}
} else {
return 1;
Expand All @@ -323,6 +333,7 @@ int Mcoupled::getOemsMeshInterface(int const _net, OemsLine& line) const {
case 90: line.position=getP(0, Y, R, ABS); line.direction=YMAX; break;
case 180: line.position=getP(0, X, R, ABS); line.direction=XMAX; break;
case 270: line.position=getP(0, Y, R, ABS); line.direction=YMIN; break;
default: unreachable();
}
} else if((_net==2
&&(adjacent2.first==nullptr
Expand All @@ -335,6 +346,7 @@ int Mcoupled::getOemsMeshInterface(int const _net, OemsLine& line) const {
case 90: line.position=getP(2, Y, R, ABS); line.direction=YMIN; break;
case 180: line.position=getP(2, X, R, ABS); line.direction=XMIN; break;
case 270: line.position=getP(2, Y, R, ABS); line.direction=YMAX; break;
default: unreachable();
}
} else {
return 1;
Expand All @@ -348,10 +360,12 @@ int Mcoupled::getOemsMeshInterface(int const _net, OemsLine& line) const {

//******************************************************************************
bool Mcoupled::isOemsMeshInterface(int const _port, long double const _w) const {
if(_port==1 || _port==2 || _port==3 || _port==4) {
return(_w>m_w ? true : false);
} else {
return false;
switch(_port) {
case 1: [[fallthrough]];
case 2: [[fallthrough]];
case 3: [[fallthrough]];
case 4: return _w>m_w ? true : false;
default: return false;
}
}

Expand Down
Loading

0 comments on commit 3a07ab5

Please sign in to comment.