Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

ast_fromastfile.cc File Reference

#include <boost/spirit/core.hpp>
#include <boost/spirit/actor/push_back_actor.hpp>
#include "ast.h"
#include "ifprintf.h"

Go to the source code of this file.

Classes

struct  ASTreeGrammar
struct  ASTreeGrammar::definition< ScannerT >

Defines

#define create_create_node_func(CLASSNAME)
 Glorious macro defining an abstract node subclass which I want a create function bound too.

Typedefs

typedef Node *(* create_node_func )(void)

Functions

void pop_stack_node ()
 Various stack pop functions, wanted a generic location / format for them since some need to deallocate container members.
void pop_stack_wrapped_nodes ()
void pop_stack_list_nodes ()
void pop_stack_attribute_proxy ()
void pop_stack_attribute_value ()
static map< string, create_node_funccreate_create_node_funcs ()
void start_node (char const *start, char const *end)
 Read in a new node -> Create a new node and push it on the node stack.
void end_node (char const *start, char const *end)
 Finished with a node -> pop it off the stack.
void start_attribute (char const *start, char const *end)
 Push a new attribute proxy on the stack.
void end_attribute (char const *start, char const *end)
 Should have assigned to the proxy, pop it off.
void do_value_string (char const *start, char const *end)
void do_value_id (char const *start, char const *end)
void do_const_type (char const *start, char const *end)
void do_const_value (char const *start, char const *end)
void do_value_const (char const *start, char const *end)
void start_list (char const *start, char const *end)
void do_list_node (char const *start, char const *end)
void end_list (char const *start, char const *end)
void do_wrapped_node (const char *start, const char *end)
NodeAST::fromASTFile (FILE *f)
 Parse a .ast file and construct / return an AST from it.

Variables

vector< Node * > stack_node
 stack of nodes being read into
vector< Node * > stack_wrapped_node
 once we are done reading into a node it goes in this stack, from which it is pointed at from some parent node
vector< List * > stack_list_nodes
 Stack of list nodes we are reading into.
string constant_type
string constant_value
 Store the type / value of constants.
vector< AttributeProxy * > stack_attribute_proxy
 stack of proxy variables waiting to be assigned too
vector< Node * > stack_attribute_value
 stack of proxy values waiting to be assigned to variables
static map< string, create_node_funccreate_node_funcs = create_create_node_funcs()
 function pointer map used to quickly instantiate the proper class


Define Documentation

#define create_create_node_func CLASSNAME   ) 
 

Value:

struct Creator_##CLASSNAME {\
        static Node* create() { return new CLASSNAME(); }\
    };\
    create_node_funcs[#CLASSNAME] = Creator_##CLASSNAME::create;
Glorious macro defining an abstract node subclass which I want a create function bound too.

Definition at line 38 of file ast_fromastfile.cc.

Referenced by create_create_node_funcs().


Typedef Documentation

typedef Node*(* create_node_func)(void)
 

Definition at line 44 of file ast_fromastfile.cc.


Function Documentation

static map<string, create_node_func> create_create_node_funcs  )  [static]
 

< static function to generate the function pointer map for each class

Definition at line 45 of file ast_fromastfile.cc.

References create_create_node_func, and create_node_funcs.

00045                                                                {                                               
00046     printf("create_create_node_funcs\n");
00047     map<string, create_node_func> create_node_funcs;
00048     create_create_node_func(Program);
00049     create_create_node_func(If);
00050     create_create_node_func(Op_Binary);
00051     create_create_node_func(Identifier);
00052     create_create_node_func(Constant);
00053     create_create_node_func(FunctionCall);
00054     return create_node_funcs;
00055 }

void do_const_type char const *  start,
char const *  end
 

Definition at line 103 of file ast_fromastfile.cc.

References constant_value.

Referenced by ASTreeGrammar::definition< ScannerT >::definition().

00103                                                       {
00104     string str(start, end);
00105     constant_value = str;
00106 }

void do_const_value char const *  start,
char const *  end
 

Definition at line 107 of file ast_fromastfile.cc.

References constant_value.

Referenced by ASTreeGrammar::definition< ScannerT >::definition().

00107                                                        {
00108     string str(start, end);
00109     constant_value = str;
00110 }

void do_list_node char const *  start,
char const *  end
 

Definition at line 122 of file ast_fromastfile.cc.

