amath  1.8.5
Simple command line calculator
ErrorNode Class Reference

Represents an error message encapsulated in a syntax tree. More...

#include <nodes.h>

Inheritance diagram for ErrorNode:
Collaboration diagram for ErrorNode:

Public Member Functions

 ErrorNode (const char *input, int pos)
 
 ErrorNode (const char *input, const char *message, const char *parameter, int pos)
 
virtual ~ErrorNode ()
 
NodeType GetNodeType ()
 
SyntaxNodeGetNext ()
 
char * GetTextCode ()
 
char * Execute ()
 
void Attach (SyntaxNode *node)
 
void Detach (SyntaxNode *node)
 
void Replace (SyntaxNode *n, SyntaxNode *x)
 
- Public Member Functions inherited from SyntaxNode
 SyntaxNode ()
 
virtual ~SyntaxNode ()
 
void SetFirstNode ()
 
bool GetFirstNode () const
 
SyntaxNodeGetParent () const
 
void SetParent (SyntaxNode *node)
 
virtual ReductionType GetReductionType ()
 
virtual void ResetIterator ()
 

Static Private Member Functions

static void StrCopyVisible (char *destination, const char *source)
 

Private Attributes

char * message
 
char * input
 
int pos
 

Additional Inherited Members

- Protected Attributes inherited from SyntaxNode
CharBufferoutput
 
SyntaxNodeparent
 
SyntaxNodeiterator
 
bool leftBottom
 

Detailed Description

Represents an error message encapsulated in a syntax tree.

Definition at line 123 of file nodes.h.

Constructor & Destructor Documentation

◆ ErrorNode() [1/2]

ErrorNode::ErrorNode ( const char *  input,
int  pos 
)

Definition at line 147 of file nodes.cpp.

References AllocAndCopy(), input, message, pos, StrCopyVisible(), StrLen(), and SyntaxNode::SyntaxNode().

Referenced by Parser::Parse(), and Parser::TryParseStatement().

147  :
148  SyntaxNode(), pos(pos)
149 {
150  char* temp = HELPSYNTAX;
151  this->input = new char[StrLen(input) + 1];
152  StrCopyVisible(this->input, input);
153  AllocAndCopy(&this->message, temp);
154 }
SyntaxNode()
Definition: nodes.cpp:42
char * input
Definition: nodes.h:141
unsigned int AllocAndCopy(char **destination, const char *source)
Allocate memory and copy a string into the array.
Definition: alloccpy.c:40
#define HELPSYNTAX
Definition: text.h:78
int pos
Definition: nodes.h:142
int StrLen(const char *string)
Get the length of a null terminated string.
Definition: strlen.c:34
static void StrCopyVisible(char *destination, const char *source)
Definition: nodes.cpp:188
char * message
Definition: nodes.h:140
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ErrorNode() [2/2]

ErrorNode::ErrorNode ( const char *  input,
const char *  message,
const char *  parameter,
int  pos 
)

Definition at line 133 of file nodes.cpp.

References AllocAndCopy(), CharBuffer::Append(), CharBuffer::CharBuffer(), CharBuffer::EnsureSize(), CharBuffer::GetString(), input, message, pos, StrCopyVisible(), StrLen(), and SyntaxNode::SyntaxNode().

Referenced by Parser::ParseDigistStatement(), Parser::ParseFileStatement(), Parser::ParseFunctionDef(), Parser::ParseIdent(), and Parser::ParseNumeralStatement().

133  :
134  SyntaxNode(), pos(pos)
135 {
136  this->input = new char[StrLen(input) + 1];
137  StrCopyVisible(this->input, input);
138 
139  CharBuffer* temp = new CharBuffer();
140  temp->EnsureSize(StrLen(message) + StrLen(parameter) + 1);
141  temp->Append(message);
142  temp->Append(parameter);
143  AllocAndCopy(&this->message, temp->GetString());
144  delete temp;
145 }
char * GetString() const
Definition: charbuf.cpp:306
SyntaxNode()
Definition: nodes.cpp:42
char * input
Definition: nodes.h:141
void Append(const char *source)
Definition: charbuf.cpp:262
unsigned int AllocAndCopy(char **destination, const char *source)
Allocate memory and copy a string into the array.
Definition: alloccpy.c:40
int pos
Definition: nodes.h:142
int StrLen(const char *string)
Get the length of a null terminated string.
Definition: strlen.c:34
static void StrCopyVisible(char *destination, const char *source)
Definition: nodes.cpp:188
Encapsulate an character array which can be used as a string.
Definition: charbuf.h:44
void EnsureSize(unsigned int size)
Ensure a memory block of specified size is allocated.
Definition: charbuf.cpp:114
char * message
Definition: nodes.h:140
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~ErrorNode()

