I'm pretty sure I missed cases and introduced bugs with the new CGenerator triplit system, but I finally got all normal tests passing, and it's almost 5 in the morning, so I'm calling it a night. We have destructors and copy constructors now\! I need to work out copy assignment, but again, another day
This commit is contained in:
25
include/CCodeTriple.h
Normal file
25
include/CCodeTriple.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef CCODETRIPLE_H
|
||||
#define CCODETRIPLE_H
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include "util.h"
|
||||
|
||||
class CCodeTriple {
|
||||
public:
|
||||
CCodeTriple(std::string pre, std::string val, std::string post);
|
||||
CCodeTriple(std::string val);
|
||||
CCodeTriple(const char* val);
|
||||
CCodeTriple();
|
||||
~CCodeTriple();
|
||||
std::string oneString();
|
||||
CCodeTriple & operator=(const CCodeTriple &rhs);
|
||||
CCodeTriple & operator+=(const CCodeTriple &rhs);
|
||||
|
||||
std::string preValue;
|
||||
std::string value;
|
||||
std::string postValue;
|
||||
private:
|
||||
};
|
||||
CCodeTriple operator+(const CCodeTriple &a, const CCodeTriple &b);
|
||||
#endif //CCODETRIPLE_H
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <stack>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "CCodeTriple.h"
|
||||
#include "NodeTree.h"
|
||||
#include "ASTData.h"
|
||||
#include "Type.h"
|
||||
@@ -26,7 +27,7 @@ class CGenerator {
|
||||
bool isUnderTranslationUnit(NodeTree<ASTData>* from, NodeTree<ASTData>* typeDefinition);
|
||||
NodeTree<ASTData>* highestScope(NodeTree<ASTData>* node);
|
||||
std::pair<std::string, std::string> generateTranslationUnit(std::string name, std::map<std::string, NodeTree<ASTData>*> ASTs);
|
||||
std::string generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enclosingObject = NULL, bool justFuncName = false);
|
||||
CCodeTriple generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enclosingObject = NULL, bool justFuncName = false);
|
||||
std::string generateAliasChains(std::map<std::string, NodeTree<ASTData>*> ASTs, NodeTree<ASTData>* definition);
|
||||
std::string ValueTypeToCType(Type *type, std::string);
|
||||
std::string ValueTypeToCTypeDecoration(Type *type);
|
||||
@@ -35,12 +36,20 @@ class CGenerator {
|
||||
static std::string scopePrefix(NodeTree<ASTData>* from);
|
||||
std::string generateObjectMethod(NodeTree<ASTData>* enclosingObject, NodeTree<ASTData>* from, std::string *functionPrototype);
|
||||
NodeTree<ASTData>* getMethodsObjectType(NodeTree<ASTData>* scope, std::string functionName);
|
||||
NodeTree<ASTData>* getMethod(Type* type, std::string method);
|
||||
bool methodExists(Type* type, std::string method);
|
||||
std::string generateMethodIfExists(Type* type, std::string method, std::string parameter);
|
||||
std::string emitDestructors(std::vector<NodeTree<ASTData>*> possibleDeclarations, NodeTree<ASTData>* enclosingObject);
|
||||
std::string tabs();
|
||||
std::string getID();
|
||||
|
||||
int tabLevel;
|
||||
int id;
|
||||
std::string generatorString;
|
||||
std::string linkerString;
|
||||
std::string functionTypedefString;
|
||||
std::vector<std::vector<NodeTree<ASTData>*>> distructDoubleStack;
|
||||
std::stack<int> loopDistructStackDepth;
|
||||
std::vector<std::vector<NodeTree<ASTData>*>> deferDoubleStack;
|
||||
std::stack<int> loopDeferStackDepth;
|
||||
private:
|
||||
|
||||
@@ -31,6 +31,21 @@ bool contains(std::vector<T> vec, T item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::vector<T> flatten(std::vector<std::vector<T>> vec) {
|
||||
std::vector<T> flat;
|
||||
for (auto i : vec)
|
||||
flat.insert(flat.end(), i.begin(), i.end());
|
||||
return flat;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::vector<T> reverse(std::vector<T> vec) {
|
||||
std::vector<T> flat;
|
||||
flat.insert(flat.end(), vec.rbegin(), vec.rend());
|
||||
return flat;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::vector<T> slice(std::vector<T> vec, int begin, int end, int step = 1) {
|
||||
std::vector<T> toReturn;
|
||||
|
||||
Reference in New Issue
Block a user