Added Type class, bettered types a bit, made address of and dereference operators work.

This commit is contained in:
Nathan Braswell
2013-12-23 01:26:24 -06:00
parent 935cc6f968
commit 15674fec2a
10 changed files with 207 additions and 106 deletions

View File

@@ -3,7 +3,9 @@
#include <vector>
#include <set>
#include "Symbol.h"
#include "Type.h"
#ifndef NULL
#define NULL 0
@@ -14,21 +16,17 @@ enum ASTType {undef, translation_unit, interpreter_directive, import, identifier
typed_parameter, expression, boolean_expression, statement,
if_statement, while_loop, for_loop, return_statement, assignment_statement, declaration_statement,
if_comp, simple_passthrough, function_call, value};
enum ValueType {none, void_type, boolean, integer, floating, double_percision, char_string };
class ASTData {
public:
ASTData();
ASTData(ASTType type, ValueType valueType = none);
ASTData(ASTType type, Symbol symbol, ValueType valueType = none);
ASTData(ASTType type, Type valueType = Type());
ASTData(ASTType type, Symbol symbol, Type valueType = Type());
~ASTData();
std::string toString();
static std::string ASTTypeToString(ASTType type);
static std::string ValueTypeToString(ValueType type);
static ValueType strToType(std::string type);
ASTType type;
ValueType valueType;
Type valueType;
Symbol symbol;
private:

View File

@@ -6,6 +6,7 @@
#include "NodeTree.h"
#include "ASTData.h"
#include "Type.h"
#include "util.h"
@@ -15,7 +16,7 @@ class CGenerator {
CGenerator();
~CGenerator();
std::string generate(NodeTree<ASTData>* from);
static std::string ValueTypeToCType(ValueType type);
static std::string ValueTypeToCType(Type type);
std::string generatorString;
private:
std::string tabs();

29
include/Type.h Normal file
View File

@@ -0,0 +1,29 @@
#ifndef TYPE_H
#define TYPE_H
#ifndef NULL
#define NULL 0
#endif
#include <string>
#include <iostream>
#include "util.h"
enum ValueType {none, void_type, boolean, integer, floating, double_percision, character };
class Type {
public:
Type();
Type(ValueType typeIn, int indirectionIn);
Type(ValueType typeIn);
Type(std::string typeIn);
~Type();
std::string toString();
ValueType baseType;
int indirection;
private:
};
#endif