ErrorNode::~ErrorNode ( )
virtual

Definition at line 156 of file nodes.cpp.

References input, and message.

157 {
158  delete [] input;
159  delete [] message;
160 }
char * input
Definition: nodes.h:141
char * message
Definition: nodes.h:140

Member Function Documentation

◆ Attach()

void ErrorNode::Attach ( SyntaxNode node)
virtual

Implements SyntaxNode.

Definition at line 203 of file nodes.cpp.

204 {
205 }

◆ Detach()

void ErrorNode::Detach ( SyntaxNode node)
virtual

Implements SyntaxNode.

Definition at line 207 of file nodes.cpp.

208 {
209 }

◆ Execute()

char * ErrorNode::Execute ( )
virtual

Implements SyntaxNode.

Definition at line 173 of file nodes.cpp.

References CharBuffer::Append(), CharBuffer::ClearAndAlloc(), CharBuffer::Empty(), CharBuffer::GetString(), input, message, SyntaxNode::output, pos, and StrLen().

174 {
176  output->Empty();
179  output->Append(input);
181  output->Append(' ', pos);
182  output->Append('^');
184 
185  return output->GetString();
186 }
#define NEWLINE
Definition: amath.h:222
void Empty()
Definition: charbuf.cpp:218
char * GetString() const
Definition: charbuf.cpp:306
char * input
Definition: nodes.h:141
void Append(const char *source)
Definition: charbuf.cpp:262
int pos
Definition: nodes.h:142
int StrLen(const char *string)
Get the length of a null terminated string.
Definition: strlen.c:34
CharBuffer * output
Definition: nodes.h:85
char * message
Definition: nodes.h:140
void ClearAndAlloc(unsigned int size)
Release memory and allocate new size.
Definition: charbuf.cpp:92
Here is the call graph for this function:

◆ GetNext()

SyntaxNode * ErrorNode::GetNext ( )
virtual

Implements SyntaxNode.

Definition at line 198 of file nodes.cpp.

199 {
200  return nullptr;
201 }

◆ GetNodeType()

NodeType ErrorNode::GetNodeType ( )
virtual

Implements SyntaxNode.

Definition at line 162 of file nodes.cpp.

References othernodetype.

163 {
164  return othernodetype;
165 }

◆ GetTextCode()

char * ErrorNode::GetTextCode ( )
virtual

Implements SyntaxNode.

Definition at line 167 of file nodes.cpp.

168 {
169  static char* ret = (char*)"ERRND";
170  return ret;
171 }

◆ Replace()

void ErrorNode::Replace ( SyntaxNode n,
SyntaxNode x 
)
virtual

Implements SyntaxNode.

Definition at line 211 of file nodes.cpp.

212 {
213 }

◆ StrCopyVisible()

void ErrorNode::StrCopyVisible ( char *  destination,
const char *  source 
)
staticprivate

Definition at line 188 of file nodes.cpp.

Referenced by ErrorNode().

189 {
190  while (*source != '\0' && *source >= 32 && *source <= 126)
191  {
192  *destination++ = *source++;
193  }
194 
195  *destination = '\0';
196 }
Here is the caller graph for this function:

Member Data Documentation

◆ input

char* ErrorNode::input
private

Definition at line 141 of file nodes.h.

Referenced by ErrorNode(), Execute(), and ~ErrorNode().

◆ message

char* ErrorNode::message
private

Definition at line 140 of file nodes.h.

Referenced by ErrorNode(), Execute(), and ~ErrorNode().

◆ pos

int ErrorNode::pos
private

Definition at line 142 of file nodes.h.

Referenced by ErrorNode(), and Execute().


The documentation for this class was generated from the following files: