source: src/Parser/RunParser.cpp @ afdb74b

ADTast-experimental
Last change on this file since afdb74b was f2f595d7, checked in by Andrew Beach <ajbeach@…>, 21 months ago

RunParser? now uses AST for its interface everywhere. (Works because LinkageSpec::Spec and ast::Linkage::Spec have the same layout.)

  • Property mode set to 100644
File size: 2.0 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 : Thr Feb 16 10:08:00 2023
13// Update Count     : 2
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/ParseNode.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::list<Declaration *> translationUnit;
49        buildList( parseTree, translationUnit );
50
51        delete parseTree;
52        parseTree = nullptr;
53
54        // When the parse/buildList code is translated to the new ast, these
55        // fill passes (and the one after 'Hoist Type Decls') should be redundent
56        // because the code locations should already be filled.
57        CodeTools::fillLocations( translationUnit );
58        ast::TranslationUnit transUnit = convert( std::move( translationUnit ) );
59        forceFillCodeLocations( transUnit );
60        return transUnit;
61}
62
63// Local Variables: //
64// tab-width: 4 //
65// mode: c++ //
66// compile-command: "make install" //
67// End: //
Note: See TracBrowser for help on using the repository browser.