insnameelem.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001, The University of Queensland
00003  * Copyright (C) 2002, Trent Waddington
00004  *
00005  * See the file "LICENSE.TERMS" for information on usage and
00006  * redistribution of this file, and for a DISCLAIMER OF ALL
00007  * WARRANTIES.
00008  *
00009  */
00010 
00011 /*
00012  * insnameelem.cc
00013  *
00014  * an element of an instruction name - contains definition of class InsNameElem
00015  *
00016  * 19 Feb 01 - Simon: created
00017  * 01 May 02 - Mike: Mods for boomerang
00018  */
00019 
00020 #include <assert.h>
00021 #if defined(_MSC_VER) && _MSC_VER <= 1200
00022 #pragma warning(disable:4786)
00023 #endif
00024 
00025 #include <string>
00026 #include <map>
00027 #include "types.h"
00028 #include "insnameelem.h"
00029 #if defined(_MSC_VER) && _MSC_VER <= 1100
00030 #include "exp.h"
00031 #endif
00032 
00033 
00034 InsNameElem::InsNameElem(const char *name)
00035 {
00036     elemname = name;
00037     value = 0;
00038     nextelem = NULL;
00039 }
00040 
00041 InsNameElem::~InsNameElem(void)
00042 {
00043 //    delete nextelem;
00044 }
00045 
00046 int InsNameElem::ntokens(void)
00047 {
00048     return 1;
00049 }
00050 
00051 std::string InsNameElem::getinstruction(void)
00052 {
00053     return (nextelem != NULL)? (elemname + nextelem->getinstruction()): elemname;
00054 }
00055 
00056 std::string InsNameElem::getinspattern(void)
00057 {
00058     return (nextelem != NULL)? (elemname + nextelem->getinspattern()): elemname;
00059 }
00060 
00061 void InsNameElem::getrefmap(std::map<std::string, InsNameElem*> &m)
00062 {
00063     if (nextelem != NULL)
00064         nextelem->getrefmap(m);
00065     else
00066         m.erase(m.begin(), m.end());
00067 }
00068 
00069 int InsNameElem::ninstructions(void)
00070 {
00071     return (nextelem != NULL)? (nextelem->ninstructions() * ntokens()): ntokens();
00072 }
00073 
00074 void InsNameElem::append(InsNameElem* next)
00075 {
00076     if (nextelem == NULL)
00077         nextelem = next;
00078     else
00079         nextelem->append(next);
00080 }
00081 
00082 bool InsNameElem::increment(void)
00083 {
00084     if ((nextelem == NULL) || nextelem->increment())
00085         value++;
00086     if (value >= ntokens()) {
00087         value = 0;
00088         return true;
00089     }
00090     return false;
00091 }
00092 
00093 void InsNameElem::reset(void)
00094 {
00095     value = 0;
00096     if (nextelem != NULL) nextelem->reset();
00097 }
00098 
00099 int InsNameElem::getvalue(void)
00100 {
00101     return value;
00102 }
00103 
00104 InsOptionElem::InsOptionElem(const char *name):
00105     InsNameElem(name)
00106 {
00107 }
00108 
00109 int InsOptionElem::ntokens(void)
00110 {
00111     return 2;
00112 }
00113 
00114 std::string InsOptionElem::getinstruction(void)
00115 {
00116     std::string s = (nextelem != NULL)
00117         ? ((getvalue() == 0)
00118             ? (elemname + nextelem->getinstruction())
00119             : nextelem->getinstruction())
00120         : ((getvalue() == 0)
00121             ? elemname
00122             : "");
00123     return s;
00124 }
00125 
00126 std::string InsOptionElem::getinspattern(void)
00127 {
00128     return (nextelem != NULL)
00129         ? ('\'' + elemname + '\'' + nextelem->getinspattern())
00130         : ('\'' + elemname + '\'');
00131 }
00132 
00133 InsListElem::InsListElem(const char *name, Table* t, const char *idx):
00134     InsNameElem(name)
00135 {
00136     indexname = idx;
00137     thetable = t;
00138 }
00139 
00140 int InsListElem::ntokens(void)
00141 {
00142     return thetable->records.size();
00143 }
00144 
00145 std::string InsListElem::getinstruction(void)
00146 {
00147     return (nextelem != NULL)
00148         ? (thetable->records[getvalue()] + nextelem->getinstruction())
00149         : thetable->records[getvalue()];
00150 }
00151 
00152 std::string InsListElem::getinspattern(void)
00153 {
00154     return (nextelem != NULL)
00155         ? (elemname + '[' + indexname + ']' + nextelem->getinspattern())
00156         : (elemname + '[' + indexname + ']');
00157 }
00158 
00159 void InsListElem::getrefmap(std::map<std::string, InsNameElem*> &m)
00160 {
00161     if (nextelem != NULL)
00162         nextelem->getrefmap(m);
00163     else
00164         m.erase(m.begin(), m.end());
00165     m[indexname] = this;
00166     // of course, we're assuming that we've already checked (try in the parser)
00167     // that indexname hasn't been used more than once on this line ..
00168 }
00169 
00170 std::string InsListElem::getindex(void)
00171 {
00172     return indexname;
00173 }

Generated on Tue Sep 19 21:18:24 2006 for Boomerang by  doxygen 1.4.6