Source

Silver / Classes / Core / SVNode.h

Full commit
//
//  SVNode.h
//  SV
//
//  Created by Michael Tindal on 6/4/10.
//  Copyright 2010 Michael Tindal. All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 3 of
// the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

@interface NSObject (SVevaluateWithContext)

- (id) evaluateNode;

- (id) evaluateWithContext:(NSMutableDictionary *)context;

- (NSString *) stringValue;

@end

#define SV_BOX_KEY @"_SvBoxFunc"
#define SV_UNBOX_KEY @"_SvUnboxFunc"
#define SV_ABI_KEY @"_SvAbiFunc"

@interface SVNode : NSObject <NSCopying> {
    NSString * source_;
    NSString * comments_; // Comments attached to the source
}

+ (SVNode *)createNodeFromFile:(NSString *)path;

+ (SVNode *)createNodeFromSource:(NSString *)source;

+ (SVNode *)node;

- (id) evaluateNode;

- (id) evaluateWithContext:(NSMutableDictionary *)context;

- (NSComparisonResult) compare:(SVNode *)node;

- (NSString *) stringValueWithDepth:(NSInteger)d;

@property (copy) NSString * source, * comments;
@end

@interface SVContextGrab : SVNode

@end

@interface SVNoEvalNode : SVNode {
    NSString* identifier_;
}

+ (SVNoEvalNode *) noEvalNodeWithIdentifier:(NSString *)identifier;

- (id) initWithIdentifier:(NSString *)identifier;

@property (copy) NSString * identifier;
@end

#define SV_PARENT_CONTEXT_KEY @"_SVParentContext"
#define __sv_nil (SVNode *)[NSNull null]
#ifndef N
#define N(n) [NSNumber numberWithFloat : n]
#endif
#ifndef BL
#define BL(n) [NSNumber numberWithBool : n]
#endif
#define V_(v) [v isKindOfClass:[SVVariable class]] ? [v varName] : nil
#define R_(l,v,r) SVInstanceRef * ref = [SVInstanceRef refWithLValue:l key:v]
#define A_(r) [SVFunctionArgument argumentWithName:nil value:r]
#define Y_(o) [NSArray arrayWithObject:o]
#define F_(n,f,a) SVFunction * n = [SVFunction functionCallWithName:f arguments:a]
#define Z_(a) [[a objectAtIndex:0] value]
#define L_(a) [[[a objectAtIndex:0] value] lvalue]
#define O_(l,r,v,m) R_(l,v,ref); F_(func,ref,Y_(A_(r))); m = CFRetain(func);
#define O(l,r,v,m) R_(l,v,ref); F_(func,ref,Y_(A_(r))); m = func;
#define N_(l,r,v,m) R_(l,v,ref); F_(func,ref,Y_(A_(r))); m = CFRetain([[SVLogicalNotOperator alloc] initWithOperand:func]);
#define U_(l,v,m) R_(l,v,ref); F_(func,ref,nil); m = CFRetain(func);
#define XS(n) [[SVSymbolTable sharedTable] symbolWithName:n]
#define C_(n) [CGKConstant getFPConstant:n]
#define B_(n) [CGKConstant getBoolConstant:n]
#define CP_(n) [CGKConstant getPtrConstant:n ofType:[CGKType idType]]

NSString * generateDepth(NSInteger depth);

NSInteger depthLength(NSInteger d);

NSString * NormalizedClassNameFor(Class c);

NSString * NormalizedProtocolNameFor(Protocol* p);