Commit 6138a3ff authored by Gregory Casamento's avatar Gregory Casamento
Browse files

Add transform skeleton for AST.

parent 2b0b2687
......@@ -79,6 +79,7 @@
1460D58A1A017757009D1EE9 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 1460D5891A017757009D1EE9 /* main.m */; };
14BECB8C1A4C8DA000C0522A /* ObjCASTTransform.m in Sources */ = {isa = PBXBuildFile; fileRef = 14BECB8B1A4C8DA000C0522A /* ObjCASTTransform.m */; };
14BECB901A4C8E0000C0522A /* Compiler.m in Sources */ = {isa = PBXBuildFile; fileRef = 14BECB8F1A4C8E0000C0522A /* Compiler.m */; };
14BECB931A4C9BD700C0522A /* ASTTransform.m in Sources */ = {isa = PBXBuildFile; fileRef = 14BECB921A4C9BD700C0522A /* ASTTransform.m */; };
14C83C9E1A29809400A10D94 /* Lexer.m in Sources */ = {isa = PBXBuildFile; fileRef = 14C83C931A29809400A10D94 /* Lexer.m */; };
14C83C9F1A29809400A10D94 /* Regex.m in Sources */ = {isa = PBXBuildFile; fileRef = 14C83C951A29809400A10D94 /* Regex.m */; };
/* End PBXBuildFile section */
......@@ -246,6 +247,8 @@
14BECB8B1A4C8DA000C0522A /* ObjCASTTransform.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ObjCASTTransform.m; sourceTree = "<group>"; };
14BECB8E1A4C8E0000C0522A /* Compiler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Compiler.h; sourceTree = "<group>"; };
14BECB8F1A4C8E0000C0522A /* Compiler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Compiler.m; sourceTree = "<group>"; };
14BECB911A4C9BD700C0522A /* ASTTransform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASTTransform.h; sourceTree = "<group>"; };
14BECB921A4C9BD700C0522A /* ASTTransform.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASTTransform.m; sourceTree = "<group>"; };
14C83C861A29809400A10D94 /* AST.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AST.h; sourceTree = "<group>"; };
14C83C921A29809400A10D94 /* Lexer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Lexer.h; sourceTree = "<group>"; };
14C83C931A29809400A10D94 /* Lexer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Lexer.m; sourceTree = "<group>"; };
......@@ -420,6 +423,8 @@
isa = PBXGroup;
children = (
14BECB891A4C8DA000C0522A /* ObjC */,
14BECB911A4C9BD700C0522A /* ASTTransform.h */,
14BECB921A4C9BD700C0522A /* ASTTransform.m */,
);
path = Transform;
sourceTree = "<group>";
......@@ -631,6 +636,7 @@
143C35441A38A52F004DBA61 /* ObjCTernaryOperator.m in Sources */,
143C353D1A38A52F004DBA61 /* ObjCOptionalChainExprStatement.m in Sources */,
143C34AA1A34051C004DBA61 /* ASTNode.m in Sources */,
14BECB931A4C9BD700C0522A /* ASTTransform.m in Sources */,
143C34BE1A34051C004DBA61 /* PostfixOperator.m in Sources */,
143C34B41A34051C004DBA61 /* FunctionParameter.m in Sources */,
143C352B1A38A52F004DBA61 /* ObjCAssignmentOperator.m in Sources */,
......
......@@ -8,10 +8,13 @@
#import <Foundation/Foundation.h>
#import "AST.h"
#import "ObjCASTTransform.h"
@interface Compiler : NSObject
{
ASTNode *rootNode;
ASTNode *transformed;
ASTTransform *transform;
NSString *sourceCode;
NSString *errors;
NSString *prefix;
......
......@@ -62,7 +62,10 @@
rootNode = (ASTNode *)bridge_yyparse(lexer, debug);
if(rootNode != nil)
{
NSString *program = [rootNode toCode];
transform = [ASTTransform createWithAST:rootNode
forPrefix:prefix];
transformed = [transform transform];
NSString *program = [transformed toCode];
NSString *error = nil;
const char *errstr = bridge_yyerror();
......
//
// ASTTransform.h
// phoenix
//
// Created by Gregory Casamento on 12/25/14.
// Copyright (c) 2014 indie. All rights reserved.
//
#import <Foundation/Foundation.h>
@class ASTNode;
@interface ASTTransform : NSObject
{
ASTNode *originalTree;
ASTNode *resultantTree;
}
+ (ASTTransform *)createWithAST: (ASTNode *)node
forPrefix: (NSString *)prefix;
- (id) initWithAST: (ASTNode *)tree;
- (ASTNode *)resultantTree;
- (ASTNode *)transform;
@end
//
// ASTTransform.m
// phoenix
//
// Created by Gregory Casamento on 12/25/14.
// Copyright (c) 2014 indie. All rights reserved.
//
#import "ASTTransform.h"
#import "ASTNode.h"
@implementation ASTTransform
+ (ASTTransform *)createWithAST: (ASTNode *)node
forPrefix: (NSString *)prefix
{
NSString *className = [prefix stringByAppendingString:@"ASTTransform"];
Class clz = NSClassFromString(className);
ASTTransform *transform = [[clz alloc] initWithAST:node];
return transform;
}
- (id)initWithAST:(ASTNode *)tree
{
self = [super init];
if(self)
{
originalTree = tree;
[originalTree retain];
}
return self;
}
- (ASTNode *)resultantTree
{
return resultantTree;
}
- (ASTNode *) transform
{
resultantTree = originalTree;
[resultantTree retain];
return resultantTree;
}
@end
......@@ -7,7 +7,8 @@
//
#import <Foundation/Foundation.h>
#import "ASTTransform.h"
@interface ObjCASTTransform : NSObject
@interface ObjCASTTransform : ASTTransform
@end
......@@ -10,6 +10,4 @@
@implementation ObjCASTTransform
@end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment