source: src/Parser/RunParser.cpp @ 8463136

ast-experimental
Last change on this file since 8463136 was c468150, checked in by Andrew Beach <ajbeach@…>, 19 months ago

Split up ParseNode?.h so that headers match implementation. May have a bit less to include total because of it.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2018 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// RunParser.cpp -- External interface to the parser.
8//
9// Author           : Andrew Beach
10// Created On       : Mon Dec 19 11:00:00 2022
11// Last Modified By : Andrew Beach
12// Last Modified On : Mon Mar  6  9:42:00 2023
13// Update Count     : 3
14//
15
16#include "RunParser.hpp"
17
18#include "AST/Convert.hpp"                  // for convert
19#include "AST/TranslationUnit.hpp"          // for TranslationUnit
20#include "CodeTools/TrackLoc.h"             // for fillLocations
21#include "Common/CodeLocationTools.hpp"     // for forceFillCodeLocations
22#include "Parser/DeclarationNode.h"         // for DeclarationNode, buildList
23#include "Parser/TypedefTable.h"            // for TypedefTable
24
25// Variables global to the parsing code.
26ast::Linkage::Spec linkage = ast::Linkage::Cforall;
27TypedefTable typedefTable;
28DeclarationNode * parseTree = nullptr;
29
30void parse( FILE * input, ast::Linkage::Spec linkage, bool alwaysExit ) {
31        extern int yyparse( void );
32        extern FILE * yyin;
33        extern int yylineno;
34
35        // Set global information.
36        ::linkage = linkage;
37        yyin = input;
38        yylineno = 1;
39
40        int parseStatus = yyparse();
41        fclose( input );
42        if ( alwaysExit || parseStatus != 0 ) {
43                exit( parseStatus );
44        } // if
45} // parse
46
47ast::TranslationUnit buildUnit(void) {
48        std::vector<ast::ptr<ast::Decl>> decls;
49        buildList( parseTree, decls );
50        delete parseTree;
51        parseTree = nullptr;
52
53        ast::TranslationUnit transUnit;
54        for ( auto decl : decls ) {
55                transUnit.decls.emplace_back( std::move( decl ) );
56        }
57        return transUnit;
58}
59
60// Local Variables: //
61// tab-width: 4 //
62// mode: c++ //
63// compile-command: "make install" //
64// End: //
Note: See TracBrowser for help on using the repository browser.