File: OOJSExprNode%2BGraphviz.m

package info (click to toggle)
oolite 1.77.1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 41,264 kB
  • ctags: 5,362
  • sloc: objc: 132,090; ansic: 10,457; python: 2,225; sh: 1,325; makefile: 332; perl: 259; xml: 125; php: 5
file content (198 lines) | stat: -rw-r--r-- 6,225 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//
//  OOJSExprNode+Graphviz.m
//  ScriptConverter
//
//  Created by Jens Ayton on 2009-03-13.
//  Copyright 2009 Jens Ayton. All rights reserved.
//

#import "OOJSExprNode+Graphviz.h"
#import "OOLogging.h"
#import "TestRigHelpers.h"	// FIXME


@interface OOJSExprNode (GraphvizInternal)

- (void) appendGraphVizRepresentation:(NSMutableString *)graphviz andGetNodeName:(NSString **)name;

@end


@implementation OOJSExprNode (Graphviz)

- (NSString *) graphvizRepresentation
{
	NSMutableString *graphviz = [NSMutableString stringWithString:@"digraph jsexpr\n{\n\tgraph [charset=\"UTF-8\"];\n\tnode[shape=record];\n\t\n"];
	NSString *name = nil;
	
	[self appendGraphVizRepresentation:graphviz andGetNodeName:&name];
	
	[graphviz appendString:@"}\n"];
	return [[graphviz copy] autorelease];
}


- (void) appendGraphVizRepresentation:(NSMutableString *)graphviz andGetNodeName:(NSString **)name
{
	OOLogGenericSubclassResponsibility();
}

@end


@implementation OOJSIntLiteralExprNode (GraphvizInternal)

- (void) appendGraphVizRepresentation:(NSMutableString *)graphviz andGetNodeName:(NSString **)name
{
	*name = [NSString stringWithFormat:@"int_%p", self];
	[graphviz appendFormat:@"\t%@ [label=\"%lli\"];\n", *name, (long long)[self int64Value]];
}

@end


@implementation OOJSDoubleLiteralExprNode (GraphvizInternal)

- (void) appendGraphVizRepresentation:(NSMutableString *)graphviz andGetNodeName:(NSString **)name
{
	*name = [NSString stringWithFormat:@"double_%p", self];
	[graphviz appendFormat:@"\t%@ [label=\"%g\"];\n", *name, [self doubleValue]];
}

@end


@implementation OOJSBoolLiteralExprNode (GraphvizInternal)

- (void) appendGraphVizRepresentation:(NSMutableString *)graphviz andGetNodeName:(NSString **)name
{
	*name = [self boolValue] ? @"true" : @"false";
	[graphviz appendFormat:@"\t%@;\n", *name];
}

@end


@implementation OOJSStringLiteralExprNode (GraphvizInternal)

- (void) appendGraphVizRepresentation:(NSMutableString *)graphviz andGetNodeName:(NSString **)name
{
	*name = [NSString stringWithFormat:@"string_%p", self];
	[graphviz appendFormat:@"\t%@ [label=\"\\\"%@\\\"\"];\n", *name, [[self escapedStringValue] escapedForJavaScriptLiteral]];
}

@end


@implementation OOJSIdentifierExprNode (GraphvizInternal)

- (void) appendGraphVizRepresentation:(NSMutableString *)graphviz andGetNodeName:(NSString **)name
{
	*name = [NSString stringWithFormat:@"id_%p", self];
	[graphviz appendFormat:@"\t%@ [label=\"%@\"];\n", *name, [[self identifier] escapedForJavaScriptLiteral]];
}

@end


@implementation OOJSUnaryOperatorExprNode (GraphvizInternal)

- (void) appendGraphVizRepresentation:(NSMutableString *)graphviz andGetNodeName:(NSString **)name
{
	*name = [NSString stringWithFormat:@"unary_%p", self];
	[graphviz appendFormat:@"\t%@ [label=\"%@\"];\n", *name, [[self operatorToken] escapedForJavaScriptLiteral]];
	
	NSString *subName = nil;
	[[self subExpression] appendGraphVizRepresentation:graphviz andGetNodeName:&subName];
	[graphviz appendFormat:@"\t%@ -> %@;\n", *name, subName];
}

