Browse Source

Fixed -Wall warnings

test
Michael Uleysky 9 years ago
parent
commit
21c8e0e4ad
  1. 4
      src/Makefile
  2. 77
      src/arifmetic.cpp
  3. 2
      src/debug.h
  4. 4
      src/deptree.cpp
  5. 3
      src/parser/lexical.l

4
src/Makefile

@ -1,5 +1,5 @@
CFLAGS=-O2 -g -std=gnu++11 -fvisibility=hidden -fpic CFLAGS=-O2 -g -std=gnu++11 -fvisibility=hidden -fpic -Wall
LDFLAGS=-fvisibility=hidden -Wl,--export-dynamic -fpic LDFLAGS=-fvisibility=hidden -Wl,--export-dynamic -fpic -Wall
CC=g++ CC=g++

77
src/arifmetic.cpp

@ -4,22 +4,23 @@
ObjectBase* Arifm_Add(ObjectList* input) ObjectBase* Arifm_Add(ObjectList* input)
{ {
if(input->Size()!=2) return 0; 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)); std::type_index tr(typeid(ObjectReal)),ti(typeid(ObjectInt));
if( (t1!=tr && t1!=ti) || (t2!=tr && t2!=ti) ) return 0; if( (t1!=tr && t1!=ti) || (t2!=tr && t2!=ti) ) return 0;
// Integer arifmetic // Integer arifmetic
if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast<const ObjectInt*>(input->At(0))->Value() + dynamic_cast<const ObjectInt*>(input->At(1))->Value()); if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast<const ObjectInt*>(arg1)->Value() + dynamic_cast<const ObjectInt*>(arg2)->Value());
// Real arifmetic // Real arifmetic
double r1,r2; double r1,r2;
if(t1==tr) r1=dynamic_cast<const ObjectReal*>(input->At(0))->Value(); if(t1==tr) r1=dynamic_cast<const ObjectReal*>(arg1)->Value();
else r1=dynamic_cast<const ObjectInt*>(input->At(0))->Value(); else r1=dynamic_cast<const ObjectInt*>(arg1)->Value();
if(t2==tr) r2=dynamic_cast<const ObjectReal*>(input->At(1))->Value(); if(t2==tr) r2=dynamic_cast<const ObjectReal*>(arg2)->Value();
else r2=dynamic_cast<const ObjectInt*>(input->At(1))->Value(); else r2=dynamic_cast<const ObjectInt*>(arg2)->Value();
return new ObjectReal(r1+r2); return new ObjectReal(r1+r2);
} }
@ -28,22 +29,23 @@ ObjectBase* Arifm_Add(ObjectList* input)
ObjectBase* Arifm_Sub(ObjectList* input) ObjectBase* Arifm_Sub(ObjectList* input)
{ {
if(input->Size()!=2) return 0; 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)); std::type_index tr(typeid(ObjectReal)),ti(typeid(ObjectInt));
if( (t1!=tr && t1!=ti) || (t2!=tr && t2!=ti) ) return 0; if( (t1!=tr && t1!=ti) || (t2!=tr && t2!=ti) ) return 0;
// Integer arifmetic // Integer arifmetic
if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast<const ObjectInt*>(input->At(0))->Value() - dynamic_cast<const ObjectInt*>(input->At(1))->Value()); if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast<const ObjectInt*>(arg1)->Value() - dynamic_cast<const ObjectInt*>(arg2)->Value());
// Real arifmetic // Real arifmetic
double r1,r2; double r1,r2;
if(t1==tr) r1=dynamic_cast<const ObjectReal*>(input->At(0))->Value(); if(t1==tr) r1=dynamic_cast<const ObjectReal*>(arg1)->Value();
else r1=dynamic_cast<const ObjectInt*>(input->At(0))->Value(); else r1=dynamic_cast<const ObjectInt*>(arg1)->Value();
if(t2==tr) r2=dynamic_cast<const ObjectReal*>(input->At(1))->Value(); if(t2==tr) r2=dynamic_cast<const ObjectReal*>(arg2)->Value();
else r2=dynamic_cast<const ObjectInt*>(input->At(1))->Value(); else r2=dynamic_cast<const ObjectInt*>(arg2)->Value();
return new ObjectReal(r1-r2); return new ObjectReal(r1-r2);
} }
@ -52,22 +54,23 @@ ObjectBase* Arifm_Sub(ObjectList* input)
ObjectBase* Arifm_Mul(ObjectList* input) ObjectBase* Arifm_Mul(ObjectList* input)
{ {
if(input->Size()!=2) return 0; 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)); std::type_index tr(typeid(ObjectReal)),ti(typeid(ObjectInt));
if( (t1!=tr && t1!=ti) || (t2!=tr && t2!=ti) ) return 0; if( (t1!=tr && t1!=ti) || (t2!=tr && t2!=ti) ) return 0;
// Integer arifmetic // Integer arifmetic
if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast<const ObjectInt*>(input->At(0))->Value() * dynamic_cast<const ObjectInt*>(input->At(1))->Value()); if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast<const ObjectInt*>(arg1)->Value() * dynamic_cast<const ObjectInt*>(arg2)->Value());
// Real arifmetic // Real arifmetic
double r1,r2; double r1,r2;
if(t1==tr) r1=dynamic_cast<const ObjectReal*>(input->At(0))->Value(); if(t1==tr) r1=dynamic_cast<const ObjectReal*>(arg1)->Value();
else r1=dynamic_cast<const ObjectInt*>(input->At(0))->Value(); else r1=dynamic_cast<const ObjectInt*>(arg1)->Value();
if(t2==tr) r2=dynamic_cast<const ObjectReal*>(input->At(1))->Value(); if(t2==tr) r2=dynamic_cast<const ObjectReal*>(arg2)->Value();
else r2=dynamic_cast<const ObjectInt*>(input->At(1))->Value(); else r2=dynamic_cast<const ObjectInt*>(arg2)->Value();
return new ObjectReal(r1*r2); return new ObjectReal(r1*r2);
} }
@ -76,22 +79,23 @@ ObjectBase* Arifm_Mul(ObjectList* input)
ObjectBase* Arifm_Div(ObjectList* input) ObjectBase* Arifm_Div(ObjectList* input)
{ {
if(input->Size()!=2) return 0; 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)); std::type_index tr(typeid(ObjectReal)),ti(typeid(ObjectInt));
if( (t1!=tr && t1!=ti) || (t2!=tr && t2!=ti) ) return 0; if( (t1!=tr && t1!=ti) || (t2!=tr && t2!=ti) ) return 0;
// Integer arifmetic // Integer arifmetic
if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast<const ObjectInt*>(input->At(0))->Value() / dynamic_cast<const ObjectInt*>(input->At(1))->Value()); if(t1==ti && t2==ti) return new ObjectInt(dynamic_cast<const ObjectInt*>(arg1)->Value() / dynamic_cast<const ObjectInt*>(arg2)->Value());
// Real arifmetic // Real arifmetic
double r1,r2; double r1,r2;
if(t1==tr) r1=dynamic_cast<const ObjectReal*>(input->At(0))->Value(); if(t1==tr) r1=dynamic_cast<const ObjectReal*>(arg1)->Value();
else r1=dynamic_cast<const ObjectInt*>(input->At(0))->Value(); else r1=dynamic_cast<const ObjectInt*>(arg1)->Value();
if(t2==tr) r2=dynamic_cast<const ObjectReal*>(input->At(1))->Value(); if(t2==tr) r2=dynamic_cast<const ObjectReal*>(arg2)->Value();
else r2=dynamic_cast<const ObjectInt*>(input->At(1))->Value(); else r2=dynamic_cast<const ObjectInt*>(arg2)->Value();
return new ObjectReal(r1/r2); return new ObjectReal(r1/r2);
} }
@ -100,7 +104,8 @@ ObjectBase* Arifm_Div(ObjectList* input)
ObjectBase* Arifm_Pow(ObjectList* input) ObjectBase* Arifm_Pow(ObjectList* input)
{ {
if(input->Size()!=2) return 0; 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)); std::type_index tr(typeid(ObjectReal)),ti(typeid(ObjectInt));
if( (t1!=tr && t1!=ti) || (t2!=tr && t2!=ti) ) return 0; if( (t1!=tr && t1!=ti) || (t2!=tr && t2!=ti) ) return 0;
@ -108,11 +113,11 @@ ObjectBase* Arifm_Pow(ObjectList* input)
// Only real arifmetic // Only real arifmetic
double r1,r2; double r1,r2;
if(t1==tr) r1=dynamic_cast<const ObjectReal*>(input->At(0))->Value(); if(t1==tr) r1=dynamic_cast<const ObjectReal*>(arg1)->Value();
else r1=dynamic_cast<const ObjectInt*>(input->At(0))->Value(); else r1=dynamic_cast<const ObjectInt*>(arg1)->Value();
if(t2==tr) r2=dynamic_cast<const ObjectReal*>(input->At(1))->Value(); if(t2==tr) r2=dynamic_cast<const ObjectReal*>(arg2)->Value();
else r2=dynamic_cast<const ObjectInt*>(input->At(1))->Value(); else r2=dynamic_cast<const ObjectInt*>(arg2)->Value();
return new ObjectReal(pow(r1,r2)); return new ObjectReal(pow(r1,r2));
} }
@ -121,13 +126,14 @@ ObjectBase* Arifm_Pow(ObjectList* input)
ObjectBase* Arifm_Neg(ObjectList* input) ObjectBase* Arifm_Neg(ObjectList* input)
{ {
if(input->Size()!=1) return 0; 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)); std::type_index tr(typeid(ObjectReal)),ti(typeid(ObjectInt));
// Integer arifmetic // Integer arifmetic
if(t==ti) return new ObjectInt(-dynamic_cast<const ObjectInt*>(input->At(0))->Value()); if(t==ti) return new ObjectInt(-dynamic_cast<const ObjectInt*>(arg)->Value());
// Real arifmetic // Real arifmetic
if(t==tr) return new ObjectReal(-dynamic_cast<const ObjectReal*>(input->At(0))->Value()); if(t==tr) return new ObjectReal(-dynamic_cast<const ObjectReal*>(arg)->Value());
return 0; return 0;
} }
@ -136,13 +142,14 @@ ObjectBase* Arifm_Neg(ObjectList* input)
ObjectBase* Arifm_Pos(ObjectList* input) ObjectBase* Arifm_Pos(ObjectList* input)
{ {
if(input->Size()!=1) return 0; 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)); std::type_index tr(typeid(ObjectReal)),ti(typeid(ObjectInt));
// Integer arifmetic // Integer arifmetic
if(t==ti) return new ObjectInt(dynamic_cast<const ObjectInt*>(input->At(0))->Value()); if(t==ti) return new ObjectInt(dynamic_cast<const ObjectInt*>(arg)->Value());
// Real arifmetic // Real arifmetic
if(t==tr) return new ObjectReal(dynamic_cast<const ObjectReal*>(input->At(0))->Value()); if(t==tr) return new ObjectReal(dynamic_cast<const ObjectReal*>(arg)->Value());
return 0; return 0;
} }

