amath  1.8.5
Simple command line calculator
StatementBlockNode Class Reference

A sequence of statements in a syntax tree. More...

#include <nodes.h>

Inheritance diagram for StatementBlockNode:
Collaboration diagram for StatementBlockNode:

Public Member Functions

 StatementBlockNode ()
 
 ~StatementBlockNode ()
 
NodeType GetNodeType ()
 
SyntaxNodeGetNext ()
 
void Add (SyntaxNode *node)
 
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 ()
 

Private Attributes

StatementBlockElementfirst
 

Additional Inherited Members

- Protected Attributes inherited from SyntaxNode
CharBufferoutput
 
SyntaxNodeparent
 
SyntaxNodeiterator
 
bool leftBottom
 

Detailed Description

A sequence of statements in a syntax tree.

Definition at line 151 of file nodes.h.

Constructor & Destructor Documentation

◆ StatementBlockNode()

StatementBlockNode::StatementBlockNode ( )

Definition at line 219 of file nodes.cpp.

References first, SyntaxNode::iterator, and SyntaxNode::SyntaxNode().

Referenced by Parser::Parse().

219  :
220  SyntaxNode()
221 {
222  first = nullptr;
223  iterator = nullptr;
224 }
StatementBlockElement * first
Definition: nodes.h:167
SyntaxNode()
Definition: nodes.cpp:42
SyntaxNode * iterator
Definition: nodes.h:87
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~StatementBlockNode()

StatementBlockNode::~StatementBlockNode ( )

Definition at line 226 of file nodes.cpp.

References first, StatementBlockElement::next, and StatementBlockElement::statement.

227 {
229 
230  while (e != nullptr)
231  {
232  StatementBlockElement* next = e->next;
233  delete e->statement;
234  delete e;
235  e = next;
236  }
237 }
StatementBlockElement * first
Definition: nodes.h:167
Used to create a linked list of statements.
Definition: nodes.h:174
SyntaxNode * statement
Definition: nodes.h:176
StatementBlockElement * next
Definition: nodes.h:177

Member Function Documentation

◆ Add()

void StatementBlockNode::Add ( SyntaxNode node)

Definition at line 244 of file nodes.cpp.

References first, StatementBlockElement::next, and StatementBlockElement::statement.

Referenced by Parser::Parse().

245 {
246  if (first == nullptr)
247  {
249  first->statement = node;
250  first->next = nullptr;
251  return;
252  }
253 
255  StatementBlockElement* current = first->next;
256 
257  while (current != nullptr)
258  {
259  current = current->next;
260  last = last->next;
261  }
262 
263  current = new StatementBlockElement();
264  current->statement = node;
265  current->next = nullptr;
266  last->next = current;
267 }
StatementBlockElement * first
Definition: nodes.h:167
Used to create a linked list of statements.
Definition: nodes.h:174
SyntaxNode * statement
Definition: nodes.h:176
StatementBlockElement * next
Definition: nodes.h:177
Here is the caller graph for this function:

◆ Attach()

void StatementBlockNode::Attach ( SyntaxNode node)
virtual

Implements SyntaxNode.

Definition at line 298 of file nodes.cpp.

299 {
300 }

◆ Detach()

void StatementBlockNode::Detach ( SyntaxNode node)
virtual

Implements SyntaxNode.

Definition at line 302 of file nodes.cpp.

303 {
304  // TODO: Implement Detach in StatementBlockNode
305 }

◆ Execute()

char * StatementBlockNode::Execute ( )
virtual

Implements SyntaxNode.

Definition at line 275 of file nodes.cpp.

References CharBuffer::Append(), CharBuffer::ClearBuffer(), CharBuffer::Empty(), CharBuffer::EnsureGrowth(), SyntaxNode::Execute(), first, CharBuffer::GetString(), StatementBlockElement::next, SyntaxNode::output, StatementBlockElement::statement, and StrLen().

276 {
277  output->ClearBuffer();
278  output->Empty();
279 
281  while (e != nullptr)
282  {
283  const char* out = e->statement->Execute();
284  output->EnsureGrowth(StrLen(out) + 1);
285  output->Append(out);
286  e = e->next;
287  }
288 
289  return output->GetString();
290 }
StatementBlockElement * first
Definition: nodes.h:167
void Empty()
Definition: charbuf.cpp:218
Used to create a linked list of statements.
Definition: nodes.h:174
char * GetString() const
Definition: charbuf.cpp:306
void ClearBuffer()
Release memory in buffer.
Definition: charbuf.cpp:65
void Append(const char *source)
Definition: charbuf.cpp:262
virtual char * Execute()=0
SyntaxNode * statement
Definition: nodes.h:176
void EnsureGrowth(unsigned int size)
Definition: charbuf.cpp:169
int StrLen(const char *string)
Get the length of a null terminated string.
Definition: strlen.c:34
CharBuffer * output
Definition: nodes.h:85
StatementBlockElement * next
Definition: nodes.h:177
Here is the call graph for this function:

◆ GetNext()

SyntaxNode * StatementBlockNode::GetNext ( )
virtual

Implements SyntaxNode.

Definition at line 292 of file nodes.cpp.

293 {
294  // TODO: Implement GetNext in StatementBlockNode
295  return nullptr;
296 }

◆ GetNodeType()

NodeType StatementBlockNode::GetNodeType ( )
virtual

Implements SyntaxNode.

Definition at line 239 of file nodes.cpp.

References statement.

240 {
241  return statement;
242 }

◆ GetTextCode()

char * StatementBlockNode::GetTextCode ( )
virtual

Implements SyntaxNode.

Definition at line 269 of file nodes.cpp.

270 {
271  static char* ret = (char*)"SBLCK";
272  return ret;
273 }

◆ Replace()

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

Implements SyntaxNode.

Definition at line 307 of file nodes.cpp.

308 {
309  // TODO: Implement Replace in StatementBlockNode
310 }

Member Data Documentation

◆ first

StatementBlockElement* StatementBlockNode::first
private

Definition at line 167 of file nodes.h.

Referenced by Add(), Execute(), StatementBlockNode(), and ~StatementBlockNode().


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