@end


@implementation OOJSBinaryOperatorExprNode (GraphvizInternal)

- (void) appendGraphVizRepresentation:(NSMutableString *)graphviz andGetNodeName:(NSString **)name
{
	*name = [NSString stringWithFormat:@"binary_%p", self];
	[graphviz appendFormat:@"\t%@ [label=\"<left>|<op>%@|<right>\"];\n", *name, [[self operatorToken] escapedForJavaScriptLiteral]];
	
	NSString *lhsName = nil;
	NSString *rhsName = nil;
	[[self leftHandSideExpression] appendGraphVizRepresentation:graphviz andGetNodeName:&lhsName];
	[[self rightHandSideExpression] appendGraphVizRepresentation:graphviz andGetNodeName:&rhsName];
	[graphviz appendFormat:@"\t%@:left -> %@;\n", *name, lhsName];
	[graphviz appendFormat:@"\t%@:right -> %@;\n", *name, rhsName];
}

@end


@implementation OOJSPropertyAccessExprNode (GraphvizInternal)

- (void) appendGraphVizRepresentation:(NSMutableString *)graphviz andGetNodeName:(NSString **)name
{
	*name = [NSString stringWithFormat:@"prop_%p", self];
	[graphviz appendFormat:@"\t%@ [label=\"<obj>|<op>[]|<prop>\"];\n", *name];
	
	NSString *objName = nil;
	NSString *propName = nil;
	[[self objectExpression] appendGraphVizRepresentation:graphviz andGetNodeName:&objName];
	[[self propertyExpression] appendGraphVizRepresentation:graphviz andGetNodeName:&propName];
	[graphviz appendFormat:@"\t%@:obj -> %@;\n", *name, objName];
	[graphviz appendFormat:@"\t%@:prop -> %@;\n", *name, propName];
}

@end


@implementation OOJSFunctionCallExprNode (GraphvizInternal)

- (void) appendGraphVizRepresentation:(NSMutableString *)graphviz andGetNodeName:(NSString **)name
{
	NSArray				*arguments = [self arguments];
	unsigned			i, count = [arguments count];
	
	*name = [NSString stringWithFormat:@"call_%p", self];
	
	[graphviz appendFormat:@"\t%@ [label=\"<func>|<op>call()", *name];
	for (i = 0; i < count; i++)
	{
		[graphviz appendFormat:@"|<arg%u>", i];
	}
	[graphviz appendString:@"\"]\n"];
	
	NSString *funcName = nil;
	[[self functionExpression] appendGraphVizRepresentation:graphviz andGetNodeName:&funcName];
	[graphviz appendFormat:@"\t%@:func -> %@;\n", *name, funcName];
	
	NSString *propName = nil;
	for (i = 0; i < count; i++)
	{
		[[arguments objectAtIndex:i] appendGraphVizRepresentation:graphviz andGetNodeName:&propName];
		[graphviz appendFormat:@"\t%@:arg%u -> %@;\n", *name, i, propName];
	}
}

@end


@implementation OOJSConditionalExprNode (GraphvizInternal)

- (void) appendGraphVizRepresentation:(NSMutableString *)graphviz andGetNodeName:(NSString **)name
{
	*name = [NSString stringWithFormat:@"cond_%p", self];
	[graphviz appendFormat:@"\t%@ [label=\"<condition>|<op>?:|<true>|<false>\"];\n", *name];
	
	NSString *condName = nil;
	NSString *trueName = nil;
	NSString *falseName = nil;
	[[self conditionExpression] appendGraphVizRepresentation:graphviz andGetNodeName:&condName];
	[[self trueExpression] appendGraphVizRepresentation:graphviz andGetNodeName:&trueName];
	[[self falseExpression] appendGraphVizRepresentation:graphviz andGetNodeName:&falseName];
	[graphviz appendFormat:@"\t%@:condition -> %@;\n", *name, condName];
	[graphviz appendFormat:@"\t%@:true -> %@;\n", *name, trueName];
	[graphviz appendFormat:@"\t%@:false -> %@;\n", *name, falseName];
}

@end