References pop_stack_attribute_value(), stack_attribute_value, and stack_list_nodes.

Referenced by ASTreeGrammar::definition< ScannerT >::definition().

00122                                                      {
00123     printf("list.push_back(%s)\n", stack_attribute_value.back()->get_name());
00124     stack_list_nodes.back()->addChild(stack_attribute_value.back());
00125     pop_stack_attribute_value();
00126 }

void do_value_const char const *  start,
char const *  end
 

Definition at line 111 of file ast_fromastfile.cc.

References constant_type, constant_value, stack_attribute_value, AST::Constant::type, and AST::Constant::value.

Referenced by ASTreeGrammar::definition< ScannerT >::definition().

00111                                                        {
00112     string str(start, end);
00113     Constant* constant        = new Constant();
00114     constant->type            = constant_type;
00115     constant->value           = constant_value;
00116     stack_attribute_value.push_back(constant);
00117 }

void do_value_id char const *  start,
char const *  end
 

Definition at line 97 of file ast_fromastfile.cc.

References AST::Identifier::handle, and stack_attribute_value.

Referenced by ASTreeGrammar::definition< ScannerT >::definition().

00097                                                     {
00098     string str(start, end);
00099     Identifier* identifier    = new Identifier();
00100     identifier->handle        = str;
00101     stack_attribute_value.push_back(identifier);
00102 }

void do_value_string char const *  start,
char const *  end
 

Definition at line 92 of file ast_fromastfile.cc.

References stack_attribute_value.

Referenced by ASTreeGrammar::definition< ScannerT >::definition().

00092                                                         {
00093     string str(start, end);
00094     Leaf* leaf = new Leaf(str);
00095     stack_attribute_value.push_back(leaf);
00096 }

void do_wrapped_node const char *  start,
const char *  end
 

Definition at line 132 of file ast_fromastfile.cc.

References pop_stack_wrapped_nodes(), stack_attribute_value, and stack_wrapped_node.

Referenced by ASTreeGrammar::definition< ScannerT >::definition().

00132                                                         {
00133     //*(stack_attribute.back()) = stack_wrapped_node.back();
00134     stack_attribute_value.push_back(stack_wrapped_node.back());
00135     pop_stack_wrapped_nodes();
00136 }

void end_attribute char const *  start,
char const *  end
 

Should have assigned to the proxy, pop it off.

Definition at line 85 of file ast_fromastfile.cc.

References pop_stack_attribute_proxy(), pop_stack_attribute_value(), stack_attribute_proxy, and stack_attribute_value.

Referenced by ASTreeGrammar::definition< ScannerT >::definition().

00085                                                       {
00086     string str(start, end);
00087     *(stack_attribute_proxy.back()) = stack_attribute_value.back();
00088     pop_stack_attribute_proxy();
00089     pop_stack_attribute_value();
00090 }

void end_list char const *  start,
char const *  end
 

Definition at line 127 of file ast_fromastfile.cc.

References pop_stack_list_nodes(), stack_attribute_value, and stack_list_nodes.

Referenced by ASTreeGrammar::definition< ScannerT >::definition().

00127                                                  {
00128     printf("end_list\n");
00129     stack_attribute_value.push_back(stack_list_nodes.back());
00130     pop_stack_list_nodes();
00131 }

void end_node char const *  start,
char const *  end
 

Finished with a node -> pop it off the stack.

Definition at line 69 of file ast_fromastfile.cc.

References pop_stack_node(), stack_node, and stack_wrapped_node.

Referenced by ASTreeGrammar::definition< ScannerT >::definition().

00069                                                  {
00070     string str(start, end);
00071     printf("end_node:%s\n", str.c_str());
00072     Node* n = stack_node.back();
00073     stack_wrapped_node.push_back(n);
00074     pop_stack_node();
00075 }

void pop_stack_attribute_proxy  ) 
 

Definition at line 30 of file ast_fromastfile.cc.

References stack_attribute_proxy.

Referenced by end_attribute().

00030                                 {
00031     delete stack_attribute_proxy.back();
00032     stack_attribute_proxy.pop_back();
00033 }

void pop_stack_attribute_value  ) 
 

Definition at line 34 of file ast_fromastfile.cc.

References stack_attribute_value.

Referenced by do_list_node(), and end_attribute().

