#pragma once /////////////////////////////////////////////////////////////////////// // MT1Q1a.cpp - Node for AST // // // // Jim Fawcett, CSE687 - Object Oriented Design, Midterm Spring 2016 // /////////////////////////////////////////////////////////////////////// #include #include #include #include #include "ScopeStack.h" /* * class needs to: * - hold all the properties needed for code analysis * - provide a way to access and modify the properties * - provide support for building AST */ class ASTNode { public: using iterator = std::vector::iterator; using Name = std::string; using Type = std::string; using Line = size_t; iterator begin(); iterator end(); ASTNode(); ASTNode::ASTNode(const Type& type, const Name& name, Line start, Line end=0); Name& name(); Type& type(); Line& startLine(); Line& endLine(); void addChild(ASTNode* node); std::vector children() { return _children; } ASTNode* operator[](size_t n); const ASTNode* operator[](size_t n) const; void clear(); size_t size(); void makeChildAndPush(ScopeStack& ss); static void AddLineCountAndPop(ScopeStack& ss, size_t linecount); private: std::vector _children; Name _name; Type _type; Line _startLine; Line _endLine; };