From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- tiger-compiler/src/ast/README.txt | 66 ++++ tiger-compiler/src/ast/all.hh | 51 +++ tiger-compiler/src/ast/array-exp.cc | 31 ++ tiger-compiler/src/ast/array-exp.hh | 60 ++++ tiger-compiler/src/ast/array-exp.hxx | 22 ++ tiger-compiler/src/ast/array-ty.cc | 21 ++ tiger-compiler/src/ast/array-ty.hh | 48 +++ tiger-compiler/src/ast/array-ty.hxx | 16 + tiger-compiler/src/ast/assert-exp.cc | 24 ++ tiger-compiler/src/ast/assert-exp.hh | 42 +++ tiger-compiler/src/ast/assert-exp.hxx | 14 + tiger-compiler/src/ast/assert-visitor.hh | 51 +++ tiger-compiler/src/ast/assert-visitor.hxx | 32 ++ tiger-compiler/src/ast/assign-exp.cc | 26 ++ tiger-compiler/src/ast/assign-exp.hh | 54 ++++ tiger-compiler/src/ast/assign-exp.hxx | 19 ++ tiger-compiler/src/ast/ast-nodes.mk | 41 +++ tiger-compiler/src/ast/ast.cc | 15 + tiger-compiler/src/ast/ast.hh | 48 +++ tiger-compiler/src/ast/ast.hxx | 18 ++ tiger-compiler/src/ast/break-exp.cc | 18 ++ tiger-compiler/src/ast/break-exp.hh | 49 +++ tiger-compiler/src/ast/break-exp.hxx | 21 ++ tiger-compiler/src/ast/call-exp.cc | 27 ++ tiger-compiler/src/ast/call-exp.hh | 64 ++++ tiger-compiler/src/ast/call-exp.hxx | 25 ++ tiger-compiler/src/ast/cast-exp.cc | 26 ++ tiger-compiler/src/ast/cast-exp.hh | 62 ++++ tiger-compiler/src/ast/cast-exp.hxx | 19 ++ tiger-compiler/src/ast/chunk-interface.hh | 25 ++ tiger-compiler/src/ast/chunk-interface.hxx | 16 + tiger-compiler/src/ast/chunk-list.cc | 58 ++++ tiger-compiler/src/ast/chunk-list.hh | 80 +++++ tiger-compiler/src/ast/chunk-list.hxx | 19 ++ tiger-compiler/src/ast/chunk.hh | 139 ++++++++ tiger-compiler/src/ast/chunk.hxx | 118 +++++++ tiger-compiler/src/ast/class-ty.cc | 22 ++ tiger-compiler/src/ast/class-ty.hh | 55 ++++ tiger-compiler/src/ast/class-ty.hxx | 19 ++ tiger-compiler/src/ast/dec.cc | 17 + tiger-compiler/src/ast/dec.hh | 50 +++ tiger-compiler/src/ast/dec.hxx | 15 + tiger-compiler/src/ast/default-visitor.hh | 151 +++++++++ tiger-compiler/src/ast/default-visitor.hxx | 247 +++++++++++++++ tiger-compiler/src/ast/dumper-dot.cc | 438 ++++++++++++++++++++++++++ tiger-compiler/src/ast/dumper-dot.hh | 112 +++++++ tiger-compiler/src/ast/dumper-dot.hxx | 214 +++++++++++++ tiger-compiler/src/ast/escapable.cc | 14 + tiger-compiler/src/ast/escapable.hh | 30 ++ tiger-compiler/src/ast/escapable.hxx | 16 + tiger-compiler/src/ast/exp.cc | 16 + tiger-compiler/src/ast/exp.hh | 43 +++ tiger-compiler/src/ast/exp.hxx | 11 + tiger-compiler/src/ast/field-init.cc | 22 ++ tiger-compiler/src/ast/field-init.hh | 55 ++++ tiger-compiler/src/ast/field-init.hxx | 19 ++ tiger-compiler/src/ast/field-var.cc | 22 ++ tiger-compiler/src/ast/field-var.hh | 60 ++++ tiger-compiler/src/ast/field-var.hxx | 22 ++ tiger-compiler/src/ast/field.cc | 22 ++ tiger-compiler/src/ast/field.hh | 55 ++++ tiger-compiler/src/ast/field.hxx | 19 ++ tiger-compiler/src/ast/for-exp.cc | 28 ++ tiger-compiler/src/ast/for-exp.hh | 60 ++++ tiger-compiler/src/ast/for-exp.hxx | 22 ++ tiger-compiler/src/ast/function-dec.cc | 33 ++ tiger-compiler/src/ast/function-dec.hh | 72 +++++ tiger-compiler/src/ast/function-dec.hxx | 23 ++ tiger-compiler/src/ast/fwd.hh | 80 +++++ tiger-compiler/src/ast/if-exp.cc | 31 ++ tiger-compiler/src/ast/if-exp.hh | 71 +++++ tiger-compiler/src/ast/if-exp.hxx | 22 ++ tiger-compiler/src/ast/int-exp.cc | 19 ++ tiger-compiler/src/ast/int-exp.hh | 44 +++ tiger-compiler/src/ast/int-exp.hxx | 15 + tiger-compiler/src/ast/let-exp.cc | 26 ++ tiger-compiler/src/ast/let-exp.hh | 55 ++++ tiger-compiler/src/ast/let-exp.hxx | 19 ++ tiger-compiler/src/ast/libast.cc | 44 +++ tiger-compiler/src/ast/libast.hh | 26 ++ tiger-compiler/src/ast/local.am | 30 ++ tiger-compiler/src/ast/location.hh | 14 + tiger-compiler/src/ast/method-call-exp.cc | 24 ++ tiger-compiler/src/ast/method-call-exp.hh | 70 ++++ tiger-compiler/src/ast/method-call-exp.hxx | 21 ++ tiger-compiler/src/ast/method-dec.cc | 22 ++ tiger-compiler/src/ast/method-dec.hh | 45 +++ tiger-compiler/src/ast/method-dec.hxx | 11 + tiger-compiler/src/ast/name-ty.cc | 19 ++ tiger-compiler/src/ast/name-ty.hh | 56 ++++ tiger-compiler/src/ast/name-ty.hxx | 20 ++ tiger-compiler/src/ast/nil-exp.cc | 19 ++ tiger-compiler/src/ast/nil-exp.hh | 37 +++ tiger-compiler/src/ast/nil-exp.hxx | 11 + tiger-compiler/src/ast/non-assert-visitor.hh | 51 +++ tiger-compiler/src/ast/non-assert-visitor.hxx | 34 ++ tiger-compiler/src/ast/non-object-visitor.hh | 92 ++++++ tiger-compiler/src/ast/non-object-visitor.hxx | 62 ++++ tiger-compiler/src/ast/object-exp.cc | 19 ++ tiger-compiler/src/ast/object-exp.hh | 47 +++ tiger-compiler/src/ast/object-exp.hxx | 16 + tiger-compiler/src/ast/object-visitor.hh | 89 ++++++ tiger-compiler/src/ast/object-visitor.hxx | 69 ++++ tiger-compiler/src/ast/op-exp.cc | 42 +++ tiger-compiler/src/ast/op-exp.hh | 80 +++++ tiger-compiler/src/ast/op-exp.hxx | 21 ++ tiger-compiler/src/ast/pretty-printer.cc | 419 ++++++++++++++++++++++++ tiger-compiler/src/ast/pretty-printer.hh | 96 ++++++ tiger-compiler/src/ast/record-exp.cc | 30 ++ tiger-compiler/src/ast/record-exp.hh | 57 ++++ tiger-compiler/src/ast/record-exp.hxx | 22 ++ tiger-compiler/src/ast/record-ty.cc | 26 ++ tiger-compiler/src/ast/record-ty.hh | 49 +++ tiger-compiler/src/ast/record-ty.hxx | 16 + tiger-compiler/src/ast/seq-exp.cc | 26 ++ tiger-compiler/src/ast/seq-exp.hh | 47 +++ tiger-compiler/src/ast/seq-exp.hxx | 16 + tiger-compiler/src/ast/simple-var.cc | 19 ++ tiger-compiler/src/ast/simple-var.hh | 56 ++++ tiger-compiler/src/ast/simple-var.hxx | 20 ++ tiger-compiler/src/ast/string-exp.cc | 19 ++ tiger-compiler/src/ast/string-exp.hh | 47 +++ tiger-compiler/src/ast/string-exp.hxx | 16 + tiger-compiler/src/ast/subscript-var.cc | 26 ++ tiger-compiler/src/ast/subscript-var.hh | 54 ++++ tiger-compiler/src/ast/subscript-var.hxx | 19 ++ tiger-compiler/src/ast/tasks.cc | 32 ++ tiger-compiler/src/ast/tasks.hh | 24 ++ tiger-compiler/src/ast/ty.cc | 17 + tiger-compiler/src/ast/ty.hh | 39 +++ tiger-compiler/src/ast/ty.hxx | 11 + tiger-compiler/src/ast/typable.cc | 15 + tiger-compiler/src/ast/typable.hh | 50 +++ tiger-compiler/src/ast/typable.hxx | 24 ++ tiger-compiler/src/ast/type-constructor.cc | 31 ++ tiger-compiler/src/ast/type-constructor.hh | 38 +++ tiger-compiler/src/ast/type-constructor.hxx | 23 ++ tiger-compiler/src/ast/type-dec.cc | 22 ++ tiger-compiler/src/ast/type-dec.hh | 51 +++ tiger-compiler/src/ast/type-dec.hxx | 16 + tiger-compiler/src/ast/var-dec.cc | 31 ++ tiger-compiler/src/ast/var-dec.hh | 61 ++++ tiger-compiler/src/ast/var-dec.hxx | 19 ++ tiger-compiler/src/ast/var.cc | 15 + tiger-compiler/src/ast/var.hh | 26 ++ tiger-compiler/src/ast/var.hxx | 11 + tiger-compiler/src/ast/visitor.hh | 114 +++++++ tiger-compiler/src/ast/visitor.hxx | 36 +++ tiger-compiler/src/ast/while-exp.cc | 26 ++ tiger-compiler/src/ast/while-exp.hh | 53 ++++ tiger-compiler/src/ast/while-exp.hxx | 19 ++ 151 files changed, 6826 insertions(+) create mode 100644 tiger-compiler/src/ast/README.txt create mode 100644 tiger-compiler/src/ast/all.hh create mode 100644 tiger-compiler/src/ast/array-exp.cc create mode 100644 tiger-compiler/src/ast/array-exp.hh create mode 100644 tiger-compiler/src/ast/array-exp.hxx create mode 100644 tiger-compiler/src/ast/array-ty.cc create mode 100644 tiger-compiler/src/ast/array-ty.hh create mode 100644 tiger-compiler/src/ast/array-ty.hxx create mode 100644 tiger-compiler/src/ast/assert-exp.cc create mode 100644 tiger-compiler/src/ast/assert-exp.hh create mode 100644 tiger-compiler/src/ast/assert-exp.hxx create mode 100644 tiger-compiler/src/ast/assert-visitor.hh create mode 100644 tiger-compiler/src/ast/assert-visitor.hxx create mode 100644 tiger-compiler/src/ast/assign-exp.cc create mode 100644 tiger-compiler/src/ast/assign-exp.hh create mode 100644 tiger-compiler/src/ast/assign-exp.hxx create mode 100644 tiger-compiler/src/ast/ast-nodes.mk create mode 100644 tiger-compiler/src/ast/ast.cc create mode 100644 tiger-compiler/src/ast/ast.hh create mode 100644 tiger-compiler/src/ast/ast.hxx create mode 100644 tiger-compiler/src/ast/break-exp.cc create mode 100644 tiger-compiler/src/ast/break-exp.hh create mode 100644 tiger-compiler/src/ast/break-exp.hxx create mode 100644 tiger-compiler/src/ast/call-exp.cc create mode 100644 tiger-compiler/src/ast/call-exp.hh create mode 100644 tiger-compiler/src/ast/call-exp.hxx create mode 100644 tiger-compiler/src/ast/cast-exp.cc create mode 100644 tiger-compiler/src/ast/cast-exp.hh create mode 100644 tiger-compiler/src/ast/cast-exp.hxx create mode 100644 tiger-compiler/src/ast/chunk-interface.hh create mode 100644 tiger-compiler/src/ast/chunk-interface.hxx create mode 100644 tiger-compiler/src/ast/chunk-list.cc create mode 100644 tiger-compiler/src/ast/chunk-list.hh create mode 100644 tiger-compiler/src/ast/chunk-list.hxx create mode 100644 tiger-compiler/src/ast/chunk.hh create mode 100644 tiger-compiler/src/ast/chunk.hxx create mode 100644 tiger-compiler/src/ast/class-ty.cc create mode 100644 tiger-compiler/src/ast/class-ty.hh create mode 100644 tiger-compiler/src/ast/class-ty.hxx create mode 100644 tiger-compiler/src/ast/dec.cc create mode 100644 tiger-compiler/src/ast/dec.hh create mode 100644 tiger-compiler/src/ast/dec.hxx create mode 100644 tiger-compiler/src/ast/default-visitor.hh create mode 100644 tiger-compiler/src/ast/default-visitor.hxx create mode 100644 tiger-compiler/src/ast/dumper-dot.cc create mode 100644 tiger-compiler/src/ast/dumper-dot.hh create mode 100644 tiger-compiler/src/ast/dumper-dot.hxx create mode 100644 tiger-compiler/src/ast/escapable.cc create mode 100644 tiger-compiler/src/ast/escapable.hh create mode 100644 tiger-compiler/src/ast/escapable.hxx create mode 100644 tiger-compiler/src/ast/exp.cc create mode 100644 tiger-compiler/src/ast/exp.hh create mode 100644 tiger-compiler/src/ast/exp.hxx create mode 100644 tiger-compiler/src/ast/field-init.cc create mode 100644 tiger-compiler/src/ast/field-init.hh create mode 100644 tiger-compiler/src/ast/field-init.hxx create mode 100644 tiger-compiler/src/ast/field-var.cc create mode 100644 tiger-compiler/src/ast/field-var.hh create mode 100644 tiger-compiler/src/ast/field-var.hxx create mode 100644 tiger-compiler/src/ast/field.cc create mode 100644 tiger-compiler/src/ast/field.hh create mode 100644 tiger-compiler/src/ast/field.hxx create mode 100644 tiger-compiler/src/ast/for-exp.cc create mode 100644 tiger-compiler/src/ast/for-exp.hh create mode 100644 tiger-compiler/src/ast/for-exp.hxx create mode 100644 tiger-compiler/src/ast/function-dec.cc create mode 100644 tiger-compiler/src/ast/function-dec.hh create mode 100644 tiger-compiler/src/ast/function-dec.hxx create mode 100644 tiger-compiler/src/ast/fwd.hh create mode 100644 tiger-compiler/src/ast/if-exp.cc create mode 100644 tiger-compiler/src/ast/if-exp.hh create mode 100644 tiger-compiler/src/ast/if-exp.hxx create mode 100644 tiger-compiler/src/ast/int-exp.cc create mode 100644 tiger-compiler/src/ast/int-exp.hh create mode 100644 tiger-compiler/src/ast/int-exp.hxx create mode 100644 tiger-compiler/src/ast/let-exp.cc create mode 100644 tiger-compiler/src/ast/let-exp.hh create mode 100644 tiger-compiler/src/ast/let-exp.hxx create mode 100644 tiger-compiler/src/ast/libast.cc create mode 100644 tiger-compiler/src/ast/libast.hh create mode 100644 tiger-compiler/src/ast/local.am create mode 100644 tiger-compiler/src/ast/location.hh create mode 100644 tiger-compiler/src/ast/method-call-exp.cc create mode 100644 tiger-compiler/src/ast/method-call-exp.hh create mode 100644 tiger-compiler/src/ast/method-call-exp.hxx create mode 100644 tiger-compiler/src/ast/method-dec.cc create mode 100644 tiger-compiler/src/ast/method-dec.hh create mode 100644 tiger-compiler/src/ast/method-dec.hxx create mode 100644 tiger-compiler/src/ast/name-ty.cc create mode 100644 tiger-compiler/src/ast/name-ty.hh create mode 100644 tiger-compiler/src/ast/name-ty.hxx create mode 100644 tiger-compiler/src/ast/nil-exp.cc create mode 100644 tiger-compiler/src/ast/nil-exp.hh create mode 100644 tiger-compiler/src/ast/nil-exp.hxx create mode 100644 tiger-compiler/src/ast/non-assert-visitor.hh create mode 100644 tiger-compiler/src/ast/non-assert-visitor.hxx create mode 100644 tiger-compiler/src/ast/non-object-visitor.hh create mode 100644 tiger-compiler/src/ast/non-object-visitor.hxx create mode 100644 tiger-compiler/src/ast/object-exp.cc create mode 100644 tiger-compiler/src/ast/object-exp.hh create mode 100644 tiger-compiler/src/ast/object-exp.hxx create mode 100644 tiger-compiler/src/ast/object-visitor.hh create mode 100644 tiger-compiler/src/ast/object-visitor.hxx create mode 100644 tiger-compiler/src/ast/op-exp.cc create mode 100644 tiger-compiler/src/ast/op-exp.hh create mode 100644 tiger-compiler/src/ast/op-exp.hxx create mode 100644 tiger-compiler/src/ast/pretty-printer.cc create mode 100644 tiger-compiler/src/ast/pretty-printer.hh create mode 100644 tiger-compiler/src/ast/record-exp.cc create mode 100644 tiger-compiler/src/ast/record-exp.hh create mode 100644 tiger-compiler/src/ast/record-exp.hxx create mode 100644 tiger-compiler/src/ast/record-ty.cc create mode 100644 tiger-compiler/src/ast/record-ty.hh create mode 100644 tiger-compiler/src/ast/record-ty.hxx create mode 100644 tiger-compiler/src/ast/seq-exp.cc create mode 100644 tiger-compiler/src/ast/seq-exp.hh create mode 100644 tiger-compiler/src/ast/seq-exp.hxx create mode 100644 tiger-compiler/src/ast/simple-var.cc create mode 100644 tiger-compiler/src/ast/simple-var.hh create mode 100644 tiger-compiler/src/ast/simple-var.hxx create mode 100644 tiger-compiler/src/ast/string-exp.cc create mode 100644 tiger-compiler/src/ast/string-exp.hh create mode 100644 tiger-compiler/src/ast/string-exp.hxx create mode 100644 tiger-compiler/src/ast/subscript-var.cc create mode 100644 tiger-compiler/src/ast/subscript-var.hh create mode 100644 tiger-compiler/src/ast/subscript-var.hxx create mode 100644 tiger-compiler/src/ast/tasks.cc create mode 100644 tiger-compiler/src/ast/tasks.hh create mode 100644 tiger-compiler/src/ast/ty.cc create mode 100644 tiger-compiler/src/ast/ty.hh create mode 100644 tiger-compiler/src/ast/ty.hxx create mode 100644 tiger-compiler/src/ast/typable.cc create mode 100644 tiger-compiler/src/ast/typable.hh create mode 100644 tiger-compiler/src/ast/typable.hxx create mode 100644 tiger-compiler/src/ast/type-constructor.cc create mode 100644 tiger-compiler/src/ast/type-constructor.hh create mode 100644 tiger-compiler/src/ast/type-constructor.hxx create mode 100644 tiger-compiler/src/ast/type-dec.cc create mode 100644 tiger-compiler/src/ast/type-dec.hh create mode 100644 tiger-compiler/src/ast/type-dec.hxx create mode 100644 tiger-compiler/src/ast/var-dec.cc create mode 100644 tiger-compiler/src/ast/var-dec.hh create mode 100644 tiger-compiler/src/ast/var-dec.hxx create mode 100644 tiger-compiler/src/ast/var.cc create mode 100644 tiger-compiler/src/ast/var.hh create mode 100644 tiger-compiler/src/ast/var.hxx create mode 100644 tiger-compiler/src/ast/visitor.hh create mode 100644 tiger-compiler/src/ast/visitor.hxx create mode 100644 tiger-compiler/src/ast/while-exp.cc create mode 100644 tiger-compiler/src/ast/while-exp.hh create mode 100644 tiger-compiler/src/ast/while-exp.hxx (limited to 'tiger-compiler/src/ast') diff --git a/tiger-compiler/src/ast/README.txt b/tiger-compiler/src/ast/README.txt new file mode 100644 index 0000000..4291b24 --- /dev/null +++ b/tiger-compiler/src/ast/README.txt @@ -0,0 +1,66 @@ +* README + +Tiger Abstract Syntax Tree nodes with their principal members. +Incomplete classes are tagged with a `*'. + +/Ast/ (Location location) + /Dec/ (symbol name) + FunctionDec (VarChunk formals, NameTy result, Exp body) + MethodDec () + TypeDec (Ty ty) + VarDec (NameTy type_name, Exp init) + + /Exp/ () + /Var/ () + FieldVar (Var var, symbol name) + SimpleVar (symbol name) + SubscriptVar (Var var, Exp index) + + ArrayExp (NameTy type_name, Exp size, Exp init) + AssertExp (Exp exp) + AssignExp (Var var, Exp exp) + BreakExp () + CallExp (symbol name, exps_type args) + MethodCallExp (Var object) + CastExp (Exp exp, Ty ty) + ForExp (VarDec vardec, Exp hi, Exp body) + IfExp (Exp test, Exp thenclause, Exp elseclause) + IntExp (int value) + LetExp (ChunkList chunks, Exp body) + NilExp () + ObjectExp (NameTy type_name) + OpExp (Exp left, Oper oper, Exp right) + RecordExp (NameTy type_name, fieldinits_type fields) + SeqExp (exps_type exps) + StringExp (string value) + WhileExp (Exp test, Exp body) + + /Ty/ () + ArrayTy (NameTy base_type) + ClassTy (NameTy super, ChunkList chunks) + NameTy (symbol name) + RecordTy (fields_type fields) + + ChunkList (list_type chunks) + + Field (symbol name, NameTy type_name) + + FieldInit (symbol name, Exp init) + + +Some of these classes also inherit from other classes. + +/Escapable/ + VarDec (NameTy type_name, Exp init) + +/Typable/ + /Dec/ (symbol name) + /Exp/ () + /Ty/ () + +/TypeConstructor/ + /Ty/ () + FunctionDec (VarChunk formals, NameTy result, Exp body) + NilExp () + TypeDec (Ty ty) + diff --git a/tiger-compiler/src/ast/all.hh b/tiger-compiler/src/ast/all.hh new file mode 100644 index 0000000..c55c3eb --- /dev/null +++ b/tiger-compiler/src/ast/all.hh @@ -0,0 +1,51 @@ +/** + ** \file ast/all.hh + ** \brief Include all the exported headers. + */ + +#pragma once + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/tiger-compiler/src/ast/array-exp.cc b/tiger-compiler/src/ast/array-exp.cc new file mode 100644 index 0000000..8c0f241 --- /dev/null +++ b/tiger-compiler/src/ast/array-exp.cc @@ -0,0 +1,31 @@ +/** + ** \file ast/array-exp.cc + ** \brief Implementation of ast::ArrayExp. + */ + +#include +#include + +namespace ast +{ + ArrayExp::ArrayExp(const Location& location, + NameTy* type_name, + Exp* size, + Exp* init) + : Exp(location) + , type_name_(type_name) + , size_(size) + , init_(init) + {} + + ArrayExp::~ArrayExp() + { + delete type_name_; + delete size_; + delete init_; + } + + void ArrayExp::accept(ConstVisitor& v) const { v(*this); } + + void ArrayExp::accept(Visitor& v) { v(*this); } +} // namespace ast diff --git a/tiger-compiler/src/ast/array-exp.hh b/tiger-compiler/src/ast/array-exp.hh new file mode 100644 index 0000000..ceab385 --- /dev/null +++ b/tiger-compiler/src/ast/array-exp.hh @@ -0,0 +1,60 @@ +/** + ** \file ast/array-exp.hh + ** \brief Declaration of ast::ArrayExp. + */ + +#pragma once + +#include +#include + +namespace ast +{ + /// ArrayExp. + class ArrayExp : public Exp + { + public: + /** \name Ctor & dtor. + ** \{ */ + /// Construct an ArrayExp node. + ArrayExp(const Location& location, NameTy* type_name, Exp* size, Exp* init); + ArrayExp(const ArrayExp&) = delete; + ArrayExp& operator=(const ArrayExp&) = delete; + /// Destroy an ArrayExp node. + ~ArrayExp() override; + /** \} */ + + /// \name Visitors entry point. + /// \{ */ + /// Accept a const visitor \a v. + void accept(ConstVisitor& v) const override; + /// Accept a non-const visitor \a v. + void accept(Visitor& v) override; + /// \} + + /** \name Accessors. + ** \{ */ + /// Return identifier of the stored elements type. + const NameTy& type_name_get() const; + /// Return identifier of the stored elements type. + NameTy& type_name_get(); + /// Return size of the array. + const Exp& size_get() const; + /// Return size of the array. + Exp& size_get(); + /// Return initial value assigned to all elements of the array. + const Exp& init_get() const; + /// Return initial value assigned to all elements of the array. + Exp& init_get(); + /** \} */ + + protected: + /// Identifier of the stored elements type. + NameTy* type_name_; + /// Size of the array. + Exp* size_; + /// Initial value assigned to all elements of the array. + Exp* init_; + }; +} // namespace ast +#include diff --git a/tiger-compiler/src/ast/array-exp.hxx b/tiger-compiler/src/ast/array-exp.hxx new file mode 100644 index 0000000..cab3e8b --- /dev/null +++ b/tiger-compiler/src/ast/array-exp.hxx @@ -0,0 +1,22 @@ +/** + ** \file ast/array-exp.hxx + ** \brief Inline methods of ast::ArrayExp. + */ + +#pragma once + +#include + +namespace ast +{ + + inline const NameTy& ArrayExp::type_name_get() const { return *type_name_; } + inline NameTy& ArrayExp::type_name_get() { return *type_name_; } + + inline const Exp& ArrayExp::size_get() const { return *size_; } + inline Exp& ArrayExp::size_get() { return *size_; } + + inline const Exp& ArrayExp::init_get() const { return *init_; } + inline Exp& ArrayExp::init_get() { return *init_; } + +} // namespace ast diff --git a/tiger-compiler/src/ast/array-ty.cc b/tiger-compiler/src/ast/array-ty.cc new file mode 100644 index 0000000..d7af8b4 --- /dev/null +++ b/tiger-compiler/src/ast/array-ty.cc @@ -0,0 +1,21 @@ +/** + ** \file ast/array-ty.cc + ** \brief Implementation of ast::ArrayTy. + */ + +#include +#include + +namespace ast +{ + ArrayTy::ArrayTy(const Location& location, NameTy* base_type) + : Ty(location) + , base_type_(base_type) + {} + + ArrayTy::~ArrayTy() { delete base_type_; } + + void ArrayTy::accept(ConstVisitor& v) const { v(*this); } + + void ArrayTy::accept(Visitor& v) { v(*this); } +} // namespace ast diff --git a/tiger-compiler/src/ast/array-ty.hh b/tiger-compiler/src/ast/array-ty.hh new file mode 100644 index 0000000..73bb956 --- /dev/null +++ b/tiger-compiler/src/ast/array-ty.hh @@ -0,0 +1,48 @@ +/** + ** \file ast/array-ty.hh + ** \brief Declaration of ast::ArrayTy. + */ + +#pragma once + +#include +#include + +namespace ast +{ + /// ArrayTy. + class ArrayTy : public Ty + { + public: + /** \name Ctor & dtor. + ** \{ */ + /// Construct an ArrayTy node. + ArrayTy(const Location& location, NameTy* base_type); + ArrayTy(const ArrayTy&) = delete; + ArrayTy& operator=(const ArrayTy&) = delete; + /// Destroy an ArrayTy node. + ~ArrayTy() override; + /** \} */ + + /// \name Visitors entry point. + /// \{ */ + /// Accept a const visitor \a v. + void accept(ConstVisitor& v) const override; + /// Accept a non-const visitor \a v. + void accept(Visitor& v) override; + /// \} + + /** \name Accessors. + ** \{ */ + /// Return name of the base type. + const NameTy& base_type_get() const; + /// Return name of the base type. + NameTy& base_type_get(); + /** \} */ + + protected: + /// Name of the base type. + NameTy* base_type_; + }; +} // namespace ast +#include diff --git a/tiger-compiler/src/ast/array-ty.hxx b/tiger-compiler/src/ast/array-ty.hxx new file mode 100644 index 0000000..c679b1c --- /dev/null +++ b/tiger-compiler/src/ast/array-ty.hxx @@ -0,0 +1,16 @@ +/** + ** \file ast/array-ty.hxx + ** \brief Inline methods of ast::ArrayTy. + */ + +#pragma once + +#include + +namespace ast +{ + + inline const NameTy& ArrayTy::base_type_get() const { return *base_type_; } + inline NameTy& ArrayTy::base_type_get() { return *base_type_; } + +} // namespace ast diff --git a/tiger-compiler/src/ast/assert-exp.cc b/tiger-compiler/src/ast/assert-exp.cc new file mode 100644 index 0000000..251f776 --- /dev/null +++ b/tiger-compiler/src/ast/assert-exp.cc @@ -0,0 +1,24 @@ +/** + ** \file ast/assert-exp.cc + ** \brief Implementation of ast::AssertExp. + */ + +#include +#include + +namespace ast +{ + AssertExp::AssertExp(const Location& location, Exp* condition) + : Exp(location) + , cond_{condition} + {} + + AssertExp::~AssertExp() + { + delete cond_; + } + + void AssertExp::accept(ConstVisitor& v) const { v(*this); } + + void AssertExp::accept(Visitor& v) { v(*this); } +} // namespace ast diff --git a/tiger-compiler/src/ast/assert-exp.hh b/tiger-compiler/src/ast/assert-exp.hh new file mode 100644 index 0000000..6650ca4 --- /dev/null +++ b/tiger-compiler/src/ast/assert-exp.hh @@ -0,0 +1,42 @@ +/** + ** \file ast/assert-exp.hh + ** \brief Declaration of ast::AssertExp. + */ + +#pragma once + +#include + +namespace ast +{ + // AssertExp + class AssertExp : public Exp + { + public: + /// Construct an AssertExp node. + AssertExp(const Location& location, Exp* cond); + AssertExp(const AssertExp&) = delete; + AssertExp& operator=(const AssertExp&) = delete; + + /// Destroy an AssertExp node. + ~AssertExp() override; + + + // Here are the visitor methods + /// Accept a const visitor \a v. + void accept(ConstVisitor& v) const override; + /// Accept a non-const visitor \a v. + void accept(Visitor& v) override; + + // Some basic getters + // Return the asserted condition in const form + const Exp& cond_get() const; + // Return the asserted condition + Exp& cond_get(); + + protected: + // The condition that the assertion will evaluate + Exp* cond_; + }; +} // namespace ast +#include diff --git a/tiger-compiler/src/ast/assert-exp.hxx b/tiger-compiler/src/ast/assert-exp.hxx new file mode 100644 index 0000000..d5f8af8 --- /dev/null +++ b/tiger-compiler/src/ast/assert-exp.hxx @@ -0,0 +1,14 @@ +/** + ** \file ast/assert-exp.hxx + ** \brief Inline methods of ast::AssertExp. + */ + +#pragma once + +#include + +namespace ast +{ + inline const Exp& AssertExp::cond_get() const { return *cond_; } + inline Exp& AssertExp::cond_get() { return *cond_; } +} // namespace ast diff --git a/tiger-compiler/src/ast/assert-visitor.hh b/tiger-compiler/src/ast/assert-visitor.hh new file mode 100644 index 0000000..0488c1c --- /dev/null +++ b/tiger-compiler/src/ast/assert-visitor.hh @@ -0,0 +1,51 @@ +/** + ** \file ast/object-visitor.hh + ** \brief Provide default visits for assertion nodes. + */ + +#pragma once + +#include + +namespace ast +{ + template