-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcppfront.mm
More file actions
62 lines (47 loc) · 2.39 KB
/
cppfront.mm
File metadata and controls
62 lines (47 loc) · 2.39 KB
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
// Copyright (c) Herb Sutter
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//===========================================================================
// cppfront
//===========================================================================
#include "cppfront.h"
#include "cppfront_impl.h"
#import <XCTest/XCTest.h>
//===========================================================================
// main - driver
//===========================================================================
void cppfront(NSString* input, NSString* output, BOOL pure, BOOL failure)
{
std::cout << "Processing " << [[input lastPathComponent] UTF8String] << " ...";
// Make a copy of the output, since it gets over written by lower_to_cpp1()
NSString* expectedOutput = [NSString stringWithContentsOfFile:output
encoding:NSUTF8StringEncoding
error:NULL];
if (!failure)
XCTAssert([expectedOutput length] != 0, @"Failed on %@", [output lastPathComponent]);
// Load + lex + parse + sema
cpp2::cppfront c([input UTF8String]);
// Generate Cpp1 (this may catch additional late errors)
c.lower_to_cpp1();
if (!failure)
XCTAssert(c.had_no_errors(), @"Failed on %@", [input lastPathComponent]);
else
{
XCTAssert(!c.had_no_errors(), @"Failed on %@", [input lastPathComponent]);
}
// Read-in the final output, to compare later on
NSString* outputAsCpp = [NSString stringWithContentsOfFile:output
encoding:NSUTF8StringEncoding
error:NULL];
if (!failure)
{
XCTAssert([outputAsCpp length] != 0, @"Failed on %@", [output lastPathComponent]);
XCTAssertEqualObjects(expectedOutput, outputAsCpp, @"Failed on %@", [input lastPathComponent]);
}
}