All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

Commit 6505b646 authored by Sarah Spall's avatar Sarah Spall Committed by Vikram Narayanan

moved definitions of ast constructors into h file, so cpp file is empty for...

moved definitions of ast constructors into h file, so cpp file is empty for now. switching to a true visitor pattern for code generator. visitor.h declares visitor interface, header_generator, declares header generator visitor, and header_generator.cpp, is not yet filled out
parent 7cac6387
#include "header_generator.h"
void HeaderGeneratorVisitor::visit(Scope *scope)
{
// maybe i should change name again
// print out verbatim section
// call accept on all rpc definitions
// what about messages again?
// what to do about symbol table
}
void HeaderGeneratorVisitor::visit(Message *message)
{
// what is a message used for agian?
}
void HeaderGeneratorVisitor::visit(MessageField *message_field)
{
// what is a message used for again?
}
void HeaderGeneratorVisitor::visit(Projection *projection)
{
// don't need to do anything? only relevant
// in c file generation
}
void HeaderGeneratorVisitor::visit(ProjectionField *proj_field)
{
// do we need to do anything for header generation?
// i believe this is only needed when generating
// c files
}
void HeaderGeneratorVisitor::visit(Rpc *rpc)
{
// need to call accept on the return type
// need to print the name and paren
// need to call accept on each of the parameters
}
void HeaderGeneratorVisitor::visit(Parameter *param)
{
// need to call accept on the type and print the
// name
}
void HeaderGeneratorVisitor::visit(Typedef *typedef)
{
// do we need one for teypdefs? if we are replacing
// the use of the typedef in the file, with the real type
// we don't need to print a c typedef at the top, especially if there is one in another file
// may not need a visit for typedef? talk to anton
}
void HeaderGeneratorVisitor::visit(ProjectionType *proj_type)
{
// just need to print the underlying type
}
void HeaderGeneratorVisitor::visit(PrimitiveType *prim_type)
{
// just need to print the entire type....
}
void HeaderGeneratorVisitor::visit(UnresolvedType *unresolved_type)
{
}
#ifndef LCD_HEADER_GENERATOR_H_
#define LCD_HEADER_GENERATOR_H_
#include "lcd_ast.h"
#include "visitor.h"
#include <stdio.h>
class HeaderGeneratorVisitor : public ASTVisitor
{
FILE *out_file_;
public:
HeaderGeneratorVisitor(FILE *out_file) {
this->out_file_ = out_file; }
virtual void visit(Scope *scope);
virtual void visit(Message *message);
virtual void visit(MessageField *message_field);
virtual void visit(Projection *projection);
virtual void visit(ProjectionField *proj_field);
virtual void visit(Rpc *rpc);
virtual void visit(Parameter *parameter);
virtual void visit(Typedef *type_def);
virtual void visit(ProjectionType *proj_type);
virtual void visit(PrimitiveType *prim_type);
virtual void visit(UnresolvedType *unresolved_type);
// virtual void visit(Type *type);
// virtual void visit(Definition* def);
};
#endif // LCD_HEADER_GENERATOR_H_
#include "lcd_ast.h"
PrimitiveType::PrimitiveType(TypeModifier type_mod, PrimType primitive)
{
this->type_modifier_ = type_mod;
this->primitive_ = primitive;
}
ProjectionType::ProjectionType(char* type_name, bool pointer)
{
this->type_name_ = type_name;
this->pointer_ = pointer;
}
Scope::Scope(char* verbatim, std::vector<Rpc* >* rpc_definitions, std::vector<Message* >* message_definitions,
std::map<char* , Definition* >* symbol_table)
{
this->verbatim_ = verbatim;
this->rpc_definitions_ = rpc_definitions;
this->message_definitions_ = message_definitions;
this->symbol_table__ = symbol_table;
}
Rpc::Rpc(Type* return_type, char* name, std::vector<Parameter* >* parameters)
{
this->return_type_ = return_type;
this->name_ = name;
this->parameters_ = parameters;
}
Projection::Projection(char* name, char* true_type, std::vector<ProjectionField* >* fields)
{
this->name_ = name;
this->true_type_ = true_type;
this->fields_ = fields;
}
ProjectionField::ProjectionField(bool in, bool out, bool alloc, bool bind, Type* field_type, char* field_name)
{
this->in_ = in;
this->out_ = out;
this->alloc_ = alloc;
this->bind_ = bind;
this->field_type_ = field_type;
this->field_name_ = field_name;
}
Parameter::Parameter(Type* type, char* name)
{
this->type_ = type;
this->name_ = name;
}
MessageField::MessageField(Type* field_type, char* field_name)
{
this->field_type_ = field_type;
this->field_name_ = field_name;
}
Message::Message(char* name, std::vector<MessageField* >* fields)
{
this->name_ = name;
this->fields_ = fields;
}
Typedef::Typedef(char* real_type, Type* marshal_type, char* typedef_name)
{
this->real_type_ = real_type;
this->marshal_type_ = marshal_type;
this->name_ = typedef_name;
}
......@@ -5,6 +5,7 @@
#include <map>
enum DefinitionType {kRpc = 1, kModule, kMessage, kProjection, kTypedef};
enum Types {kProjectionType, kPrimType, kUnresolvedType }
enum PrimType { kChar = 1, kShort, kInt, kLong, kLongLong, kCapability};
enum TypeModifier {kUnsigned = 1, kNone};
......@@ -12,6 +13,7 @@ class Definition
{
public:
virtual DefinitionType get_definition_type(void) = 0;
virtual void accept(ASTVisitor *worker) = 0;
// virtual ~Definition() {};
};
......@@ -20,18 +22,37 @@ class Type
{
public:
virtual ~Type() {}
virtual DerivedType DerivedClassType(void) = 0;
virtual void accept(ASTVisitor *worker) = 0;
char* GetType();
};
class UnresolvedType : public Type
{
char* name_;
public:
UnresolvedType(char* name) { this->name_ = name; }
DerivedType DerivedClassType() { return kUnresolvedType; }
char * name() { return name_; }
void accept(ASTVisitor *worker) { worker->visit(this); }
}
class PrimitiveType : public Type
{
TypeModifier type_modifier_;
PrimType primitive_;
public:
PrimitiveType(TypeModifier type_mod, PrimType primitive);
PrimitiveType(TypeModifier type_mod, PrimType primitive) {
this->type_modifier_ = type_mod;
this->primitive_ = primitive; }
TypeModifier type_modifier() {return type_modifier_; }
PrimType primitive() {return primitive_; }
char * GetFullName();
char * GetType();
DerivedType DerivedClassType() { return kPrimType; }
void accept(ASTVisitor *worker) { worker->visit(this); }
// maybe for consistency this shouldnt have getfullname
};
......@@ -41,9 +62,13 @@ class ProjectionType : public Type // complex type
bool pointer_;
public:
ProjectionType(char * type_name, bool pointer);
char * type_name() {return type_name_; }
ProjectionType(char * type_name, bool pointer) {
this->type_name_ = type_name;
this->pointer_ = pointer; }
char* type_name() {return type_name_; }
bool pointer() { return pointer_; }
DerivedType DerivedClassType() { return kProjectionType; }
void accept(ASTVisitor *worker) { worker->visit(this); }
// get full name function? class isn't aware of parent need to pass env
};
......@@ -54,9 +79,13 @@ class Typedef : public Definition
char* name_;
public:
Typedef(char* real_type, Type* marshal_type, char* typedef_name);
Typedef(char* real_type, Type* marshal_type, char* typedef_name) {
this->real_type_ = real_type;
this->marshal_type_ = marshal_type;
this->name_ = typedef_name; }
char* name() { return name_; }
DefinitionType get_definition_type(){ return kTypedef; }
void accept(ASTVisitor *worker) { worker->visit(this); }
};
class Parameter
......@@ -65,8 +94,11 @@ class Parameter
char* name_;
public:
Parameter(Type* type, char* name);
Parameter(Type* type, char* name) {
this->type_ = type;
this->name_ = name; }
~Parameter();
void accept(ASTVisitor *worker) { worker->visit(this); }
};
class Rpc : public Definition
......@@ -76,9 +108,15 @@ class Rpc : public Definition
std::vector<Parameter* >* parameters_;
public:
Rpc(Type* return_type, char* name, std::vector<Parameter* >* parameters);
Rpc(Type* return_type, char* name, std::vector<Parameter* >* parameters) {
this->return_type_ = return_type;
this->name_ = name;
this->parameters_ = parameters; }
DefinitionType get_definition_type(){ return kRpc; }
char* name() { return name_; }
Type* return_type() { return return_type_; }
std::vector<Parameter*>* parameters() { return parameters_; }
void accept(ASTVisitor *worker) { worker->visit(this); }
};
class ProjectionField
......@@ -97,6 +135,7 @@ class ProjectionField
bool out() { return out_; }
bool alloc() { return alloc_; }
bool bind() { return bind_; }
void accept(ASTVisitor *worker) { worker->visit(this); }
};
class Projection : public Definition
......@@ -106,9 +145,13 @@ class Projection : public Definition
std::vector<ProjectionField* >* fields_;
public:
Projection(char* name, char* true_type, std::vector<ProjectionField* >* fields);
Projection(char* name, char* true_type, std::vector<ProjectionField* >* fields) {
this->name_ = name;
this->true_type_ = true_type;
this->fields_ = fields; }
char* name() const { return name_; }
DefinitionType get_definition_type(){return kProjection;}
void accept(ASTVisitor *worker) { worker->visit(this); }
};
......@@ -118,7 +161,10 @@ class MessageField
char* field_name_;
public:
MessageField(Type* field_type, char* field_name);
MessageField(Type* field_type, char* field_name) {
this->field_type_ = field_type;
this->field_name_ = field_name; }
void accept(ASTVisitor *worker) { worker->visit(this); }
};
class Message : public Definition
......@@ -127,8 +173,11 @@ class Message : public Definition
std::vector<MessageField* >* fields_;
public:
Message(char * name, std::vector<MessageField* >* fields);
Message(char * name, std::vector<MessageField* >* fields) {
this->name_ = name;
this->fields_ = fields; }
DefinitionType get_definition_type() { return kMessage; }
void accept(ASTVisitor *worker) { worker->visit(this); }
};
......@@ -138,12 +187,17 @@ class Scope
char* verbatim_;
std::vector<Rpc *>* rpc_definitions_;
std::vector<Message *>* message_definitions_;
std::map<char *, Definition *>* symbol_table__;
std::map<char *, Definition *>* symbol_table_;
// believe it is only necessary to store projections in "env" since functions can't be referenced in other functions
public:
Scope(char* verbatim, std::vector<Rpc* >* rpc_definitions, std::vector<Message* >* message_definitions,
std::map<char* , Definition* >* symbol_table);
std::map<char* , Definition* >* symbol_table) {
this->verbatim_ = verbatim;
this->rpc_definitions_ = rpc_definitions;
this->message_definitions_ = message_definitions;
this->symbol_table_ = symbol_table; }
void accept(ASTVisitor *worker) { worker->visit(this); }
};
......
#ifndef _VISITOR_
#define _VISITOR_
class ASTVisitor
{
public:
virtual void visit(Scope *scope) = 0;
virtual void visit(Message *message) = 0;
virtual void visit(MessageField *message_field) = 0;
virtual void visit(Projection *projection) = 0;
virtual void visit(ProjectionField *proj_field) = 0;
virtual void visit(Rpc *rpc) = 0;
virtual void visit(Parameter *parameter) = 0;
virtual void visit(Typedef *type_def) = 0;
virtual void visit(ProjectionType *proj_type) = 0;
virtual void visit(PrimitiveType *prim_type) = 0;
virtual void visit(UnresolvedType *unresolved_type) = 0;
// virtual void visit(Type *type) = 0;
// virtual void visit(Definition* def) = 0;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment