changed AST

This commit is contained in:
mrexodia 2016-09-21 21:46:11 +02:00
parent 8227ec126c
commit 4b4cda91cb
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
3 changed files with 28 additions and 13 deletions

View File

@ -55,21 +55,30 @@ namespace AST
{ {
}; };
class Builtin : public Decl //built-in declaration (int x) class BuiltinVar : public Decl //built-in variable declaration (int x)
{ {
Type mType; Type mType;
string mId; string mName;
public: public:
explicit Builtin(Type type, const string & id) explicit BuiltinVar(Type type, const string & id)
: mType(type), mId(id) {} : mType(type), mName(id) {}
}; };
class Struct : public Decl //struct (can contain code, not just declarations) class Struct : public Decl //struct declaration (can contain code, not just declarations)
{ {
string mId; string mName;
uptr<Block> mBlock; uptr<Block> mBlock;
public: public:
explicit Struct(const string & id, uptr<Block> block) explicit Struct(const string & id, uptr<Block> block)
: mId(id), mBlock(move(block)) {} : mName(id), mBlock(move(block)) {}
};
class StructVar : public Decl //struct variable declaration: (struct {...} x;)
{
string mVarName; //name of the variable
string mStructName; //name of the struct
public:
explicit StructVar(const string & varName, const string & structName)
: mVarName(varName), mStructName(structName) {}
}; };
}; };

View File

@ -128,7 +128,7 @@ uptr<Return> Parser::ParseReturn()
uptr<Decl> Parser::ParseDecl() uptr<Decl> Parser::ParseDecl()
{ {
auto builtin = ParseBuiltin(); auto builtin = ParseBuiltinVar();
if (builtin) if (builtin)
return move(builtin); return move(builtin);
auto stru = ParseStruct(); auto stru = ParseStruct();
@ -137,7 +137,7 @@ uptr<Decl> Parser::ParseDecl()
return nullptr; return nullptr;
} }
uptr<Builtin> Parser::ParseBuiltin() uptr<BuiltinVar> Parser::ParseBuiltinVar()
{ {
if (CurToken.Token == Lexer::tok_uint) //TODO: properly handle types if (CurToken.Token == Lexer::tok_uint) //TODO: properly handle types
{ {
@ -145,18 +145,18 @@ uptr<Builtin> Parser::ParseBuiltin()
NextToken(); NextToken();
if (CurToken.Token != Lexer::tok_identifier) if (CurToken.Token != Lexer::tok_identifier)
{ {
ReportError("failed to parse Builtin (no identifier)"); ReportError("failed to parse BuiltinVar (no identifier)");
return nullptr; return nullptr;
} }
auto id = CurToken.IdentifierStr; auto id = CurToken.IdentifierStr;
NextToken(); NextToken();
if (CurToken.Token != Lexer::tok_semic) if (CurToken.Token != Lexer::tok_semic)
{ {
ReportError("failed to parse Builtin (no semicolon)"); ReportError("failed to parse BuiltinVar (no semicolon)");
return nullptr; return nullptr;
} }
NextToken(); NextToken();
return make_uptr<Builtin>(type, id); return make_uptr<BuiltinVar>(type, id);
} }
return nullptr; return nullptr;
} }
@ -182,3 +182,8 @@ uptr<Struct> Parser::ParseStruct()
} }
return nullptr; return nullptr;
} }
AST::uptr<AST::StructVar> Parser::ParseStructVar()
{
return nullptr;
}

View File

@ -37,6 +37,7 @@ private:
AST::uptr<AST::Return> ParseReturn(); AST::uptr<AST::Return> ParseReturn();
AST::uptr<AST::Decl> ParseDecl(); AST::uptr<AST::Decl> ParseDecl();
AST::uptr<AST::Builtin> ParseBuiltin(); AST::uptr<AST::BuiltinVar> ParseBuiltinVar();
AST::uptr<AST::Struct> ParseStruct(); AST::uptr<AST::Struct> ParseStruct();
AST::uptr<AST::StructVar> ParseStructVar();
}; };