Commit 428543c4 authored by Sarah Spall's avatar Sarah Spall Committed by Vikram Narayanan

fixed circular dependency issues with visitor and ast. Moved visitor definition into ast h file

parent c103639d
......@@ -18,3 +18,42 @@ Scope::Scope()
builtin->insert( std::pair<int,Type>(1, new IntegerType(kCapability, false, sizeof("int"))));
}
void Typedef::accept(ASTVisitor* worker)
{
worker->visit(this);
}
void IntegerType::accept(ASTVisitor* worker)
{
worker->visit(this);
}
void PointerType::accept(ASTVisitor* worker)
{
worker->visit(this);
}
void ProjectionType::accept(ASTVisitor* worker)
{
worker->visit(this);
}
void Parameter::accept(ASTVisitor* worker)
{
worker->visit(this);
}
void Rpc::accept(ASTVisitor* worker)
{
worker->visit(this);
}
void ProjectionField::accept(ASTVisitor* worker)
{
worker->visit(this);
}
void File::accept(ASTVisitor* worker)
{
worker->visit(this);
}
......@@ -6,30 +6,38 @@
enum PrimType { kChar = 1, kShort, kInt, kLong, kLongLong, kCapability};
class ASTVisitor;
class Base
{
M_info info;
//M_info info;
};
class Type : public Base
{
public:
virtual void accept(ASTVisitor *worker) = 0;
virtual void marshal() = 0;
virtual int size() = 0;
};
class Scope : public Base
{
// add built in types here, so size can be evaluated before parse
private:
map<int,Type> types_;
std::map<int,Type> types_;
void init_types();
public:
Scope();
lookup_symbol(char* sym);
Type* lookup_symbol(char* sym);
};
class Type : public Base
class RootScope : public Scope
{
public:
virtual void accept(ASTVisitor *worker) = 0;
virtual void marshal() = 0;
virtual int size() = 0;
RootScope();
};
class Typedef : public Type
{
Type* type_;
......@@ -40,18 +48,18 @@ class Typedef : public Type
virtual void accept(ASTVisitor *worker);
virtual void marshal();
}
};
class IntegerType : public Type
{
bool unsigned_;
PrimType type_;
int size_:
int size_;
public:
IntegerType(PrimType type, bool unsigned, int size)
{ this->unsigned_ = unsigned; this->type_ = type; this->size_ = size;}
virtual void accept(ASTVisitor *worker) { worker->visit(this); }
IntegerType(PrimType type, bool un, int size)
{ this->unsigned_ = un; this->type_ = type; this->size_ = size;}
virtual void accept(ASTVisitor *worker);
virtual void marshal();
};
......@@ -65,10 +73,31 @@ class PointerType : public Type
Type* type_;
public:
PointerType(Type* type);
virtual void accept(ASTVisitor *worker) { worker->visit(this); }
virtual void accept(ASTVisitor *worker);
virtual void marshal();
};
class ProjectionField : public Base
{
bool in_;
bool out_;
bool alloc_;
bool bind_;
Type* field_type_;
char* field_name_;
public:
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; }
~ProjectionField();
bool in() { return in_; }
bool out() { return out_; }
bool alloc() { return alloc_; }
bool bind() { return bind_; }
void accept(ASTVisitor *worker);
};
class ProjectionType : public Type // complex type
{
char* id_;
......@@ -78,7 +107,7 @@ class ProjectionType : public Type // complex type
public:
ProjectionType(char * id, char* real_type, std::vector<ProjectionField*>* fields)
{ this->id_ = id; this->real_type_ = real_type; this->fields_ = fields; }
void accept(ASTVisitor *worker) { worker->visit(this); }
void accept(ASTVisitor *worker);
virtual void marshal();
};
......@@ -86,12 +115,12 @@ class Parameter : public Base
{
Type* type_;
char* name_;
M_info m;
//M_info m;
public:
Parameter(Type* type, char* name)
{ this->type_ = type; this->name_ = name; m = new M_info(); }
{ this->type_ = type; this->name_ = name; }//m = new M_info(); }
~Parameter();
void accept(ASTVisitor *worker) { worker->visit(this); }
void accept(ASTVisitor *worker);
};
class Rpc : public Base
......@@ -102,37 +131,16 @@ class Rpc : public Base
public:
Rpc(Type* return_type, char* name, std::vector<Parameter* >* parameters) {
this->return_type_ = return_type;
this->ret_type_ = return_type;
this->name_ = name;
this->parameters_ = parameters; }
DefinitionType get_definition_type(){ return kRpc; }
this->params_ = parameters; }
char* name() { return name_; }
Type* return_type() { return return_type_; }
std::vector<Parameter*>* parameters() { return parameters_; }
void accept(ASTVisitor *worker) { worker->visit(this); }
Type* return_type() { return ret_type_; }
std::vector<Parameter*>* parameters() { return params_; }
void accept(ASTVisitor *worker);
};
class ProjectionField : public Base
{
bool in_;
bool out_;
bool alloc_;
bool bind_;
Type* field_type_;
char* field_name_;
public:
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; }
~ProjectionField();
bool in() { return in_; }
bool out() { return out_; }
bool alloc() { return alloc_; }
bool bind() { return bind_; }
void accept(ASTVisitor *worker) { worker->visit(this); }
virtual void marshal(); // should this be connected to type needs to be marshalled too?
};
/*
class MessageField
......@@ -165,21 +173,33 @@ class Message : public Definition
class File : public Scope
{
char* verbatim_;
Root_scope * root_scope_;
RootScope * root_scope_;
std::vector<Rpc *>* rpc_defs_;
std::vector<Message *>* message_defs_;
// std::vector<Message *>* message_defs_;
public:
File(char* verbatim, Root_scope* rs, std::vector<Rpc* >* rpc_definitions, std::vector<Message* >* message_definitions) {
File(char* verbatim, RootScope* rs, std::vector<Rpc* >* rpc_definitions) {
this->verbatim_ = verbatim;
this->root_scope_ = rs;
this->rpc_definitions_ = rpc_definitions;
this->message_definitions_ = message_definitions;
this->rpc_defs_ = rpc_definitions;
}
void accept(ASTVisitor *worker) { worker->visit(this); }
void accept(ASTVisitor *worker);
};
class ASTVisitor
{
public:
virtual void visit(File *file) = 0;
// virtual void visit(Message *message) = 0;
// virtual void visit(MessageField *message_field) = 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(PointerType *pointer_type) = 0;
virtual void visit(IntegerType *integer_type) = 0;
};
#endif
#ifndef _VISITOR_
#define _VISITOR_
class ASTVisitor
{
public:
virtual void visit(File *file) = 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
#include "lcd_ast.h"
#include "lcd_idl.h"
#include "include/lcd_ast.h"
#include "parser/lcd_idl.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
......
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