diff --git a/src/Makefile b/src/Makefile index c1cbf73..71f166c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,5 @@ -CFLAGS=-O2 -g -std=gnu++11 -fvisibility=hidden -fpic -LDFLAGS=-fvisibility=hidden -Wl,--export-dynamic -fpic +CFLAGS=-O2 -g -std=gnu++11 -fvisibility=hidden -fpic -Wall +LDFLAGS=-fvisibility=hidden -Wl,--export-dynamic -fpic -Wall CC=g++ diff --git a/src/arifmetic.cpp b/src/arifmetic.cpp index 9c2b8c3..cc18bf9 100644 --- a/src/arifmetic.cpp +++ b/src/arifmetic.cpp @@ -4,22 +4,23 @@ ObjectBase* Arifm_Add(ObjectList* input) { if(input->Size()!=2) return 0; - std::type_index t1(typeid(*input->At(0))),t2(typeid(*input->At(1))); + const ObjectBase *arg1=input->At(0),*arg2=input->At(1); + std::type_index t1(typeid(*arg1)),t2(typeid(*arg2)); std::type_index tr(typeid(ObjectReal)),ti(typeid(ObjectInt)); if( (t1!=tr && t1!=ti) || (t2!=tr && t2!=ti) ) return 0; // Integer arifmetic - if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast(input->At(0))->Value() + dynamic_cast(input->At(1))->Value()); + if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast(arg1)->Value() + dynamic_cast(arg2)->Value()); // Real arifmetic double r1,r2; - if(t1==tr) r1=dynamic_cast(input->At(0))->Value(); - else r1=dynamic_cast(input->At(0))->Value(); + if(t1==tr) r1=dynamic_cast(arg1)->Value(); + else r1=dynamic_cast(arg1)->Value(); - if(t2==tr) r2=dynamic_cast(input->At(1))->Value(); - else r2=dynamic_cast(input->At(1))->Value(); + if(t2==tr) r2=dynamic_cast(arg2)->Value(); + else r2=dynamic_cast(arg2)->Value(); return new ObjectReal(r1+r2); } @@ -28,22 +29,23 @@ ObjectBase* Arifm_Add(ObjectList* input) ObjectBase* Arifm_Sub(ObjectList* input) { if(input->Size()!=2) return 0; - std::type_index t1(typeid(*input->At(0))),t2(typeid(*input->At(1))); + const ObjectBase *arg1=input->At(0),*arg2=input->At(1); + std::type_index t1(typeid(*arg1)),t2(typeid(*arg2)); std::type_index tr(typeid(ObjectReal)),ti(typeid(ObjectInt)); if( (t1!=tr && t1!=ti) || (t2!=tr && t2!=ti) ) return 0; // Integer arifmetic - if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast(input->At(0))->Value() - dynamic_cast(input->At(1))->Value()); + if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast(arg1)->Value() - dynamic_cast(arg2)->Value()); // Real arifmetic double r1,r2; - if(t1==tr) r1=dynamic_cast(input->At(0))->Value(); - else r1=dynamic_cast(input->At(0))->Value(); + if(t1==tr) r1=dynamic_cast(arg1)->Value(); + else r1=dynamic_cast(arg1)->Value(); - if(t2==tr) r2=dynamic_cast(input->At(1))->Value(); - else r2=dynamic_cast(input->At(1))->Value(); + if(t2==tr) r2=dynamic_cast(arg2)->Value(); + else r2=dynamic_cast(arg2)->Value(); return new ObjectReal(r1-r2); } @@ -52,22 +54,23 @@ ObjectBase* Arifm_Sub(ObjectList* input) ObjectBase* Arifm_Mul(ObjectList* input) { if(input->Size()!=2) return 0; - std::type_index t1(typeid(*input->At(0))),t2(typeid(*input->At(1))); + const ObjectBase *arg1=input->At(0),*arg2=input->At(1); + std::type_index t1(typeid(*arg1)),t2(typeid(*arg2)); std::type_index tr(typeid(ObjectReal)),ti(typeid(ObjectInt)); if( (t1!=tr && t1!=ti) || (t2!=tr && t2!=ti) ) return 0; // Integer arifmetic - if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast(input->At(0))->Value() * dynamic_cast(input->At(1))->Value()); + if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast(arg1)->Value() * dynamic_cast(arg2)->Value()); // Real arifmetic double r1,r2; - if(t1==tr) r1=dynamic_cast(input->At(0))->Value(); - else r1=dynamic_cast(input->At(0))->Value(); + if(t1==tr) r1=dynamic_cast(arg1)->Value(); + else r1=dynamic_cast(arg1)->Value(); - if(t2==tr) r2=dynamic_cast(input->At(1))->Value(); - else r2=dynamic_cast(input->At(1))->Value(); + if(t2==tr) r2=dynamic_cast(arg2)->Value(); + else r2=dynamic_cast(arg2)->Value(); return new ObjectReal(r1*r2); } @@ -76,22 +79,23 @@ ObjectBase* Arifm_Mul(ObjectList* input) ObjectBase* Arifm_Div(ObjectList* input) { if(input->Size()!=2) return 0; - std::type_index t1(typeid(*input->At(0))),t2(typeid(*input->At(1))); + const ObjectBase *arg1=input->At(0),*arg2=input->At(1); + std::type_index t1(typeid(*arg1)),t2(typeid(*arg2)); std::type_index tr(typeid(ObjectReal)),ti(typeid(ObjectInt)); if( (t1!=tr && t1!=ti) || (t2!=tr && t2!=ti) ) return 0; // Integer arifmetic - if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast(input->At(0))->Value() / dynamic_cast(input->At(1))->Value()); + if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast(arg1)->Value() / dynamic_cast(arg2)->Value()); // Real arifmetic double r1,r2; - if(t1==tr) r1=dynamic_cast(input->At(0))->Value(); - else r1=dynamic_cast(input->At(0))->Value(); + if(t1==tr) r1=dynamic_cast(arg1)->Value(); + else r1=dynamic_cast(arg1)->Value(); - if(t2==tr) r2=dynamic_cast(input->At(1))->Value(); - else r2=dynamic_cast(input->At(1))->Value(); + if(t2==tr) r2=dynamic_cast(arg2)->Value(); + else r2=dynamic_cast(arg2)->Value(); return new ObjectReal(r1/r2); } @@ -100,7 +104,8 @@ ObjectBase* Arifm_Div(ObjectList* input) ObjectBase* Arifm_Pow(ObjectList* input) { if(input->Size()!=2) return 0; - std::type_index t1(typeid(*input->At(0))),t2(typeid(*input->At(1))); + const ObjectBase *arg1=input->At(0),*arg2=input->At(1); + std::type_index t1(typeid(*arg1)),t2(typeid(*arg2)); std::type_index tr(typeid(ObjectReal)),ti(typeid(ObjectInt)); if( (t1!=tr && t1!=ti) || (t2!=tr && t2!=ti) ) return 0; @@ -108,11 +113,11 @@ ObjectBase* Arifm_Pow(ObjectList* input) // Only real arifmetic double r1,r2; - if(t1==tr) r1=dynamic_cast(input->At(0))->Value(); - else r1=dynamic_cast(input->At(0))->Value(); + if(t1==tr) r1=dynamic_cast(arg1)->Value(); + else r1=dynamic_cast(arg1)->Value(); - if(t2==tr) r2=dynamic_cast(input->At(1))->Value(); - else r2=dynamic_cast(input->At(1))->Value(); + if(t2==tr) r2=dynamic_cast(arg2)->Value(); + else r2=dynamic_cast(arg2)->Value(); return new ObjectReal(pow(r1,r2)); } @@ -121,13 +126,14 @@ ObjectBase* Arifm_Pow(ObjectList* input) ObjectBase* Arifm_Neg(ObjectList* input) { if(input->Size()!=1) return 0; - std::type_index t(typeid(*input->At(0))); + const ObjectBase *arg=input->At(0); + std::type_index t(typeid(*arg)); std::type_index tr(typeid(ObjectReal)),ti(typeid(ObjectInt)); // Integer arifmetic - if(t==ti) return new ObjectInt(-dynamic_cast(input->At(0))->Value()); + if(t==ti) return new ObjectInt(-dynamic_cast(arg)->Value()); // Real arifmetic - if(t==tr) return new ObjectReal(-dynamic_cast(input->At(0))->Value()); + if(t==tr) return new ObjectReal(-dynamic_cast(arg)->Value()); return 0; } @@ -136,13 +142,14 @@ ObjectBase* Arifm_Neg(ObjectList* input) ObjectBase* Arifm_Pos(ObjectList* input) { if(input->Size()!=1) return 0; - std::type_index t(typeid(*input->At(0))); + const ObjectBase *arg=input->At(0); + std::type_index t(typeid(*arg)); std::type_index tr(typeid(ObjectReal)),ti(typeid(ObjectInt)); // Integer arifmetic - if(t==ti) return new ObjectInt(dynamic_cast(input->At(0))->Value()); + if(t==ti) return new ObjectInt(dynamic_cast(arg)->Value()); // Real arifmetic - if(t==tr) return new ObjectReal(dynamic_cast(input->At(0))->Value()); + if(t==tr) return new ObjectReal(dynamic_cast(arg)->Value()); return 0; } diff --git a/src/debug.h b/src/debug.h index 76803b4..c67e7c5 100644 --- a/src/debug.h +++ b/src/debug.h @@ -5,9 +5,7 @@ enum debug_level {INTERNALREQUEST,MOREDEBUG,DEBUG,INFO,WARNING,ERROR}; -extern "C" { EXPORT std::ostream& COUT(debug_level dl); -} debug_level SetDebugLevel(debug_level dl=INTERNALREQUEST); diff --git a/src/deptree.cpp b/src/deptree.cpp index 503a749..5f80f58 100644 --- a/src/deptree.cpp +++ b/src/deptree.cpp @@ -103,14 +103,14 @@ int DepTree::CreateGlobalTree(UsedType& used) } type=DepTree::ROOT; - for(int i=0; iparents.insert(this); auto ret=n->CreateNodeFromSP(DepTree::SAVE,i,used); if(ret!=0) return ret; } - for(int i=0; iparents.insert(this); diff --git a/src/parser/lexical.l b/src/parser/lexical.l index 8062dc5..485bea4 100644 --- a/src/parser/lexical.l +++ b/src/parser/lexical.l @@ -9,6 +9,7 @@ %option extra-type="struct lexical_extra*" %option bison-bridge %option bison-locations +%option nounput %x PSTRING %x PARSE @@ -22,6 +23,8 @@ #include "../object.h" #include "parser.h" #include "grammatical.h" +// Get rid of warning on unneeded function +#define YY_NO_INPUT static std::string str; %}