Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
-The lookahead-pattern for differentiate the 3-/4-/5-node spice-bjt
 erroneously contains newline. This causes read a spice bjt-line don't
 stop at new line and detect a 5-node bjt instead of 3-node bjt as
 happen for AD822X.cir of Opamp_AC_Tran.zip from the issue 967.
 This is fixed and tested against AD822X.cir. The critical lines from
 AD822X.cir are included in the bjt.cir qucsconv_rf testing example.

cherry-picked from 3c375fd:

Fix build issues
-fixed sprintf format buffer overflow warning: check_citi.cpp,
 check_mdl.cpp, check_spice.cpp
-fixed signed compare/expression warning: check_mdl.cpp, circuit.cpp,
 hbsolver.cpp, e_trsolver.cpp, nasolver.cpp, spline.cpp, tmatrix.cpp,
 tvector.cpp
-fixed clearing of non-trivial type via memset warning by static_cast:
 circuit.cpp, tmatrix.cpp
-fixed int-in-bool-context warning: thyristor.cpp
-fixed unnecessary parentheses warning: environment.cpp, equation.cpp,
 evaluate.cpp
-fixed case fallthrough warning: equation.cpp
-fixed unused parameter/variable warning: e_trsolver.cpp, real.cpp, qucs_action.cpp
-fixed infinite recursion warning: real.cpp, real.h
-fixed format type warning: module.cpp
-fixed depracated copy warning by adding assignment operator: strlist.cpp,
 strlist.h
-fixed misleading indentation warning: vector.cpp
-fixed deprecated yacc/bison name-prefix directive warning: parse_spice.ypp,
 parse_vcd.ypp, parse_citi.ypp, parse_csv.ypp, parse_dataset.ypp, parse_mdl.ypp
 parse_mdl.ypp parse_netlist.ypp, parse_touchstone.ypp parse_zvr.ypp
-fixed useless yacc/bison symbol definition: parse_vcd.ypp
-fixed shift/reduce-conflicts (sr) and reduce/reduce-conflicts (rr) of the spice-parser
 build by parse_spice.ypp and scan_spice.lpp:
   -sr-conflicts solved by introducing token/rule precedence
   -rr-conflicts solved by introducing token lookahead's in the spice scanner
   -verification of equalness of generated output from both the converter before and
    after the code change done with spice input bjt.cir done
-fixed shift/reduce-conflicts (sr) and reduce/reduce-conflicts (rr) of the csv-parser
 build by parse_csv.ypp and scan_csv.lpp:
   -sr/rr-conflicts solved by downsize and reorder grammatic rules
   -verification of equalness of generated output from both the converter before and
    after the code change done with csv input qucs_csv.csv done
-removed useless scanner token definition and replaced misleading operator assocativity
 with precedence: parse_netlist.ypp
-fixed shift/reduce-conflicts (sr) of the touchstone-parser build by parse_touchstone.ypp and
 scan_touchstonelpp:
   -sr conflicts solved by remove useless/redundant grammatic rules
   -verification of equalness of generated output from both the converter before and
    after the code change done with touchstone input R50C1pF.s1p done

Signed-off-by: ThomasZecha <[email protected]>
  • Loading branch information
ThomasZecha committed Oct 4, 2024
1 parent b1072f1 commit fdbdaba
Show file tree
Hide file tree
Showing 35 changed files with 297 additions and 160 deletions.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ foreach(type ${ParserTypes})
${BISON_EXECUTABLE}
--defines=parse_${type}.hpp
--output=parse_${type}.cpp
-v
-Wprecedence
${bisonIn}
DEPENDS ${bisonIn})
# Create custom Flex
Expand Down
95 changes: 47 additions & 48 deletions src/check_citi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ static char * citi_get_package (struct citi_package_t * p) {
}

