Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscript Operator #92

Merged
merged 32 commits into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2778f00
Remove blank line
rdtscp May 10, 2019
d7e9fe4
Add SubscriptOperator to Grammar
rdtscp May 10, 2019
24e11fb
Add SubscriptOp to AST
rdtscp May 10, 2019
4067bf5
Remove inefficient atl::make_shared. Add unit test
rdtscp May 11, 2019
315e537
Fix unit test
rdtscp May 11, 2019
c98e1b0
Remove ArrayAccess node.
rdtscp May 11, 2019
f393d2f
Include the FunDecl required for performing this SubscriptOp
rdtscp May 11, 2019
71ff1c4
Handle SubscriptOp, provide helper for collapsing reference types to …
rdtscp May 11, 2019
1e04909
Completely refactor Scope's to be an abstract class.
rdtscp May 14, 2019
5a6f6aa
Remove dead code.
rdtscp May 14, 2019
36d8eea
Fix parseIdentifier()
rdtscp May 14, 2019
96693f8
Remove whitespace
rdtscp May 14, 2019
b2d3373
Remove dead code
rdtscp May 14, 2019
70f7d94
Remove getSignature().
rdtscp May 14, 2019
0f29fc9
Use FunSignature to to Function resolution.
rdtscp May 14, 2019
287dbbb
Temp, update test.
rdtscp May 14, 2019
38c24e3
FunDecl's should ensure their return types are valid.
rdtscp May 14, 2019
6db6f6d
FunSignature and Identifier namespacing ops.
rdtscp May 15, 2019
dc24ff6
TODO
rdtscp May 15, 2019
02d709d
Namespace resolution.
rdtscp May 15, 2019
87da0c4
Namespacing UnitTest
rdtscp May 15, 2019
88f05eb
Implement something to catch uses before decls.
rdtscp May 15, 2019
709e206
Add TODO
rdtscp May 15, 2019
ba08a7a
Bugfix
rdtscp May 15, 2019
fd625df
Bugfix
rdtscp May 15, 2019
8e0e509
Some work for SubscriptOp. Check the type of a VarDecl/Def Properly
rdtscp May 15, 2019
aa77d18
Create ConstructorCall, Do semantic analysis for ConstructorCalls
rdtscp May 15, 2019
2525a4d
Unit test ClassTypeDef and operator[]
rdtscp May 15, 2019
8892f4f
Clean up some TODOs.
rdtscp May 15, 2019
32c460b
Remove Hex, no need for support.
rdtscp May 15, 2019
1365f58
Support unsigned literals in lexing.
rdtscp May 15, 2019
ea4a154
Handle IntLiterals with suffix 'u'
rdtscp May 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ include_directories("${CMAKE_SOURCE_DIR}/include/")
add_library(AST SHARED
src/ast/AddressOf.cpp
src/ast/Allocation.cpp
src/ast/ArrayAccess.cpp
src/ast/ArrayType.cpp
src/ast/Assign.cpp
src/ast/BaseType.cpp
Expand All @@ -30,6 +29,7 @@ add_library(AST SHARED
src/ast/ClassType.cpp
src/ast/ClassTypeDecl.cpp
src/ast/ClassTypeDef.cpp
src/ast/ConstructorCall.cpp
src/ast/ConstructorDecl.cpp
src/ast/ConstructorDef.cpp
src/ast/Deletion.cpp
Expand All @@ -54,9 +54,9 @@ add_library(AST SHARED
src/ast/Program.cpp
src/ast/ReferenceType.cpp
src/ast/Return.cpp
src/ast/Scope.cpp
src/ast/SizeOf.cpp
src/ast/StringLiteral.cpp
src/ast/SubscriptOp.cpp
src/ast/TertiaryExpr.cpp
src/ast/Throw.cpp
src/ast/TypeCast.cpp
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Progressively changing to adopt new features of the language(s).
| "new" type [ "(" litExpr ("," litExpr)* ")" ] ";"
| "&" objExpr
| "!" objExpr
| objExpr "[" expr "]
| objExpr

objExpr -> funCall (objExprOp)*
Expand All @@ -131,8 +132,8 @@ Progressively changing to adopt new features of the language(s).
| STRING_LITERAL
| "true"
| "false"
| "(" exp ")"
| exp
| "(" expr ")"
| expr

* * *

Expand Down
3 changes: 2 additions & 1 deletion include/AST.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "ast/AddressOf.h"
#include "ast/Allocation.h"
#include "ast/ArrayAccess.h"
#include "ast/ArrayType.h"
#include "ast/Assign.h"
#include "ast/BaseType.h"
Expand All @@ -15,6 +14,7 @@
#include "ast/ClassType.h"
#include "ast/ClassTypeDecl.h"
#include "ast/ClassTypeDef.h"
#include "ast/ConstructorCall.h"
#include "ast/ConstructorDecl.h"
#include "ast/ConstructorDef.h"
#include "ast/Decl.h"
Expand Down Expand Up @@ -47,6 +47,7 @@
#include "ast/SizeOf.h"
#include "ast/Stmt.h"
#include "ast/StringLiteral.h"
#include "ast/SubscriptOp.h"
#include "ast/TertiaryExpr.h"
#include "ast/Throw.h"
#include "ast/Type.h"
Expand Down
6 changes: 4 additions & 2 deletions include/ASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace ACC {

class AddressOf;
class Allocation;
class ArrayAccess;
class ArrayType;
class Assign;
class BaseType;
Expand All @@ -15,6 +14,7 @@ class CharLiteral;
class ClassType;
class ClassTypeDecl;
class ClassTypeDef;
class ConstructorCall;
class ConstructorDecl;
class ConstructorDef;
class Deletion;
Expand All @@ -41,6 +41,7 @@ class ReferenceType;
class Return;
class SizeOf;
class StringLiteral;
class SubscriptOp;
class TertiaryExpr;
class Throw;
class TypeCast;
Expand All @@ -58,7 +59,6 @@ template <typename T> class ASTVisitor {

virtual T visit(AddressOf &ao) = 0;
virtual T visit(Allocation &a) = 0;
virtual T visit(ArrayAccess &aa) = 0;
virtual T visit(ArrayType &at) = 0;
virtual T visit(Assign &as) = 0;
virtual T visit(BaseType &bt) = 0;
Expand All @@ -69,6 +69,7 @@ template <typename T> class ASTVisitor {
virtual T visit(ClassType &ct) = 0;
virtual T visit(ClassTypeDecl &ctd) = 0;
virtual T visit(ClassTypeDef &ctd) = 0;
virtual T visit(ConstructorCall &cc) = 0;
virtual T visit(ConstructorDecl &cd) = 0;
virtual T visit(ConstructorDef &cd) = 0;
virtual T visit(Deletion &d) = 0;
Expand All @@ -95,6 +96,7 @@ template <typename T> class ASTVisitor {
virtual T visit(Return &r) = 0;
virtual T visit(SizeOf &so) = 0;
virtual T visit(StringLiteral &sl) = 0;
virtual T visit(SubscriptOp &so) = 0;
virtual T visit(TertiaryExpr &t) = 0;
virtual T visit(Throw &t) = 0;
virtual T visit(TypeCast &tc) = 0;
Expand Down
2 changes: 0 additions & 2 deletions include/ast/AddressOf.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class AddressOf : public Expr, public atl::enable_shared_from_this<AddressOf> {

AddressOf(const atl::shared_ptr<Expr> &p_addressOfExpr);

atl::string getSignature() const override;

bool operator==(Expr &rhs) const override;
bool operator!=(Expr &rhs) const override;

Expand Down
3 changes: 1 addition & 2 deletions include/ast/Allocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class Allocation : public Expr,

virtual ~Allocation() {}

atl::string getSignature() const override;


bool operator==(Expr &rhs) const override;
bool operator!=(Expr &rhs) const override;

Expand Down
33 changes: 0 additions & 33 deletions include/ast/ArrayAccess.h

This file was deleted.

6 changes: 2 additions & 4 deletions include/ast/ArrayType.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ class ArrayType : public PointerType {
ArrayType(const atl::shared_ptr<Type> &p_type,
const atl::shared_ptr<Expr> &p_size);

int getBytes() const override;
unsigned int getBytes() const override;

atl::string getSignature() const override;

bool operator==(Type &rhs) const override;
bool operator==(Type &rhs) const override;
bool operator!=(Type &rhs) const override;

bool operator==(const ArrayType &rhs) const;
Expand Down
6 changes: 2 additions & 4 deletions include/ast/BaseType.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ class BaseType : public Type, public atl::enable_shared_from_this<BaseType> {

BaseType(const PrimitiveType p_pType);

int getBytes() const override;
unsigned int getBytes() const override;

atl::string getSignature() const override;

bool operator==(Type &rhs) const override;
bool operator==(Type &rhs) const override;
bool operator!=(Type &rhs) const override;

bool operator==(const BaseType &rhs) const;
Expand Down
3 changes: 1 addition & 2 deletions include/ast/BinOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ class BinOp : public Expr, public atl::enable_shared_from_this<BinOp> {
BinOp(const atl::shared_ptr<Expr> &p_lhs, const Op p_operation,
const atl::shared_ptr<Expr> &p_rhs);

atl::string getSignature() const override;


bool operator==(Expr &rhs) const override;
bool operator!=(Expr &rhs) const override;

Expand Down
26 changes: 26 additions & 0 deletions include/ast/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Block : public Stmt,
public atl::enable_shared_from_this<Block> {

public:
unsigned int stmtsChecked = 0;
atl::vector<atl::shared_ptr<Stmt>> stmts;

Block(const atl::vector<atl::shared_ptr<Stmt>> &p_stmts);
Expand All @@ -23,6 +24,31 @@ class Block : public Stmt,

atl::string astClass() const override { return "Block"; }

/* Scope Methods */
virtual atl::shared_ptr<ClassTypeDecl> findClassDecl(
const atl::shared_ptr<Identifier> identifier,
const atl::shared_ptr<Decl> &exemptDecl = nullptr) const override;

virtual atl::shared_ptr<ClassTypeDef> findClassDef(
const atl::shared_ptr<Identifier> identifier,
const atl::shared_ptr<Decl> &exemptDecl = nullptr) const override;

virtual atl::shared_ptr<FunDecl>
findFunDecl(const FunSignature &funSignature,
const atl::shared_ptr<Decl> &exemptDecl = nullptr) const override;

virtual atl::shared_ptr<FunDecl> findFunDeclLocal(
const FunSignature &funSignature,
const atl::shared_ptr<Decl> &exemptDecl = nullptr) const override;

virtual atl::shared_ptr<VarDecl>
findVarDecl(const atl::shared_ptr<Identifier> identifier,
const atl::shared_ptr<Decl> &exemptDecl = nullptr) const override;

virtual atl::shared_ptr<VarDecl> findVarDeclLocal(
const atl::shared_ptr<Identifier> identifier,
const atl::shared_ptr<Decl> &exemptDecl = nullptr) const override;

VISITOR_ACCEPTORS
};

Expand Down
3 changes: 1 addition & 2 deletions include/ast/BoolLiteral.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class BoolLiteral : public Literal,
public:
BoolLiteral(const atl::string &p_literal);

atl::string getSignature() const override;


bool operator==(Expr &rhs) const override;
bool operator!=(Expr &rhs) const override;

Expand Down
3 changes: 1 addition & 2 deletions include/ast/CharLiteral.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class CharLiteral : public Literal,
public:
CharLiteral(const atl::string &p_literal);

atl::string getSignature() const override;


bool operator==(Expr &rhs) const override;
bool operator!=(Expr &rhs) const override;

Expand Down
4 changes: 1 addition & 3 deletions include/ast/ClassType.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ class ClassType : public Type, public atl::enable_shared_from_this<ClassType> {

ClassType(const atl::shared_ptr<Identifier> &p_identifier);

int getBytes() const override;

atl::string getSignature() const override;
unsigned int getBytes() const override;

bool operator==(Type &rhs) const override;
bool operator!=(Type &rhs) const override;
Expand Down
25 changes: 25 additions & 0 deletions include/ast/ClassTypeDecl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,31 @@ class ClassTypeDecl : public Decl,

atl::string astClass() const override { return "ClassTypeDecl"; }

/* Scope Methods */
virtual atl::shared_ptr<ClassTypeDecl> findClassDecl(
const atl::shared_ptr<Identifier> identifier,
const atl::shared_ptr<Decl> &exemptDecl = nullptr) const override;

virtual atl::shared_ptr<ClassTypeDef> findClassDef(
const atl::shared_ptr<Identifier> identifier,
const atl::shared_ptr<Decl> &exemptDecl = nullptr) const override;

virtual atl::shared_ptr<FunDecl>
findFunDecl(const FunSignature &funSignature,
const atl::shared_ptr<Decl> &exemptDecl = nullptr) const override;

virtual atl::shared_ptr<FunDecl> findFunDeclLocal(
const FunSignature &funSignature,
const atl::shared_ptr<Decl> &exemptDecl = nullptr) const override;

virtual atl::shared_ptr<VarDecl>
findVarDecl(const atl::shared_ptr<Identifier> identifier,
const atl::shared_ptr<Decl> &exemptDecl = nullptr) const override;

virtual atl::shared_ptr<VarDecl> findVarDeclLocal(
const atl::shared_ptr<Identifier> identifier,
const atl::shared_ptr<Decl> &exemptDecl = nullptr) const override;

VISITOR_ACCEPTORS
};

Expand Down
29 changes: 29 additions & 0 deletions include/ast/ClassTypeDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,35 @@ class ClassTypeDef : public ClassTypeDecl {

atl::string astClass() const override { return "ClassTypeDef"; }

/* Scope Methods */
virtual atl::shared_ptr<ClassTypeDecl> findClassDecl(
const atl::shared_ptr<Identifier> identifier,
const atl::shared_ptr<Decl> &exemptDecl = nullptr) const override;

virtual atl::shared_ptr<ClassTypeDef> findClassDef(
const atl::shared_ptr<Identifier> identifier,
const atl::shared_ptr<Decl> &exemptDecl = nullptr) const override;

atl::shared_ptr<ConstructorDecl>
findConstructorDecl(const FunSignature &ctorSignature,
const atl::shared_ptr<Decl> &exemptDecl = nullptr) const;

virtual atl::shared_ptr<FunDecl>
findFunDecl(const FunSignature &funSignature,
const atl::shared_ptr<Decl> &exemptDecl = nullptr) const override;

virtual atl::shared_ptr<FunDecl> findFunDeclLocal(
const FunSignature &funSignature,
const atl::shared_ptr<Decl> &exemptDecl = nullptr) const override;

virtual atl::shared_ptr<VarDecl>
findVarDecl(const atl::shared_ptr<Identifier> identifier,
const atl::shared_ptr<Decl> &exemptDecl = nullptr) const override;

virtual atl::shared_ptr<VarDecl> findVarDeclLocal(
const atl::shared_ptr<Identifier> identifier,
const atl::shared_ptr<Decl> &exemptDecl = nullptr) const override;

VISITOR_ACCEPTORS
};

Expand Down
34 changes: 34 additions & 0 deletions include/ast/ConstructorCall.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include "ConstructorDecl.h"
#include "Expr.h"
#include "Identifier.h"
#include "Type.h"

namespace ACC {

class ConstructorCall : public Expr,
public atl::enable_shared_from_this<ConstructorCall> {

public:
atl::shared_ptr<Identifier> constructorIdentifier;
atl::vector<atl::shared_ptr<Expr>> constructorArgs;
atl::shared_ptr<ConstructorDecl> constructorDecl;

ConstructorCall(const atl::shared_ptr<Identifier> &p_ctorIdentifier,
const atl::vector<atl::shared_ptr<Expr>> &p_ctorArgs);

bool operator==(Expr &rhs) const override;
bool operator!=(Expr &rhs) const override;

bool operator==(const ConstructorCall &rhs) const;
bool operator!=(const ConstructorCall &rhs) const;

atl::shared_ptr<ConstructorCall> getptr() { return shared_from_this(); }

atl::string astClass() const override { return "ConstructorCall"; }

VISITOR_ACCEPTORS
};

} // namespace ACC
Loading