source: src/Parser/RunParser.cpp @ ded6c2a6

ast-experimental
Last change on this file since ded6c2a6 was c468150, checked in by Andrew Beach <ajbeach@…>, 20 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
RevLine 
[cbd1ba8]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
[bb7422a]12// Last Modified On : Mon Mar  6  9:42:00 2023
13// Update Count     : 3
[cbd1ba8]14//
15
16#include "RunParser.hpp"
17
[019b2d3]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
[c468150]22#include "Parser/DeclarationNode.h"         // for DeclarationNode, buildList
[cbd1ba8]23#include "Parser/TypedefTable.h"            // for TypedefTable
24
25// Variables global to the parsing code.
[f2f595d7]26ast::Linkage::Spec linkage = ast::Linkage::Cforall;
[cbd1ba8]27TypedefTable typedefTable;
28DeclarationNode * parseTree = nullptr;
29
[f2f595d7]30void parse( FILE * input, ast::Linkage::Spec linkage, bool alwaysExit ) {
[cbd1ba8]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
[019b2d3]47ast::TranslationUnit buildUnit(void) {
[bb7422a]48        std::vector<ast::ptr<ast::Decl>> decls;
49        buildList( parseTree, decls );
[cbd1ba8]50        delete parseTree;
51        parseTree = nullptr;
52
[bb7422a]53        ast::TranslationUnit transUnit;
54        for ( auto decl : decls ) {
55                transUnit.decls.emplace_back( std::move( decl ) );
56        }
[019b2d3]57        return transUnit;
[cbd1ba8]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.