/usr/include/trilinos/RTC_LineRTC.hh is in libtrilinos-pamgen-dev 12.4.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | #ifndef _LINERTC_H
#define _LINERTC_H
#include "RTC_BlockRTC.hh"
#include "RTC_ObjectRTC.hh"
#include "RTC_commonRTC.hh"
#include "RTC_ExecutableRTC.hh"
#include "RTC_TokenizerRTC.hh"
#include "RTC_ScalarNumberRTC.hh"
#include "RTC_OperatorRTC.hh"
#include <string>
#include <list>
#include <stack>
#include <set>
namespace PG_RuntimeCompiler {
/**
* A Line object represents a single line of code. This class is reposible
* for parsing single lines of code and turning them into post-fix lists
* of operands and operators. Lines of code can be executed.
*/
class Line: public Executable
{
public:
/**
* Constructor -> The constructor will parse line and turn it into a postfix
* list.
*
* @param tokens - A tokenized line
* @param parent - The block containing this line of code
* @param errs - A string containing errors
* @param needReturn - Whether or not this line needs to return a value to
* the entity that executed it
*/
Line(Tokenizer& tokens, Block* parent, std::string& errs,
bool needReturn);
/**
* Destructor -> The destructor will delete all objects in _postfixLine
* except for Variables. The Blocks are reponsible for deleting
* Variables. It will also delete _tempHolder.
*/
~Line();
/**
* stackop -> This method is used to sort operators into postfix.
*
* @param ops - A stack used to help produce postfix ordering
* @param op - The op we are adding to the stack
*/
void stackOp(std::stack<Operator*>& ops, Operator* op);
/**
* infToPost -> This method is used by the constructor to convert a line
* into a postfix list
*
* @param tokens - A list of all the tokens in the list
* @param err - A string to hold errors
*/
void infToPost(Tokenizer& tokens, std::string& errs);
/**
* compile -> This method does some additional checks to make sure that there
* are no errors in the Line. If any errors are found, they will
* be appended onto errs.
*
* @param err - A string to hold errors
*/
void compile(std::string& errs, Tokenizer& tokens);
/**
* execute -> This method will execute this Line object.
*/
Value* execute();
/**
* performNumericOps -> This method checks the operands at compile time. If
* all the operands involved in an operation are
* constants, it will perform this operation at compile
* time.
*/
void performNumericOps();
/**
* process_function -> Processes a function call that occurs in the user's
* code. It parses the argument list and creates
* executable argument statements for each argument.
*
* @param tokens - A list of tokens in this line
* @param errs - A string for holding errors
*/
void process_function(Tokenizer& tokens, std::string& errs);
/**
* process_newvar -> Handles the creation of a new variable. Determines if
* the variable is a scalar or an array.
*
* @param tokens - A list of tokens in this line
* @param errs - A string for holding errors
*/
void process_newvar(Tokenizer& tokens, std::string& errs);
/**
* process_existing_var -> Handles the case where we come across a variable
* that has been declared ealier. Array variables
* must be indexed.
*
* @param tokens - A list of tokens in this line
* @param itr - An iterator that points to the token currently being
* examined
* @param errs - A string for holding errors
*/
void process_existing_var(Tokenizer& tokens, std::string& errs);
/**
* process_number -> Determines what type of number itr is pointing to and
* creates the corresponding object.
*
* @param itr - An iterator that points to the token currently being
* examined
*/
void process_number(Tokenizer& tokens);
/**
* process_operator -> Handles operators by delegating them to the stackOp
* method.
*
* @param itr - An iterator that points to the token currently being
* examined
* @param ops - A stack used to help produce postfix ordering of operations
*/
void process_operator(Tokenizer& tokens, std::stack<Operator*>& ops);
/**
* add_newvar -> Adds a new variable into our system
*
* @param type - The type of the new variable
* @param newvar - The name of the new variable
* @param sizePtr - A pointer to a size expression (only applies to arrays)
* @param isArray - Tells us if we are dealing with an array or not
*/
void add_newvar(std::string& type, std::string& newvar, Line* sizePtr, bool isArray);
/**
* can_go -> This method is used by RTCBoundFunc objects to see check to see
* if the expressions (line objects) that make up their arguments
* were evaluated at compile time.
*/
bool can_go() const;
std::string func_err(const std::string& currVar) const {
return "Function: " + currVar + " does not exist.\n";
}
std::string arg_err(const std::string& currVar) const {
return "Incorrect number of args given to Function: "+currVar+"\n";
}
std::string var_err() const {
return "Tried to declare a variable with no name. \n";
}
std::string ara_err(const std::string& currVar) const {
return "Incorrect array syntax for array: " + currVar + '\n';
}
std::string dec_err(const std::string& newVar) const {
return "Tried to declare a variable: " +newVar+ " that already exists.\n";
}
std::string und_err(const std::string& currVar) const {
return "Use of undeclared variable: " + currVar + '\n';
}
std::string uninit_err(const std::string& var) const {
return "Tried to use an uninitialized variable: " + var + '\n';
}
std::string opp_err() const {
return "Number of operators does not match number of values. \n";
}
std::string ass_err() const {
return "Only one assignment(=) per line of code is allowed. \n";
}
std::string nonv_err() const {
return "Tried to assign to a non-assignable entity.\n";
}
std::string syntax_err(const std::string& value) const {
return "Unexpected token " + value + '\n';
}
void static test(); //unit test
std::ostream& operator<<(std::ostream& os) const;
private:
void addNewObject(Object* newObj);
void removeObject(Object* obj);
bool static indvTest(const std::string& line, Block* parent,
double expectedResult, bool examineResult);
std::list<Object*> _postfixLine; //!< A post-fix list of operands/operators
std::set<Object*> _objsToDelete; /**!< A list of objects this obj should
* delete. Operators are reused, so
* we don't have to delete those.
* Variables are deleted by the
* block that owns them, so we don't
* have to delete those either.
*/
Block* _parent; //!< The Block of code that this Line belongs to
ScalarNumber<double>* _tempHolder; /**!< Used to allocate memory needed for
* temporaries at compile time. This
* boosts runtime performance.
*/
int _tempSize; //!< The size of the _tempHolder array
bool _needReturnVal; /**!< Tells us if this Line needs to return result of
* its execution. This is necessary because sometimes
* Lines represent condition statements for loops or
* ConditionalBlocks.
*/
int _curr; //The line number of this line
};
}
#endif
|