Commit 625e3986 authored by Sarah Spall's avatar Sarah Spall Committed by Vikram Narayanan

accept calls for allocation visitor

parent 5d4e9753
......@@ -12,11 +12,26 @@ Marshal_type* Typedef::accept(MarshalVisitor *worker, Registers *data)
return worker->visit(this, data);
}
CCSTStatement* Typedef::accept(AllocateTypeVisitor *worker, Variable *v)
{
return worker->visit(this, v);
}
const char* Typedef::alias()
{
return this->alias_;
}
Type* Typedef::type()
{
return this->type_;
}
int Typedef::num()
{
return 1;
}
VoidType::VoidType()
{
}
......@@ -26,6 +41,16 @@ Marshal_type* VoidType::accept(MarshalVisitor *worker, Registers *data)
return worker->visit(this, data);
}
CCSTStatement* VoidType::accept(AllocateTypeVisitor *worker, Variable *v)
{
return worker->visit(this, v);
}
int VoidType::num()
{
return 5;
}
IntegerType::IntegerType(PrimType type, bool un, int size)
{
this->type_ = type;
......@@ -38,6 +63,11 @@ Marshal_type* IntegerType::accept(MarshalVisitor* worker, Registers *data)
return worker->visit(this, data);
}
CCSTStatement* IntegerType::accept(AllocateTypeVisitor *worker, Variable *v)
{
return worker->visit(this, v);
}
PrimType IntegerType::int_type()
{
return this->type_;
......@@ -48,44 +78,85 @@ bool IntegerType::is_unsigned()
return unsigned_;
}
int IntegerType::num()
{
return 2;
}
PointerType::PointerType(Type* type)
{
this->type_ = type;
}
int PointerType::num()
{
return 3;
}
Type* PointerType::type()
{
return this->type_;
}
Marshal_type* PointerType::accept(MarshalVisitor* worker, Registers *data)
{
return worker->visit(this, data);
}
ProjectionField::ProjectionField(bool in, bool out, bool alloc, bool bind, Type* field_type, const char* field_name)
CCSTStatement* PointerType::accept(AllocateTypeVisitor *worker, Variable *v)
{
this->in_ = in; this->out_ = out; this->alloc_ = alloc; this->bind_ = bind; this->field_type_ = field_type; this->field_name_ = field_name;
return worker->visit(this, v);
}
bool ProjectionField::in()
ProjectionField::ProjectionField(bool in, bool out, bool alloc, bool bind, Type* field_type, const char* field_name, ProjectionType *container_projection)
{
return this->in_;
this->in_ = in;
this->out_ = out;
this->alloc_ = alloc;
this->bind_ = bind;
this->field_type_ = field_type;
this->field_name_ = field_name;
this->container_ = container_projection;
}
bool ProjectionField::out()
Marshal_type* ProjectionField::accept(MarshalVisitor* worker, Registers *data)
{
return this->out_;
return worker->visit(this, data);
}
bool ProjectionField::alloc()
Type* ProjectionField::type()
{
return this->alloc_;
return this->field_type_;
}
bool ProjectionField::bind()
Rpc* ProjectionField::scope()
{
return this->bind_;
return this->accessor_->scope();
}
Marshal_type* ProjectionField::accept(MarshalVisitor* worker, Registers *data)
const char* ProjectionField::identifier()
{
return worker->visit(this, data);
return this->field_name_;
}
void ProjectionField::set_accessor(Variable *v)
{
this->accessor_ = v;
}
Variable* ProjectionField::accessor()
{
return this->accessor_;
}
bool ProjectionField::in()
{
return this->in_;
}
bool ProjectionField::out()
{
return this->out_;
}
ProjectionType::ProjectionType(const char* id, const char* real_type, std::vector<ProjectionField*> fields)
......@@ -98,6 +169,11 @@ Marshal_type* ProjectionType::accept(MarshalVisitor* worker, Registers *data)
return worker->visit(this, data);
}
CCSTStatement* ProjectionType::accept(AllocateTypeVisitor *worker, Variable *v)
{
return worker->visit(this, v);
}
const char* ProjectionType::id()
{
return this->id_;
......@@ -109,6 +185,16 @@ const char* ProjectionType::real_type()
return this->real_type_;
}
std::vector<ProjectionField*> ProjectionType::fields()
{
return this->fields_;
}
int ProjectionType::num()
{
return 4;
}
Parameter::Parameter(Type* type, const char* name)
{
this->type_ = type;
......@@ -120,18 +206,162 @@ Marshal_type* Parameter::accept(MarshalVisitor* worker, Registers *data)
return worker->visit(this, data);
}
const char* Parameter::name()
const char* Parameter::identifier()
{
return this->name_;
}
Type* Parameter::type()
{
return this->type_;
}
Rpc* Parameter::scope()
{
return this->function_;
}
void Parameter::set_accessor(Variable *v)
{
this->accessor_ = v;
}
Variable* Parameter::accessor()
{
return this->accessor_;
}
void Parameter::set_marshal_info(Marshal_type* mt)
{
this->marshal_info_ = mt;
}
Marshal_type* Parameter::marshal_info()
{
return this->marshal_info_;
}
ReturnVariable::ReturnVariable()
{
}
ReturnVariable::ReturnVariable(Type *return_type)
{
this->type_ = return_type;
this->name_ = "";
}
void ReturnVariable::set_marshal_info(Marshal_type *mt)
{
this->marshal_info_ = mt;
}
Marshal_type* ReturnVariable::marshal_info()
{
return this->marshal_info_;
}
const char* ReturnVariable::identifier()
{
return this->name_;
}
Type* ReturnVariable::type()
{
return this->type_;
}
void ReturnVariable::set_accessor(Variable *v)
{
this->accessor_ = v;
}
Rpc* ReturnVariable::scope()
{
return this->function_;
}
Variable* ReturnVariable::accessor()
{
return this->accessor_;
}
ImplicitReturnVariable::ImplicitReturnValue(Parameter *p)
{
this->p_ = p;
}
void ImplicitReturnValue::set_marshal_info(Marshal_type *mt)
{
this->marshal_info_ = mt;
}
Marshal_type* ImplicitReturnVariable::marshal_info()
{
return this->marshal_info_;
}
Rpc::Rpc(Type* return_type, char* name, std::vector<Parameter* > parameters)
void ImplicitReturnVariable::set_accesor(Variable *v)
{
this->explicit_ret_type_ = return_type;
this->accessor_ = v;
}
Type* ImplicitReturnVariable::type()
{
return this->p_->type();
}
const char* ImplicitReturnVariable::identifier()
{
return this->p_->identifier();
}
Rpc* ImplicitReturnVariable::scope()
{
return this->function_;
}
Variable* ImplicitReturnVariable::accessor()
{
return this->accessor_;
}
Rpc::Rpc(ReturnVariable *return_value, char* name, std::vector<Parameter* > parameters)
{
this->explicit_return_ = return_value;
this->name_ = name;
this->params_ = parameters;
this->set_implicit_returns();
this->symbol_table_ = new SymbolTable();
for(std::vector<Parameter*>::iterator it = parameters.begin(); it != parameters.end(); it ++)
{
Parameter *p = (Parameter*) *it;
this->symbol_table_->insert(p->identifier());
}
}
ReturnVariable* Rpc::return_value()
{
return this->explicit_return_;
}
void Rpc::set_implicit_returns()
{
std::vector<ImplicitReturnVariable*> implicit_returns;
for(std::vector<Parameter*>::iterator it = this->parameters_.begin(); it != this->parameters_.end(); it ++)
{
Parameter *p = (Parameter*) *it;
if(p->type()->num() == 3) // Pointer //make an enum......
{
implicit_returns.push_back(new ImplicitReturnVariable(p));
}
}
this->implicit_returns_ = implicit_returns;
}
char* Rpc::name()
......
......@@ -28,6 +28,7 @@ class Type : public Base
public:
virtual Marshal_type* accept(MarshalVisitor *worker, Registers *data) = 0;
virtual CCSTTypeName* accept(TypeNameVisitor *worker) = 0;
virtual CCSTStatement* accept(AllocateTypeVisitor *worker, Variable *v) = 0;
virtual int num() = 0;
};
......@@ -88,6 +89,7 @@ class Typedef : public Type
Typedef(const char* alias, Type* type);
virtual Marshal_type* accept(MarshalVisitor *worker, Registers *data);
virtual CCSTTypeName* accept(TypeNameVisitor *worker);
virtual CCSTStatement* accept(AllocateTypeVisitor *worker, Variable *v);
Type* type();
const char* alias();
virtual int num();
......@@ -100,6 +102,7 @@ class VoidType : public Type
VoidType();
virtual Marshal_type* accept(MarshalVisitor *worker, Registers *data);
virtual CCSTTypeName* accept(TypeNameVisitor *worker);
virtual CCSTStatement* accept(AllocateTypeVisitor *worker, Variable *v);
virtual int num();
};
......@@ -113,6 +116,7 @@ class IntegerType : public Type
IntegerType(PrimType type, bool un, int size);
virtual Marshal_type* accept(MarshalVisitor *worker, Registers *data);
virtual CCSTTypeName* accept(TypeNameVisitor *worker);
virtual CCSTStatement* accept(AllocateTypeVisitor *worker, Variable *v);
PrimType int_type();
bool is_unsigned();
virtual int num();
......@@ -126,6 +130,7 @@ class PointerType : public Type
PointerType(Type* type);
virtual Marshal_type* accept(MarshalVisitor *worker, Registers *data);
virtual CCSTTypeName* accept(TypeNameVisitor *worker);
virtual CCSTStatement* accept(AllocateTypeVisitor *worker, Variable *v);
Type* type();
virtual int num();
~PointerType(){printf("pointer type destructor\n");}
......@@ -162,6 +167,7 @@ class ProjectionType : public Type // complex type
ProjectionType(const char* id, const char* real_type, std::vector<ProjectionField*> fields);
virtual Marshal_type* accept(MarshalVisitor *worker, Registers *data);
virtual CCSTTypeName* accept(TypeNameVisitor *worker);
virtual CCSTStatement* accept(AllocateTypeVisitor *worker, Variable *v);
const char* id();
const char* real_type();
std::vector<ProjectionField*> fields();
......@@ -297,11 +303,11 @@ class AllocateTypeVisitor
CCSTStatement* allocation_helper(ProjectionType *vt, Variable *v, int pointer_count);
public:
AllocateTypeVisitor();
CCSTStatement* visit(Typedef *td);
CCSTStatement* visit(VoidType *vt);
CCSTStatement* visit(IntegerType *it);
CCSTStatement* visit(PointerType *pt);
CCSTStatement* visit(ProjectionType *pt);
CCSTStatement* visit(Typedef *td, Variable *v);
CCSTStatement* visit(VoidType *vt, Variable *v);
CCSTStatement* visit(IntegerType *it, Variable *v);
CCSTStatement* visit(PointerType *pt, Variable *v);
CCSTStatement* visit(ProjectionType *pt, Variable *v);
};
......
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