2
src/debug.h

@ -5,9 +5,7 @@
enum debug_level {INTERNALREQUEST,MOREDEBUG,DEBUG,INFO,WARNING,ERROR}; enum debug_level {INTERNALREQUEST,MOREDEBUG,DEBUG,INFO,WARNING,ERROR};
extern "C" {
EXPORT std::ostream& COUT(debug_level dl); EXPORT std::ostream& COUT(debug_level dl);
}
debug_level SetDebugLevel(debug_level dl=INTERNALREQUEST); debug_level SetDebugLevel(debug_level dl=INTERNALREQUEST);

4
src/deptree.cpp

@ -103,14 +103,14 @@ int DepTree::CreateGlobalTree(UsedType& used)
} }
type=DepTree::ROOT; type=DepTree::ROOT;
for(int i=0; i<G_tosave.size(); i++) for(G_toType::size_type i=0; i<G_tosave.size(); i++)
{ {
auto n=*childrens.insert(new DepTree).first; auto n=*childrens.insert(new DepTree).first;
n->parents.insert(this); n->parents.insert(this);
auto ret=n->CreateNodeFromSP(DepTree::SAVE,i,used); auto ret=n->CreateNodeFromSP(DepTree::SAVE,i,used);
if(ret!=0) return ret; if(ret!=0) return ret;
} }
for(int i=0; i<G_toprint.size(); i++) for(G_toType::size_type i=0; i<G_toprint.size(); i++)
{ {
auto n=*childrens.insert(new DepTree).first; auto n=*childrens.insert(new DepTree).first;
n->parents.insert(this); n->parents.insert(this);

3
src/parser/lexical.l

@ -9,6 +9,7 @@
%option extra-type="struct lexical_extra*" %option extra-type="struct lexical_extra*"
%option bison-bridge %option bison-bridge
%option bison-locations %option bison-locations
%option nounput
%x PSTRING %x PSTRING
%x PARSE %x PARSE
@ -22,6 +23,8 @@
#include "../object.h" #include "../object.h"
#include "parser.h" #include "parser.h"
#include "grammatical.h" #include "grammatical.h"
// Get rid of warning on unneeded function
#define YY_NO_INPUT
static std::string str; static std::string str;
%} %}

Loading…
Cancel
Save