/* Create a valid vector for the dataset. */
static qucs::vector * citi_create_vector (struct citi_package_t * p, int i,
char * n, char * type) {
static qucs::vector * citi_create_vector (struct citi_package_t * p, int i, char * n, char * type) {
qucs::vector * vec;
vec = citi_get_vector (p, i); // fetch vector
vec = new qucs::vector (*vec); // copy vector
Expand Down Expand Up @@ -195,8 +194,8 @@ int citi_check (void) {
int cvar = citi_count_variables (p);
if (cvec != cvar) {
logprint (LOG_ERROR, "checker error, no. of vectors (%d) does not equal "
"no. of variables (%d) in package `%s'\n", cvec, cvar,
package);
"no. of variables (%d) in package `%s'\n", cvec, cvar,
package);
errors++;
break;
}
Expand All @@ -213,50 +212,50 @@ int citi_check (void) {
for (h = p->head; h != NULL; h = h->next) {
qucs::vector * v;
if (h->var != NULL) {
char txt[256];
if (h->i1 >= 0) {
/* dependent variables */
if (h->i2 >= 0) {
sprintf (txt, "%s%s[%d,%d]", opack, h->var, h->i1, h->i2);
v = citi_create_vector (p, n, txt, h->type);
v->setDependencies (new strlist (deps));
errors += citi_check_dep_length (v, deps, package);
citi_result->addVariable (v);
n++;
} else {
sprintf (txt, "%s%s[%d]", opack, h->var, h->i1);
v = citi_create_vector (p, n, txt, h->type);
v->setDependencies (new strlist (deps));
errors += citi_check_dep_length (v, deps, package);
citi_result->addVariable (v);
n++;
}
} else if (h->n >= 0) {
/* independent variable */
sprintf (txt, "%s%s", opack, h->var);
v = citi_create_vector (p, n, txt, h->type);
deps.add (txt);
if (!citi_result->findDependency (txt)) {
/* add independent vectors only once */
citi_result->addDependency (v);
}
n++;
// check length of independent vector
if (v->getSize () != h->n) {
logprint (LOG_ERROR, "checker error, vector `%s' length (%d) "
"does not equal defined length (%d) in package `%s'\n",
h->var, v->getSize (), h->n, package);
errors++;
}
} else {
/* dependent variables, no indices */
sprintf (txt, "%s%s", opack, h->var);
v = citi_create_vector (p, n, txt, h->type);
v->setDependencies (new strlist (deps));
errors += citi_check_dep_length (v, deps, package);
citi_result->addVariable (v);
n++;
}
char txt[sizeof(opack) + 16];
if (h->i1 >= 0) {
/* dependent variables */
if (h->i2 >= 0) {
sprintf (txt, "%s%s[%d,%d]", opack, h->var, h->i1, h->i2);
v = citi_create_vector (p, n, txt, h->type);
v->setDependencies (new strlist (deps));
errors += citi_check_dep_length (v, deps, package);
citi_result->addVariable (v);
n++;
} else {
sprintf (txt, "%s%s[%d]", opack, h->var, h->i1);
v = citi_create_vector (p, n, txt, h->type);
v->setDependencies (new strlist (deps));
errors += citi_check_dep_length (v, deps, package);
citi_result->addVariable (v);
n++;
}
} else if (h->n >= 0) {
/* independent variable */
sprintf (txt, "%s%s", opack, h->var);
v = citi_create_vector (p, n, txt, h->type);
deps.add (txt);
if (!citi_result->findDependency (txt)) {
/* add independent vectors only once */
citi_result->addDependency (v);
}
n++;
// check length of independent vector
if (v->getSize () != h->n) {
logprint (LOG_ERROR, "checker error, vector `%s' length (%d) "
"does not equal defined length (%d) in package `%s'\n",
h->var, v->getSize (), h->n, package);
errors++;
}
} else {
/* dependent variables, no indices */
sprintf (txt, "%s%s", opack, h->var);
v = citi_create_vector (p, n, txt, h->type);
v->setDependencies (new strlist (deps));
errors += citi_check_dep_length (v, deps, package);
citi_result->addVariable (v);
n++;
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/check_mdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ valuelist<int> * mdl_find_depdataset (struct mdl_link_t * link,
else if (!strcmp (hyptab->name, "List Table")) {
lstsweep * sw = new lstsweep ();
sw->create (nof);
char txt[16];
char txt[32];
for (int i = 0; i < nof; i++) {
sprintf (txt, "Value %d", i + 1);
val = mdl_helement_dvalue (link, hyptab->data, txt);
Expand Down Expand Up @@ -418,7 +418,7 @@ static void mdl_find_varlink (struct mdl_link_t * link, char * name,
// Sorts a dependency list according to their sweep order.
static strlist * mdl_sort_deps (valuelist<int> * d) {
strlist * deps = new strlist ();
for (int i = 0; i < d->size(); i++) {
for (int i = 0; i < static_cast<int>(d->size()); i++) {
for (auto &val: *d) {
if (val.second == i + 1) {
deps->append (val.first.c_str());
Expand Down
38 changes: 19 additions & 19 deletions src/circuit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,22 +229,22 @@ void circuit::freeMatrixHB (void) {
/* Allocates the HB-matrix memory. */
void circuit::allocMatrixHB (void) {
if (VectorQ) {
memset (VectorQ, 0, size * sizeof (nr_complex_t));
memset (static_cast<void*>(VectorQ), 0, size * sizeof (nr_complex_t));
} else {
VectorQ = new nr_complex_t[size];
}
if (MatrixQV) {
memset (MatrixQV, 0, size * size * sizeof (nr_complex_t));
memset (static_cast<void*>(MatrixQV), 0, size * size * sizeof (nr_complex_t));
} else {
MatrixQV = new nr_complex_t[size * size];
}
if (VectorCV) {
memset (VectorCV, 0, size * sizeof (nr_complex_t));
memset (static_cast<void*>(VectorCV), 0, size * sizeof (nr_complex_t));
} else {
VectorCV = new nr_complex_t[size];
}
if (VectorGV) {
memset (VectorGV, 0, size * sizeof (nr_complex_t));
memset (static_cast<void*>(VectorGV), 0, size * sizeof (nr_complex_t));
} else {
VectorGV = new nr_complex_t[size];
}
Expand All @@ -253,7 +253,7 @@ void circuit::allocMatrixHB (void) {
/* Allocates the S-parameter matrix memory. */
void circuit::allocMatrixS (void) {
if (MatrixS) {
memset (MatrixS, 0, size * size * sizeof (nr_complex_t));
memset (static_cast<void*>(MatrixS), 0, size * size * sizeof (nr_complex_t));
} else {
MatrixS = new nr_complex_t[size * size];
}
Expand Down Expand Up @@ -654,8 +654,8 @@ void circuit::setMatrixS (matrix s) {
circuit. */
matrix circuit::getMatrixS (void) {
matrix res (size);
for(unsigned int i=0; i < size; ++i)
for(unsigned int j=0; j < size; ++j)
for(int i=0; i < size; ++i)
for(int j=0; j < size; ++j)
res(i,j) = MatrixS[i*size + j];
return res;
}
Expand All @@ -675,8 +675,8 @@ void circuit::setMatrixN (matrix n) {
matrix of the circuit. */
matrix circuit::getMatrixN (void) {
matrix res (size);
for(unsigned int i=0; i < size; ++i)
for(unsigned int j=0; j < size; ++j)
for(int i=0; i < size; ++i)
for(int j=0; j < size; ++j)
res(i,j) = MatrixN[i*size + j];
return res;
}
Expand All @@ -696,50 +696,50 @@ void circuit::setMatrixY (matrix y) {
circuit. */
matrix circuit::getMatrixY (void) {
matrix res (size);
for(unsigned int i=0; i < size; ++i)
for(unsigned int j=0; j < size; ++j)
for(int i=0; i < size; ++i)
for(int j=0; j < size; ++j)
res(i,j) = MatrixY[i*size + j];
return res;
}

// The function cleans up the B-MNA matrix entries.
void circuit::clearB (void) {
memset (MatrixB, 0, sizeof (nr_complex_t) * size * vsources);
memset (static_cast<void*>(MatrixB), 0, sizeof (nr_complex_t) * size * vsources);
}

// The function cleans up the C-MNA matrix entries.
void circuit::clearC (void) {
memset (MatrixC, 0, sizeof (nr_complex_t) * size * vsources);
memset (static_cast<void*>(MatrixC), 0, sizeof (nr_complex_t) * size * vsources);
}

// The function cleans up the D-MNA matrix entries.
void circuit::clearD (void) {
memset (MatrixD, 0, sizeof (nr_complex_t) * vsources * vsources);
memset (static_cast<void*>(MatrixD), 0, sizeof (nr_complex_t) * vsources * vsources);
}

// The function cleans up the E-MNA matrix entries.
void circuit::clearE (void) {
memset (VectorE, 0, sizeof (nr_complex_t) * vsources);
memset (static_cast<void*>(VectorE), 0, sizeof (nr_complex_t) * vsources);
}

// The function cleans up the J-MNA matrix entries.
void circuit::clearJ (void) {
memset (VectorJ, 0, sizeof (nr_complex_t) * vsources);
memset (static_cast<void*>(VectorJ), 0, sizeof (nr_complex_t) * vsources);
}

// The function cleans up the I-MNA matrix entries.
void circuit::clearI (void) {
memset (VectorI, 0, sizeof (nr_complex_t) * size);
memset (static_cast<void*>(VectorI), 0, sizeof (nr_complex_t) * size);
}

// The function cleans up the V-MNA matrix entries.
void circuit::clearV (void) {
memset (VectorV, 0, sizeof (nr_complex_t) * size);
memset (static_cast<void*>(VectorV), 0, sizeof (nr_complex_t) * size);
}

// The function cleans up the G-MNA matrix entries.
void circuit::clearY (void) {
memset (MatrixY, 0, sizeof (nr_complex_t) * size * size);
memset (static_cast<void*>(MatrixY), 0, sizeof (nr_complex_t) * size * size);
}

/* This function can be used by several components in order to place
Expand Down
2 changes: 1 addition & 1 deletion src/components/devices/thyristor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void thyristor::calcTheModel (bool last) {
isOn = Ud > Ud_bo;

nr_double_t Vak = real (getV (NODE_A1) - getV (NODE_A2));
isOn *= (Vak > 0.0);
isOn &= (Vak > 0.0);

if (Ud >= 80.0) {
Id *= std::exp (80.0) * (1.0 + Ud - 80.0) - 1.0;
Expand Down
2 changes: 1 addition & 1 deletion src/components/microstrip/bondwire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ void bondwire::calcDC(void)
}
}

void bondwire::calcTR(nr_double_t t)
void bondwire::calcTR()
{
calcDC();
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/microstrip/bondwire.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class bondwire : public qucs::circuit
void initTR (void);
void calcDC (void);
void calcAC (nr_double_t);
void calcTR (nr_double_t);
void calcTR ();
void calcNoiseAC (nr_double_t);
qucs::matrix calcMatrixY (nr_double_t);
void saveCharacteristics (nr_double_t);
Expand Down
6 changes: 5 additions & 1 deletion src/converter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ foreach(type ${ParserTypes})
${BISON_EXECUTABLE}
--defines=parse_${type}.hpp
--output=parse_${type}.cpp
-v
-Wce
-Wprecedence
-Wmidrule-value
${bisonIn}
DEPENDS ${bisonIn})
# Create custom Flex
Expand Down Expand Up @@ -60,4 +64,4 @@ target_link_libraries(qucsconv_rf libqucsator ${CMAKE_DL_LIBS})
#
# Handle installation
#
install(TARGETS qucsconv_rf DESTINATION bin)
install(TARGETS qucsconv_rf DESTINATION bin)
2 changes: 1 addition & 1 deletion src/converter/check_spice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ static void spice_translate_nodes (struct definition_t * def, int pass) {
node->node = strdup (t->node);
else {
// no node given, occurs in device descriptions
char txt[16];
char txt[17];
sprintf (txt, "%s%d", "_node", n);
node->node = strdup (txt);
}
Expand Down
Loading

0 comments on commit fdbdaba

Please sign in to comment.