159b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill//
259b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill// Copyright (c) 2011 The ANGLE Project Authors. All rights reserved.
359b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill// Use of this source code is governed by a BSD-style license that can be
459b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill// found in the LICENSE file.
559b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill//
659b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill
759b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill#ifndef COMPILER_PREPROCESSOR_PREPROCESSOR_H_
859b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill#define COMPILER_PREPROCESSOR_PREPROCESSOR_H_
959b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill
1059b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill#include <stddef.h>
1159b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill
1259b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill#include "pp_utils.h"
1359b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill
1459b77858e30ff402ea4af9285d038bc255b53c48Jamie Madillnamespace pp
1559b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill{
1659b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill
1759b77858e30ff402ea4af9285d038bc255b53c48Jamie Madillclass Diagnostics;
1859b77858e30ff402ea4af9285d038bc255b53c48Jamie Madillclass DirectiveHandler;
1959b77858e30ff402ea4af9285d038bc255b53c48Jamie Madillstruct PreprocessorImpl;
2059b77858e30ff402ea4af9285d038bc255b53c48Jamie Madillstruct Token;
2159b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill
2259b77858e30ff402ea4af9285d038bc255b53c48Jamie Madillclass Preprocessor
2359b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill{
2459b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill  public:
2559b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    Preprocessor(Diagnostics* diagnostics, DirectiveHandler* directiveHandler);
2659b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    ~Preprocessor();
2759b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill
2859b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    // count: specifies the number of elements in the string and length arrays.
2959b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    // string: specifies an array of pointers to strings.
3059b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    // length: specifies an array of string lengths.
3159b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    // If length is NULL, each string is assumed to be null terminated.
3259b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    // If length is a value other than NULL, it points to an array containing
3359b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    // a string length for each of the corresponding elements of string.
3459b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    // Each element in the length array may contain the length of the
3559b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    // corresponding string or a value less than 0 to indicate that the string
3659b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    // is null terminated.
3759b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    bool init(size_t count, const char* const string[], const int length[]);
3859b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    // Adds a pre-defined macro.
3959b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    void predefineMacro(const char* name, int value);
4059b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    // Sets maximum allowed token length.
4159b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    // If token length exceeds this limit,
4259b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    // the token text will be truncated to the given maximum length, and
4359b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    // TOKEN_TOO_LONG diagnostic will be generated.
4459b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    // The maximum length defaults to 256.
4559b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    void setMaxTokenLength(size_t maxLength);
4659b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill
4759b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    void lex(Token* token);
4859b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill
4959b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill  private:
5059b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    PP_DISALLOW_COPY_AND_ASSIGN(Preprocessor);
5159b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill
5259b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill    PreprocessorImpl* mImpl;
5359b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill};
5459b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill
5559b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill}  // namespace pp
5659b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill#endif  // COMPILER_PREPROCESSOR_PREPROCESSOR_H_
5759b77858e30ff402ea4af9285d038bc255b53c48Jamie Madill
58