source: src/Parser/RunParser.cpp @ a8ced63

Last change on this file since a8ced63 was c92bdcc, checked in by Andrew Beach <ajbeach@…>, 6 months ago

Updated the rest of the names in src/ (except for the generated files).

  • Property mode set to 100644
File size: 1.6 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/TranslationUnit.hpp"          // for TranslationUnit
19#include "Common/CodeLocationTools.hpp"     // for forceFillCodeLocations
20#include "Parser/DeclarationNode.hpp"       // for DeclarationNode, buildList
21#include "Parser/TypedefTable.hpp"          // for TypedefTable
22
23// Variables global to the parsing code.
24ast::Linkage::Spec linkage = ast::Linkage::Cforall;
25TypedefTable typedefTable;
26DeclarationNode * parseTree = nullptr;
27
28void parse( FILE * input, ast::Linkage::Spec linkage, bool alwaysExit ) {
29        extern int yyparse( void );
30        extern FILE * yyin;
31        extern int yylineno;
32
33        // Set global information.
34        ::linkage = linkage;
35        yyin = input;
36        yylineno = 1;
37
38        int parseStatus = yyparse();
39        fclose( input );
40        if ( alwaysExit || parseStatus != 0 ) {
41                exit( parseStatus );
42        } // if
43} // parse
44
45ast::TranslationUnit buildUnit(void) {
46        std::vector<ast::ptr<ast::Decl>> decls;
47        buildList( parseTree, decls );
48        delete parseTree;
49        parseTree = nullptr;
50
51        ast::TranslationUnit transUnit;
52        for ( auto decl : decls ) {
53                transUnit.decls.emplace_back( std::move( decl ) );
54        }
55        return transUnit;
56}
57
58// Local Variables: //
59// tab-width: 4 //
60// mode: c++ //
61// compile-command: "make install" //
62// End: //
Note: See TracBrowser for help on using the repository browser.