Skip to content

Commit

Permalink
[Structs] Added initial support for structs
Browse files Browse the repository at this point in the history
  • Loading branch information
dmed256 committed Apr 3, 2019
1 parent 897f600 commit beec086
Show file tree
Hide file tree
Showing 24 changed files with 1,988 additions and 1,571 deletions.
25 changes: 12 additions & 13 deletions include/occa/lang/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,25 @@ namespace occa {
void loadDeclarationBraceInitializer(variableDeclaration &decl);

vartype_t loadType();
struct_t* loadStruct();

qualifiers_t loadQualifiers();

void loadBaseType(vartype_t &vartype);

void loadQualifier(token_t *token,
const qualifier_t &qualifier,
vartype_t &vartype);
void loadVartypeQualifier(token_t *token,
const qualifier_t &qualifier,
vartype_t &vartype);

void setPointers(vartype_t &vartype);
void setPointer(vartype_t &vartype);
void setVartypePointers(vartype_t &vartype);
void setVartypePointer(vartype_t &vartype);

void setReference(vartype_t &vartype);
void setVartypeReference(vartype_t &vartype);

bool isLoadingFunctionPointer();
bool isLoadingVariable();
bool isLoadingFunction();
bool isLoadingStruct();

variable_t loadFunctionPointer(vartype_t &vartype);
variable_t loadVariable(vartype_t &vartype);
Expand All @@ -176,11 +180,6 @@ namespace occa {
public:
void getArgumentRanges(tokenRangeVector &argRanges);
variable_t getArgument();

class_t loadClassType();
struct_t loadStructType();
enum_t loadEnumType();
union_t loadUnionType();
//================================

//---[ Loader Helpers ]-----------
Expand All @@ -199,9 +198,9 @@ namespace occa {

statement_t* loadDeclarationStatement(attributeTokenMap &smntAttributes);

statement_t* loadNamespaceStatement(attributeTokenMap &smntAttributes);
statement_t* loadStructStatement(attributeTokenMap &smntAttributes);

statement_t* loadTypeDeclStatement(attributeTokenMap &smntAttributes);
statement_t* loadNamespaceStatement(attributeTokenMap &smntAttributes);

statement_t* loadFunctionStatement(attributeTokenMap &smntAttributes);

Expand Down
2 changes: 2 additions & 0 deletions include/occa/lang/qualifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ namespace occa {
const udim_t qtype_);
~qualifier_t();

bool operator == (const qualifier_t &other) const;

udim_t type() const;
};

Expand Down
1 change: 1 addition & 0 deletions include/occa/lang/statement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <occa/lang/statement/functionDeclStatement.hpp>
#include <occa/lang/statement/gotoStatement.hpp>
#include <occa/lang/statement/pragmaStatement.hpp>
#include <occa/lang/statement/structStatement.hpp>
#include <occa/lang/statement/switchStatement.hpp>
#include <occa/lang/statement/caseStatement.hpp>
#include <occa/lang/statement/declarationStatement.hpp>
Expand Down
7 changes: 6 additions & 1 deletion include/occa/lang/statement/statement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ namespace occa {
extern const int block;
extern const int namespace_;

extern const int typeDecl;
extern const int function;
extern const int functionDecl;

extern const int class_;
extern const int struct_;
extern const int classAccess;

extern const int enum_;
extern const int union_;

extern const int expression;
extern const int declaration;

Expand Down
30 changes: 30 additions & 0 deletions include/occa/lang/statement/structStatement.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef OCCA_LANG_STATEMENT_STRUCTSTATEMENT_HEADER
#define OCCA_LANG_STATEMENT_STRUCTSTATEMENT_HEADER

#include <occa/lang/statement/statement.hpp>
#include <occa/lang/type/struct.hpp>

namespace occa {
namespace lang {
class structStatement : public statement_t {
public:
struct_t &struct_;

structStatement(blockStatement *up_,
struct_t &struct_);
structStatement(blockStatement *up_,
const structStatement& other);

virtual statement_t& clone_(blockStatement *up_) const;

virtual int type() const;
virtual std::string statementName() const;

bool addStructToParentScope();

virtual void print(printer &pout) const;
};
}
}

#endif
5 changes: 5 additions & 0 deletions include/occa/lang/tokenContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace occa {
intIntMap pairs;
intVector semicolons;
bool hasError;
bool supressErrors;

tokenRangeList stack;
tokenRange tp;
Expand Down Expand Up @@ -69,7 +70,11 @@ namespace occa {

int position() const;
int size() const;

token_t* operator [] (const int index);
tokenContext& operator ++ ();
tokenContext& operator ++ (int);

void setToken(const int index,
token_t *value);

Expand Down
12 changes: 10 additions & 2 deletions include/occa/lang/type/struct.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
#ifndef OCCA_LANG_TYPE_STRUCT_HEADER
#define OCCA_LANG_TYPE_STRUCT_HEADER

#include <occa/lang/type/structure.hpp>
#include <occa/lang/type/type.hpp>

namespace occa {
namespace lang {
class struct_t : public structure_t {
class struct_t : public type_t {
public:
variableVector fields;

struct_t();
struct_t(identifierToken &nameToken);

struct_t(const struct_t &other);

virtual int type() const;
virtual type_t& clone() const;

virtual dtype_t dtype() const;

void addField(variable_t &var);
void addFields(variableVector &fields_);

virtual void printDeclaration(printer &pout) const;
};
}
Expand Down
2 changes: 1 addition & 1 deletion include/occa/lang/type/type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ namespace occa {
class array_t;
class variable_t;

typedef std::vector<pointer_t> pointerVector;
typedef std::vector<array_t> arrayVector;
typedef std::vector<pointer_t> pointerVector;
typedef std::vector<variable_t> variableVector;
typedef std::vector<variable_t*> variablePtrVector;

Expand Down
Empty file added notes.cpp
Empty file.
Loading

0 comments on commit beec086

Please sign in to comment.