Metric.h

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002     This file is part of PHP-AST Project by Romain Gaucher (http://rgaucher.info).
00003 
00004     PHP-AST is free software: you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation, either version 3 of the License, or
00007     (at your option) any later version.
00008 
00009     PHP-AST/ORACLE is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with PHP-AST.  If not, see <http://www.gnu.org/licenses/>.
00016 ------------------------------------------------------------------------------*/
00017 
00018 #ifndef __METRIC_H
00019 #define __METRIC_H
00020 
00021 #include <map>
00022 #include <string>
00023 #include <sstream>
00024 #include <iostream>
00025 #include "Utils.h"
00026 
00027 
00028 class NumericResult 
00029 {
00030     std::string container;
00031   public:
00032     NumericResult(){}
00033     NumericResult(int c) { container = to_string<int>(c); }
00034     NumericResult(float c) { container = to_string<float>(c); }
00035     NumericResult(long c) { container = to_string<long>(c); }
00036     NumericResult(unsigned c) { container = to_string<unsigned>(c); }
00037     NumericResult(double c) { container = to_string<double>(c); }
00038     NumericResult(const std::string& c) {container=c;}
00039     
00040     NumericResult(const NumericResult& n) : container(n.container){}
00041         
00042     NumericResult& operator=(const NumericResult& n) { container = n.container; return *this; }
00043     NumericResult& operator=(const int n) { container = to_string<int>(n); return *this; }
00044     NumericResult& operator=(const unsigned n) { container = to_string<unsigned>(n); return *this; }
00045     NumericResult& operator=(const long n) { container = to_string<long>(n); return *this; }
00046     NumericResult& operator=(const float n) { container = to_string<float>(n); return *this; }
00047     NumericResult& operator=(const double n) { container = to_string<double>(n); return *this; }    
00048     
00049     inline int toInt() const {
00050         int ret = 0;
00051         from_string<int>(ret,container);
00052         return ret;
00053     }
00054     inline float toFloat() const {
00055         float ret = 0;
00056         from_string<float>(ret,container);
00057         return ret;
00058     }
00059     inline long toLong() const {
00060         long ret = 0;
00061         from_string<long>(ret,container);
00062         return ret;
00063     }
00064     inline unsigned toUnsigned() const {
00065         unsigned ret = 0;
00066         from_string<unsigned>(ret,container);
00067         return ret;
00068     }
00069     inline double toDouble() const {
00070         double ret = 0;
00071         from_string<double>(ret,container);
00072         return ret;
00073     }
00074     inline std::string toString() const {
00075         return container;
00076     }
00077 };
00078 
00079 
00080 
00081 struct MetricResult
00082 {
00083     NumericResult main;
00084     std::map<std::string, NumericResult> storage;
00085 };
00086 
00087 
00088 std::ostream& operator<<(std::ostream& stream, const NumericResult&);
00089 std::ostream& operator<<(std::ostream& stream, const MetricResult&);
00090 
00091 
00092 
00093 /**
00094     Metrics abstract class
00095 */
00096 class Metric {
00097   public:
00098     Metric() {}
00099     virtual ~Metric() {}
00100   public:
00101     virtual MetricResult operator()(const tree<AstNode>&, const MapClasses* classes = 0, const MapVariables* vars = 0, 
00102                                     const MapFunctions *func = 0, const MapAssignments *assigns = 0, const MapVarEquivalent *equiv = 0) = 0;
00103 };
00104 
00105 class NumberFunctions : public Metric
00106 {
00107   public:
00108     virtual ~NumberFunctions() {}
00109     virtual MetricResult operator()(const tree<AstNode>&, const MapClasses* classes = 0, const MapVariables* vars = 0, 
00110                                     const MapFunctions *func = 0, const MapAssignments *assigns = 0, const MapVarEquivalent *equiv = 0);
00111 };
00112 
00113 
00114 class NumberSinks : public Metric
00115 {
00116   public:
00117     std::list<std::string> sensitive;
00118     const Ast* ast;
00119   public:
00120     NumberSinks(){}
00121     NumberSinks(const std::list<std::string>& sinks, const Ast* _ast = 0) {
00122         sensitive = sinks;
00123         ast = _ast;
00124     }
00125     virtual ~NumberSinks() {}
00126     virtual MetricResult operator()(const tree<AstNode>&, const MapClasses* classes = 0, const MapVariables* vars = 0,
00127                                     const MapFunctions *func = 0, const MapAssignments *assigns = 0, const MapVarEquivalent *equiv = 0);
00128 };
00129 
00130 
00131 class NumberResources : public Metric
00132 {
00133   public:
00134     std::list<std::string> taintedinput;
00135     const Ast* ast;
00136   public:
00137     NumberResources(){}
00138     NumberResources(const std::list<std::string>& sinks, const Ast* _ast = 0) {
00139         taintedinput = sinks;
00140         ast = _ast;
00141     }
00142     virtual ~NumberResources() {}
00143     virtual MetricResult operator()(const tree<AstNode>&, const MapClasses* classes = 0, const MapVariables* vars = 0,
00144                                     const MapFunctions *func = 0, const MapAssignments *assigns = 0, const MapVarEquivalent *equiv = 0);
00145 };
00146 
00147 
00148 
00149 class NumberVariables : public Metric
00150 {
00151   public:
00152     virtual ~NumberVariables() {}
00153     virtual MetricResult operator()(const tree<AstNode>&, const MapClasses* classes = 0, const MapVariables* vars = 0, 
00154                                     const MapFunctions *func = 0, const MapAssignments *assigns = 0, const MapVarEquivalent *equiv = 0);
00155 };
00156 
00157 
00158 
00159 class NumberClasses : public Metric
00160 {
00161   public:
00162     virtual ~NumberClasses() {}
00163     virtual MetricResult operator()(const tree<AstNode>&, const MapClasses* classes = 0, const MapVariables* vars = 0, 
00164                                     const MapFunctions *func = 0, const MapAssignments *assigns = 0, const MapVarEquivalent *equiv = 0);
00165 };
00166 
00167 
00168 class NumberInput : public Metric
00169 {
00170   public:
00171     Ast defAST;
00172   public:
00173     NumberInput(){}
00174     NumberInput(const std::string& defASTStr) {
00175         defAST = Ast(defASTStr);
00176     }
00177     virtual ~NumberInput() {}
00178     virtual MetricResult operator()(const tree<AstNode>&, const MapClasses* classes = 0, const MapVariables* vars = 0, 
00179                                     const MapFunctions *func = 0, const MapAssignments *assigns = 0, const MapVarEquivalent *equiv = 0);
00180 };
00181 
00182 class NumberDiffuseInputs : public Metric
00183 {
00184   public:
00185     Ast defAST;
00186   public:
00187     NumberDiffuseInputs(){}
00188     NumberDiffuseInputs(const std::string& defASTStr) {
00189         defAST = Ast(defASTStr);
00190     }
00191     virtual ~NumberDiffuseInputs() {}
00192     virtual MetricResult operator()(const tree<AstNode>&, const MapClasses* classes = 0, const MapVariables* vars = 0, 
00193                                     const MapFunctions *func = 0, const MapAssignments *assigns = 0, const MapVarEquivalent *equiv = 0);
00194 };
00195 
00196 class NumberSunkDiffuseInputs : public Metric
00197 {
00198   public:
00199     Ast defAST;
00200     const Ast *ast;
00201     std::list<std::string> sensitive;
00202   public:
00203     NumberSunkDiffuseInputs(){}
00204     NumberSunkDiffuseInputs(const Ast* astPtr, const std::string& defASTStr, const std::list<std::string>& sinks) {
00205         defAST = Ast(defASTStr);
00206         sensitive = sinks;
00207         ast = astPtr;
00208     }
00209     virtual ~NumberSunkDiffuseInputs() {}
00210     virtual MetricResult operator()(const tree<AstNode>&, const MapClasses* classes = 0, const MapVariables* vars = 0, 
00211                                     const MapFunctions *func = 0, const MapAssignments *assigns = 0, const MapVarEquivalent *equiv = 0);
00212 };
00213 
00214 
00215 
00216 
00217 
00218 
00219 #endif

Generated on Wed Feb 27 20:31:06 2008 for php.ast.svn.src. by  doxygen 1.5.3