|
//====================================================================
// Although great care has gone into developing this software,
// it is provided without any guarantee of reliability, accuracy
// of information, or correctness of operation. I am not responsible
// for any damages that may occur as a result of using this software.
// Use this software entirely at your own risk.
// Copyright 2003, Chris Richardson
//
// Description: Simple #include parser.
//
//====================================================================
#if !defined(AFX_PARSER_H__F3B0EDC8_B2D6_40E4_94B6_48ED91C12A33__INCLUDED_)
#define AFX_PARSER_H__F3B0EDC8_B2D6_40E4_94B6_48ED91C12A33__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Status.h"
#include "global.h"
#include "ParsedFile.h"
#include "Token.h"
using namespace std;
class CLexer;
class CParsedFile;
class CIncludeFinderInfo;
class CDSParsedSettings;
class CStatusNotifier
{
public:
virtual void OnFileStart( CParsedFile * p_poFile ) = 0;
virtual void OnFileComplete( CParsedFile * p_poResults ) = 0;
virtual void OnFinished() = 0;
};
typedef vector<CLexer*> CLexerStack;
struct ParseNode
{
public:
ParseNode( long p_lValue = 0, bool p_bOK = false ) :
lValue( p_lValue ),
bOK( p_bOK )
{
}
void OK()
{
bOK = true;
}
// Value of the node.
long lValue;
// Did it parse OK?
bool bOK;
};
typedef map<CTCharString,ParseNode,CTCharStringLess> CStdMapStringToNode;
class CParser
{
public:
CParser( CIncludeFinderInfo * p_poInfo );
virtual ~CParser();
ParseStatus Parse( const TCHAR * p_pszFile,
CParsedFileList * p_poResults,
HANDLE p_hStopEvent );
void SetSettings( CDSParsedSettings & p_roSettings );
inline CParsedFile * GetLastFile();
protected:
CLexer * c_poLexer; // Cached copy of the top of the stack.
CLexerStack c_oLexerStack;
CToken c_oToken;
CParsedFileList * c_poResults;
CStdStringArray c_oIncludeDirs;
CParsedFile * c_poLastFile;
CParsedFile * c_poParentFile;
CIncludeFinderInfo * c_poFindInfo;
HANDLE c_hStopEvent;
ParseStatus Eat( ParseTokens p_eToken );
ParseStatus ParseInternal( const TCHAR * p_pszFile );
ParseStatus ParseFile();
CParsedFile * Lookup( const TCHAR * p_pszFile );
CParsedFile * LookupInParent( CParsedFile * p_poParent, const TCHAR * p_pszFile );
BOOL FindFullPath( const TCHAR * p_pszFile,
TCHAR * p_pszFullPath,
BOOL p_bIsBracketed );
// Pre-processor handling.
long c_lPreprocessorExcluding;
CStdLongArray c_oPreprocessorExpressionStack;
CStdMapStringToNode c_oDefinedVars;
ParseStatus ParsePreprocessorStatement();
ParseNode ParsePreprocessorExpression( long p_lPrec );
ParseNode ParsePreprocessorUnaryExpression( long p_lPrec );
long Precedence( ParseTokens p_eOp, int p_iOps );
};
inline CParsedFile * CParser::GetLastFile()
{
return c_poLastFile;
}
//
// ------------------------------------------------------------------
//
#endif // !defined(AFX_PARSER_H__F3B0EDC8_B2D6_40E4_94B6_48ED91C12A33__INCLUDED_)
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.