Fixing a few cppcheck warnings
[supertux.git] / tools / miniswig / tree.hpp
index 4dfcf1b..47741de 100644 (file)
@@ -12,8 +12,9 @@ class Namespace;
 
 class AtomicType {
 public:
-    AtomicType()
-        : parent(0)
+    AtomicType() :
+      name(),
+      parent(0)
     { }
     virtual ~AtomicType()
     { }
@@ -25,6 +26,10 @@ public:
 
     std::string name;
     Namespace* parent;
+
+private:
+    AtomicType(const AtomicType&);
+    AtomicType& operator=(const AtomicType&);
 };
 
 class BasicType : public AtomicType {
@@ -40,14 +45,14 @@ public:
 
 private:
     BasicType(const std::string& name)
-    { 
+    {
         this->name = name;
-    }                                     
+    }
 };
 
 class Type {
 public:
-    Type() 
+    Type()
         : atomic_type(0), _unsigned(false), _const(false), _static(false),
         pointer(0), ref(0)
     { }
@@ -55,7 +60,7 @@ public:
     void write_c_type(std::ostream& out)
     {
         if(_static)
-            out << "static ";        
+            out << "static ";
         if(_const)
             out << "const ";
         atomic_type->write_c(out);
@@ -84,6 +89,28 @@ public:
     int ref;
 };
 
+class SQIntegerType : public AtomicType {
+public:
+    SQIntegerType()
+    {
+        this->name = "SQInteger";
+        assert(_instance == 0);
+        _instance = this;
+    }
+    virtual ~SQIntegerType()
+    {
+        assert(_instance == this);
+        _instance = NULL;
+    }
+
+    static SQIntegerType* instance()
+    {
+        return _instance;
+    }
+private:
+    static SQIntegerType* _instance;
+};
+
 class HSQUIRRELVMType : public AtomicType {
 public:
     HSQUIRRELVMType()
@@ -95,7 +122,7 @@ public:
     virtual ~HSQUIRRELVMType()
     {
         assert(_instance == this);
-        _instance = 0;
+        _instance = NULL;
     }
 
     static HSQUIRRELVMType* instance()
@@ -131,36 +158,54 @@ public:
     }
 
 private:
-    static StringType* _instance;   
+    static StringType* _instance;
 };
 
-class Parameter {
+class Parameter
+{
 public:
+    Parameter() :
+        name(),
+        type()
+    { }
+
     std::string name;
     Type type;
 };
 
 class ClassMember {
 public:
+    ClassMember() :
+        visibility()
+    { }
     virtual ~ClassMember()
     { }
 
-    enum Visbility {
+    enum Visibility {
         PUBLIC,
         PROTECTED,
         PRIVATE
     };
-    Visbility visibility;
+    Visibility visibility;
 };
 
 class Function : public ClassMember {
 public:
-    Function() {
-      type = FUNCTION;
-      suspend = false;
-      custom = false;
+    Function() :
+        type(),
+        suspend(),
+        custom(),
+        parameter_spec(),
+        docu_comment(),
+        name(),
+        return_type(),
+        parameters()
+    {
+        type = FUNCTION;
+        suspend = false;
+        custom = false;
     }
-  
+
     enum FuncType {
         FUNCTION,
         CONSTRUCTOR,
@@ -171,6 +216,7 @@ public:
     bool suspend;
     /// a custom wrapper (just pass along HSQUIRRELVM)
     bool custom;
+    std::string parameter_spec;
     std::string docu_comment;
     std::string name;
     Type return_type;
@@ -179,31 +225,45 @@ public:
 
 class Field : public ClassMember {
 public:
-    Field()
+    Field() :
+        type(),
+        docu_comment(),
+        name(),
+        has_const_value(),
+        const_float_value(),
+        const_int_value(),
+        const_string_value()
     {
         has_const_value = false;
     }
-    
+
     Type* type;
     std::string docu_comment;
     std::string name;
     bool has_const_value;
 
-    union {
-        float const_float_value;
-        int const_int_value;
-    };
+    float const_float_value;
+    int const_int_value;
     std::string const_string_value;
+
+private:
+    Field(const Field&);
+    Field& operator=(const Field&);
 };
 
 class Class : public AtomicType {
 public:
+    Class() :
+        members(),
+        super_classes(),
+        sub_classes(),
+        docu_comment()
+    { }
     ~Class() {
-        for(std::vector<ClassMember*>::iterator i = members.begin();
-                i != members.end(); ++i)
+        for(std::vector<ClassMember*>::iterator i = members.begin(); i != members.end(); ++i)
             delete *i;
     }
-    
+
     std::vector<ClassMember*> members;
     std::vector<Class*> super_classes;
     std::vector<Class*> sub_classes;
@@ -212,7 +272,14 @@ public:
 
 class Namespace {
 public:
-    Namespace() {
+    Namespace() :
+        functions(),
+        fields(),
+        types(),
+        namespaces(),
+        parent(),
+        name()
+    {
         parent = 0;
     }
     virtual ~Namespace() {
@@ -272,7 +339,7 @@ public:
 
         return ret;
     }
-                                                                             
+
     std::vector<Function*> functions;
     std::vector<Field*> fields;
     std::vector<AtomicType*> types;
@@ -280,6 +347,10 @@ public:
 
     Namespace* parent;
     std::string name;
+
+private:
+    Namespace(const Namespace&);
+    Namespace& operator=(const Namespace&);
 };
 
 class CompilationUnit : public Namespace {
@@ -287,4 +358,3 @@ public:
 };
 
 #endif
-