X-Git-Url: https://gitweb.ps.run/toc/blobdiff_plain/c2ba7425955ae538e220cec79d9124756d1b4c8b..66a27d2fc7c1ad4e97de76d4982168a0fed9920a:/src/repr.h diff --git a/src/repr.h b/src/repr.h index f12b0da..569411c 100644 --- a/src/repr.h +++ b/src/repr.h @@ -8,6 +8,8 @@ using namespace std; +// This contains a 1 to 1 representation of the defined language + struct Type; struct Variable; struct Body; @@ -37,10 +39,17 @@ struct AssignStmt; struct ReturnStmt; struct Stmt; +// Context is a collection of everything that can be defined in a namespace +// that is reused for bodies so that the hierarchy can be walked uniformly +// both up and down using the parent variable struct Context { + std::optional name; std::shared_ptr parent; std::vector variables; + std::vector functions; + std::vector structs; + std::vector namespaces; }; enum class TypeModifierType @@ -61,6 +70,22 @@ struct Type std::vector namespacePrefixes; std::string name; std::vector modifiers; + std::vector genericInstantiation; + + bool operator!=(const Type & that) + { + if (this->name != that.name) + return true; + + for (int i = 0; i < this->modifiers.size(); i++) + if (this->modifiers[i].type != that.modifiers[i].type) + return true; + + for (int i = 0; i < this->namespacePrefixes.size(); i++) + if (this->namespacePrefixes[i] != that.namespacePrefixes[i]) + return true; + return false; + } }; struct Variable @@ -77,10 +102,14 @@ struct Body struct Function { - Type returnType; std::string name; + Type returnType; std::vector parameters; bool defined; + + std::vector genericTypeNames; + std::vector> genericInstantiations; + Body body; }; @@ -95,6 +124,8 @@ struct StructMember struct Struct { std::string name; + std::vector genericTypeNames; + std::vector> genericInstantiations; std::vector> members; std::vector> methods; }; @@ -103,17 +134,11 @@ struct Namespace { std::string name; std::shared_ptr ctx; - std::vector structs; - std::vector functions; - std::vector namespaces; }; struct Program { std::shared_ptr ctx; - std::vector structs; - std::vector functions; - std::vector namespaces; }; enum class ExprType @@ -126,6 +151,7 @@ struct FuncExpr std::vector namespacePrefixes; std::string functionName; std::vector arguments; + std::vector genericInstantiation; }; struct MethodExpr @@ -133,6 +159,7 @@ struct MethodExpr std::shared_ptr expr; std::string methodName; std::vector arguments; + std::vector genericInstantiation; }; enum class LitType @@ -157,10 +184,13 @@ struct ParenExpr struct DotExpr { + bool isPointer; std::shared_ptr expr; std::string identifier; }; +// OperatorType enum with corresponding string array to lookup +// enum from string and the other way round enum class PrefixOperatorType { Plus, Minus, Increment, Decrement,