00034                                 {
00035     stack_attribute_value.pop_back();
00036 }

void pop_stack_list_nodes  ) 
 

Definition at line 27 of file ast_fromastfile.cc.

References stack_list_nodes.

Referenced by end_list().

00027                            {
00028     stack_list_nodes.pop_back();
00029 }

void pop_stack_node  ) 
 

Various stack pop functions, wanted a generic location / format for them since some need to deallocate container members.

Definition at line 21 of file ast_fromastfile.cc.

References stack_node.

Referenced by end_node().

00021                      {
00022     stack_node.pop_back();
00023 }

void pop_stack_wrapped_nodes  ) 
 

Definition at line 24 of file ast_fromastfile.cc.

References stack_wrapped_node.

Referenced by do_wrapped_node().

00024                               {
00025     stack_wrapped_node.pop_back();
00026 }

void start_attribute char const *  start,
char const *  end
 

Push a new attribute proxy on the stack.

Definition at line 78 of file ast_fromastfile.cc.

References stack_attribute_proxy, and stack_node.

Referenced by ASTreeGrammar::definition< ScannerT >::definition().

00078                                                         {
00079     string str(start, end);
00080     //printf("new attrib %s.%s\n", stack_node.back()->get_name(), str.c_str());
00081     AttributeProxy* attrib = new AttributeProxy(stack_node.back(), str);
00082     stack_attribute_proxy.push_back(attrib);
00083 }

void start_list char const *  start,
char const *  end
 

Definition at line 118 of file ast_fromastfile.cc.

References stack_list_nodes.

Referenced by ASTreeGrammar::definition< ScannerT >::definition().

00118                                                    {
00119     printf("start_list\n");
00120     stack_list_nodes.push_back(new List());
00121 }

void start_node char const *  start,
char const *  end
 

Read in a new node -> Create a new node and push it on the node stack.

Definition at line 59 of file ast_fromastfile.cc.

References create_node_funcs, and stack_node.

Referenced by ASTreeGrammar::definition< ScannerT >::definition().

00059                                                    {
00060     string str(start, end);
00061     printf("start_node:%s\n", str.c_str());
00062     create_node_func func = create_node_funcs[str];
00063     assert(func && "undefined function for some type");
00064     Node* n = func();
00065     assert(n && "func failed");
00066     stack_node.push_back(n);
00067 }


Variable Documentation

string constant_type
 

Definition at line 16 of file ast_fromastfile.cc.

Referenced by do_value_const().

string constant_value
 

Store the type / value of constants.

Definition at line 16 of file ast_fromastfile.cc.

Referenced by do_const_type(), do_const_value(), and do_value_const().

map<string, create_node_func> create_node_funcs = create_create_node_funcs() [static]
 

function pointer map used to quickly instantiate the proper class

Definition at line 56 of file ast_fromastfile.cc.

Referenced by create_create_node_funcs(), and start_node().

vector<AttributeProxy*> stack_attribute_proxy
 

stack of proxy variables waiting to be assigned too

Definition at line 17 of file ast_fromastfile.cc.

Referenced by end_attribute(), pop_stack_attribute_proxy(), and start_attribute().

vector<Node*> stack_attribute_value
 

stack of proxy values waiting to be assigned to variables

Definition at line 18 of file ast_fromastfile.cc.

Referenced by do_list_node(), do_value_const(), do_value_id(), do_value_string(), do_wrapped_node(), end_attribute(), end_list(), and pop_stack_attribute_value().

vector<List*> stack_list_nodes
 

Stack of list nodes we are reading into.

Definition at line 15 of file ast_fromastfile.cc.

Referenced by do_list_node(), end_list(), pop_stack_list_nodes(), and start_list().

vector<Node*> stack_node
 

stack of nodes being read into

Stacks we use to track data as we parse the tree

Definition at line 13 of file ast_fromastfile.cc.

Referenced by end_node(), pop_stack_node(), start_attribute(), and start_node().

vector<Node*> stack_wrapped_node
 

once we are done reading into a node it goes in this stack, from which it is pointed at from some parent node

Definition at line 14 of file ast_fromastfile.cc.

Referenced by do_wrapped_node(), end_node(), AST::fromASTFile(), and pop_stack_wrapped_nodes().


Generated on Thu Oct 20 12:00:04 2005 for ASTree by  doxygen 1.4.2-20050421