diff --git a/.gitignore b/.gitignore index 78c93ff..31eed88 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ src/parseLEX.cpp *.swp *.eps *.plt +.vscode/ diff --git a/Makefile b/Makefile index 48d6523..96e220c 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,22 @@ -LEX = flex +LEX = flex YACC = bison -LEX_FLAG = -Pparse -YACC_FLAG = -d -p parse +LEX_FLAG = -Pparse +YACC_FLAG = -d -p parse -CXX = g++ -#CFLAGS = -g -Iinclude -CFLAGS = -O3 -Iinclude -Wall -CSRCS = $(wildcard src/*.cpp) -CHDRS = $(wildcard include/*.h) -#COBJS = $(addsuffix .o, $(basename $(CSRCS))) +CXX = g++ +CFLAGS = -O3 -Iinclude -Wall +CFLAGS_STFU = -Wno-unused-function -Wno-unneeded-internal-declaration +CSRCS = $(wildcard src/*.cpp) +CHDRS = $(wildcard include/*.h) -COBJS = obj/main.o obj/simulator.o obj/circuit.o obj/utils.o obj/parseLEX.o obj/parseYY.o +COBJS = obj/main.o obj/simulator.o obj/circuit.o obj/utils.o obj/parseLEX.o obj/parseYY.o -all : bin/cspice +.PHONY: create_dirs + +all : create_dirs bin/cspice + +create_dirs: + mkdir -p bin obj src/parseLEX.cpp: src/parser.l src/parseYY.hpp @echo "> lexing: $<" @@ -25,6 +29,10 @@ src/parseYY.cpp src/parseYY.hpp: src/parser.y @mv parseYY.hpp src/parseYY.hpp @ln -sf src/parseYY.hpp include/parseYY.hpp +# Special rule for parseLEX.o to shut up warnings from autogenerated source +obj/parseLEX.o : src/parseLEX.cpp + $(CXX) $(CFLAGS) ${CFLAGS_STFU} -c -o $@ $< + obj/parseYY.o : src/parser.cpp bin/cspice : $(COBJS) @@ -39,5 +47,6 @@ obj/%.o : src/%.cpp $(COBJS) : $(CHDRS) clean: - -rm -f obj/* bin/* src/parseYY.cpp src/parseYY.hpp src/parseLEX.cpp + -rm -f obj/*.o bin/cspice src/parseYY.cpp src/parseYY.hpp src/parseLEX.cpp + -rm -rf bin obj diff --git a/include/parser.h b/include/parser.h index b633e12..e4028b8 100644 --- a/include/parser.h +++ b/include/parser.h @@ -10,7 +10,7 @@ using namespace std; class Parser { public: - Parser(const char *) ; + Parser(const char* fname = nullptr) ; const Circuit& getCircuit() const { return circuit; } const vector& getConfig() const { return config; } Circuit& getCircuit() { return circuit; } diff --git a/include/source.h b/include/source.h index 1e4b02f..1fdae38 100644 --- a/include/source.h +++ b/include/source.h @@ -11,8 +11,8 @@ class Source { _name() , _prevValue(0.0) , _nextValue(0.0) , - _n1(NULL) , - _n2(NULL) { } + _n1(0) , + _n2(0) { } Source(const char * name , const int n1 , const int n2 , const double pv , const double nv) : _name(name) , diff --git a/include/utils.h b/include/utils.h index fbbbec5..cd7d82a 100644 --- a/include/utils.h +++ b/include/utils.h @@ -13,7 +13,7 @@ extern void printFormula(const vector > & , ostream &) ; extern complex evalFormula(const vector & , const double&); extern vector > expandFormula(const vector > &) ; vector numericalIntegration(const vector& times,Simulator::TransferFunction& tf, unsigned shift = 8) ; -extern unsigned long long hash(const char *) ; +extern unsigned long long util_hash(const char *) ; #endif /* __UTILS_H__ */ diff --git a/src/circuit.cpp b/src/circuit.cpp index 4c73e11..9ecee33 100644 --- a/src/circuit.cpp +++ b/src/circuit.cpp @@ -111,7 +111,7 @@ void Circuit::dfs( // Be ware that, we have to take the risk of // hash(a) + hash(b) == hash(c) + hash(d), // though I don't think it would happen so easily. - hashValue += hash(current_tree[i]->formula().c_str()) ; + hashValue += util_hash(current_tree[i]->formula().c_str()) ; sign *= current_tree[i]->sign() ; } diff --git a/src/parser.cpp b/src/parser.cpp index af3ca8b..f7521f7 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1,4 +1,4 @@ -Parser::Parser(const char * fname = NULL) { +Parser::Parser(const char * fname) { extern FILE * yyin ; extern int yyparse() ; diff --git a/src/parser.l b/src/parser.l index 620af0b..af637cd 100644 --- a/src/parser.l +++ b/src/parser.l @@ -282,7 +282,7 @@ FNAME (([0-9a-zA-Z\.\-_])+\.eps) . { /* rest cases */ char msg[40] ; - sprintf(msg , "Unexpected character: '%s'" , escape(yytext)) ; + snprintf(msg , 40, "Unexpected character: '%s'" , escape(yytext)) ; yyerror(msg) ; return yytext[0] ; } diff --git a/src/utils.cpp b/src/utils.cpp index cdb5f87..8e3e06f 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -98,7 +98,7 @@ ostream& operator<<(ostream& out , const Element& element) { return out ; } -unsigned long long hash(const char * p) { +unsigned long long util_hash(const char * p) { // using FNV-1a hash algorithm const unsigned long long prime = 1099511628211ull ; unsigned long long result = 14695981039346656037ull ;