[Compbench-devel] CompBenchmarks++/libcompbenchmarks/Compiler Compiler-Option-Logic.cpp, NONE, 1.1
Brought to you by:
xfred
From: Frederic T. <xf...@us...> - 2007-04-11 20:31:20
|
Update of /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/Compiler In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv30750 Added Files: Compiler-Option-Logic.cpp Compiler-Option-Logic.h Compiler-Version.cpp Compiler-Version.h Log Message: First import. --- NEW FILE: Compiler-Version.cpp --- /* ---------------------------------------------------------------------------- $Id: Compiler-Version.cpp,v 1.1 2007/04/11 20:31:13 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #include <Compiler/Compiler-Version.h> #include <System/System.h> using namespace CBM; CompilerVersion::CompilerVersion(void) { } int CompilerVersion::AsInteger(std::string _version) { int i = 0; int mul = 1; std::string cur; int tmp; int internal = 0; int digits = 0; if (_version.find(".", 0)>0) { while ( (cur=cbmSystem->Split(_version, ".", i))!="") { tmp=atoi(cur.c_str()); internal+=tmp; internal*=100; mul*=100; i++; digits++; } } internal/=100; while (digits<4) { digits+=2; mul*=100; internal*=100; } return(internal); } CompilerVersion::~CompilerVersion() { } --- NEW FILE: Compiler-Option-Logic.h --- /* ---------------------------------------------------------------------------- $Id: Compiler-Option-Logic.h,v 1.1 2007/04/11 20:31:13 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #ifndef H_CBMCOMPILER_OPTION_LOGIC #define H_CBMCOMPILER_OPTION_LOGIC 1 #include <Compiler/Compiler-Option-Description.h> namespace CBM { typedef enum CompilerOptionLogicCommandID { Unknown, Exclusive, ImpliedBy, Requires, FlagSet, FlagAssert }; typedef struct CompilerOptionLogicCommand { CompilerOptionLogicCommandID id; std::string argumentOption; std::string extraValue; }; class CompilerOptionLogic { private: protected: CompilerOptionDescriptions *context; CompilerOptionDescription *description; std::vector<CompilerOptionLogicCommand*> commands; public: CompilerOptionLogic(CompilerOptionDescriptions *_context, CompilerOptionDescription *_description, XMLNode *_from); virtual std::string use(void); virtual ~CompilerOptionLogic(); }; } #endif --- NEW FILE: Compiler-Version.h --- /* ---------------------------------------------------------------------------- $Id: Compiler-Version.h,v 1.1 2007/04/11 20:31:13 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #ifndef H_CBMCOMPILER_VERSION #define H_CBMCOMPILER_VERSION 1 #include <string> namespace CBM { class CompilerVersion { private: protected: public: CompilerVersion(); virtual int AsInteger(std::string _version); virtual ~CompilerVersion(); }; } #endif --- NEW FILE: Compiler-Option-Logic.cpp --- /* ---------------------------------------------------------------------------- $Id: Compiler-Option-Logic.cpp,v 1.1 2007/04/11 20:31:13 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #include <Compiler/Compiler-Option-Logic.h> #include <Compiler/Compiler.h> using namespace CBM; CompilerOptionLogic::CompilerOptionLogic(CompilerOptionDescriptions *_context, CompilerOptionDescription *_description, XMLNode *_from) { int i; int n = _from->nodeNumber(); CBM::XMLNode *N; CBM::XMLAttribute *A; CompilerOptionLogicCommand *cmd; context=_context; description=_description; for(i=0; i<n; i++) { N=_from->getNode(i); if (N->Name() == "logic-option-exclusive") { A=N->getAttribute("on"); if (!A) continue; cmd=new CompilerOptionLogicCommand; cmd->id=Exclusive; cmd->argumentOption=A->Value(); cmd->extraValue=_description->Id(); commands.push_back(cmd); continue; } if (N->Name() == "logic-option-implied-by") { A=N->getAttribute("id"); if (!A) continue; cmd=new CompilerOptionLogicCommand; cmd->id=ImpliedBy; cmd->argumentOption=A->Value(); cmd->extraValue=""; commands.push_back(cmd); continue; } if (N->Name() == "logic-option-requires") { A=N->getAttribute("id"); if (!A) continue; cmd=new CompilerOptionLogicCommand; cmd->id=Requires; cmd->argumentOption=A->Value(); cmd->extraValue=""; commands.push_back(cmd); continue; } if (N->Name() == "logic-flag-set") { A=N->getAttribute("id"); if (!A) continue; cmd=new CompilerOptionLogicCommand; cmd->id=FlagSet; cmd->argumentOption=A->Value(); A=N->getAttribute("value"); if (!A) cmd->extraValue="0"; else cmd->extraValue=A->Value(); commands.push_back(cmd); continue; } if (N->Name() == "logic-flag-assert") { A=N->getAttribute("id"); if (!A) continue; cmd=new CompilerOptionLogicCommand; cmd->id=FlagAssert; cmd->argumentOption=A->Value(); A=N->getAttribute("value"); if (!A) cmd->extraValue="0"; else cmd->extraValue=A->Value(); commands.push_back(cmd); continue; } } } std::string CompilerOptionLogic::use(void) { int i; int n = commands.size(); CBM::CompilerOptionLogicCommand *cmd; CBM::Compiler *C = context->Compiler(); CBM::CompilerOptionLogicFlag *flag; CBM::CompilerOptionLogicVar *var; std::string tmp; for(i=0; i<n; i++) { cmd=commands[i]; switch(cmd->id) { case Exclusive: var=C->colVarGet(cmd->argumentOption); if (!var) { C->colVarSet(cmd->argumentOption, cmd->extraValue); } else { if (var->value!=cmd->extraValue) { tmp="Option "; tmp+=context->Description(cmd->extraValue)->Option(), tmp+=" is incompatible with "; tmp+=context->Description(var->value)->Option(); return(tmp); } } break; case ImpliedBy: if (C->colOptionHas(cmd->argumentOption)) { tmp="Option "; tmp+=description->Option(); tmp+=" is implied by "; tmp+=context->Description(cmd->argumentOption)->Option(); return(tmp); } break; case Requires: if (!C->colOptionHas(cmd->argumentOption)) { tmp="Option "; tmp+=description->Option(); tmp+=" requieres "; tmp+=context->Description(cmd->argumentOption)->Option(); return(tmp); } break; case FlagSet: C->colFlagSet(cmd->argumentOption, cmd->extraValue); break; case FlagAssert: flag=C->colFlagGet(cmd->argumentOption); if ((!flag) && (cmd->extraValue=="0")) return("1"); if (((flag) && (flag->value!=cmd->extraValue)) || (!flag)) { tmp="Check failed : "; tmp+=context->Description(cmd->argumentOption)->Option(); tmp+=" must be "; tmp+=cmd->extraValue; if (flag) { tmp+=" (has "; tmp+=flag->value; tmp+=")"; } else { tmp+=" (not defined)"; } return(tmp); } break; default: return("Unknown command in option analyzing"); break; } } return("1"); } CompilerOptionLogic::~CompilerOptionLogic() { } |