Commit 0eb51ac3 by alokp@chromium.org

Deleted old unused files.

git-svn-id: https://angleproject.googlecode.com/svn/trunk@1091 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 4a02078a
//
// Copyright (c) 2011 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "Context.h"
#include <algorithm>
#include <sstream>
#include "compiler/debug.h"
#include "Lexer.h"
#include "stl_utils.h"
#include "token_type.h"
static bool isMacroNameReserved(const std::string* name)
{
ASSERT(name);
// Names prefixed with "GL_" are reserved.
if (name->substr(0, 3) == "GL_")
return true;
// Names containing two consecutive underscores are reserved.
if (name->find("__") != std::string::npos)
return true;
return false;
}
namespace pp
{
Context::Context() : mOutput(NULL)
{
}
Context::~Context()
{
}
bool Context::process(int count,
const char* const string[],
const int length[],
TokenVector* output)
{
ASSERT((count >=0) && (string != NULL) && (output != NULL));
// Setup.
mLexer.reset(new Lexer);
if (!mLexer->init(count, string, length)) return false;
mOutput = output;
defineBuiltInMacro("GL_ES", 1);
// Parse.
bool success = parse();
// Cleanup.
reset();
return success;
}
int Context::lex(YYSTYPE* lvalp, YYLTYPE* llocp)
{
return mLexer->lex(lvalp, llocp);
}
bool Context::defineMacro(pp::Token::Location location,
pp::Macro::Type type,
std::string* name,
pp::TokenVector* parameters,
pp::TokenVector* replacements)
{
std::auto_ptr<Macro> macro(new Macro(type, name, parameters, replacements));
if (isMacroNameReserved(name))
{
// TODO(alokp): Report error.
return false;
}
if (isMacroDefined(name))
{
// TODO(alokp): Report error.
return false;
}
mMacros[*name] = macro.release();
return true;
}
bool Context::undefineMacro(const std::string* name)
{
MacroSet::iterator iter = mMacros.find(*name);
if (iter == mMacros.end())
{
// TODO(alokp): Report error.
return false;
}
mMacros.erase(iter);
return true;
}
bool Context::isMacroDefined(const std::string* name)
{
return mMacros.find(*name) != mMacros.end();
}
// Reset to initialized state.
void Context::reset()
{
std::for_each(mMacros.begin(), mMacros.end(), DeleteSecond());
mMacros.clear();
mOutput = NULL;
mLexer.reset();
}
void Context::defineBuiltInMacro(const std::string& name, int value)
{
std::ostringstream stream;
stream << value;
Token* token = new Token(0, INT_CONSTANT, new std::string(stream.str()));
TokenVector* replacements = new pp::TokenVector(1, token);
mMacros[name] = new Macro(Macro::kTypeObj,
new std::string(name),
NULL,
replacements);
}
} // namespace pp
//
// Copyright (c) 2011 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef COMPILER_PREPROCESSOR_CONTEXT_H_
#define COMPILER_PREPROCESSOR_CONTEXT_H_
#include <map>
#include "common/angleutils.h"
#include "Macro.h"
#include "Token.h"
struct YYLTYPE;
union YYSTYPE;
namespace pp
{
class Lexer;
class Context
{
public:
Context();
~Context();
bool process(int count, const char* const string[], const int length[],
TokenVector* output);
TokenVector* output() { return mOutput; }
int lex(YYSTYPE* lvalp, YYLTYPE* llocp);
bool defineMacro(pp::Token::Location location,
pp::Macro::Type type,
std::string* name,
pp::TokenVector* parameters,
pp::TokenVector* replacements);
bool undefineMacro(const std::string* name);
bool isMacroDefined(const std::string* name);
private:
DISALLOW_COPY_AND_ASSIGN(Context);
typedef std::map<std::string, Macro*> MacroSet;
void reset();
void defineBuiltInMacro(const std::string& name, int value);
bool parse();
std::auto_ptr<Lexer> mLexer;
TokenVector* mOutput;
MacroSet mMacros; // Defined macros.
};
} // namespace pp
#endif // COMPILER_PREPROCESSOR_CONTEXT_H_
/*
//
// Copyright (c) 2011 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
This file contains the Yacc grammar for GLSL ES preprocessor.
Based on Microsoft Visual Studio 2010 Preprocessor Grammar:
http://msdn.microsoft.com/en-us/library/2scxys89.aspx
IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_glsl_parser.sh,
WHICH GENERATES THE GLSL ES PARSER.
*/
%{
//
// Copyright (c) 2011 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// This file is auto-generated by generate_glslang_parser.sh. DO NOT EDIT!
#if defined(__GNUC__)
#elif defined(_MSC_VER)
#pragma warning(disable: 4065)
#endif
#include "Context.h"
#define YYDEBUG 1
%}
%pure-parser
%name-prefix="pp"
%locations
%parse-param {pp::Context* context}
%lex-param {pp::Context* context}
%union {
int ival;
std::string* sval;
pp::Token* tval;
pp::TokenVector* tlist;
}
%{
static int yylex(YYSTYPE* lvalp, YYLTYPE* llocp, pp::Context* context);
static void yyerror(YYLTYPE* llocp,
pp::Context* context,
const char* reason);
static void pushConditionalBlock(pp::Context* context, bool condition);
static void popConditionalBlock(pp::Context* context);
%}
%token HASH HASH_UNDEF
%token HASH_IF HASH_IFDEF HASH_IFNDEF HASH_ELSE HASH_ELIF HASH_ENDIF DEFINED
%token HASH_ERROR HASH_PRAGMA HASH_EXTENSION HASH_VERSION HASH_LINE
%token <sval> HASH_DEFINE_OBJ HASH_DEFINE_FUNC
%token <sval> INT_CONSTANT FLOAT_CONSTANT IDENTIFIER
%type <ival> operator
%type <tval> conditional_token token
%type <tlist> parameter_list replacement_list conditional_list token_list
%%
input
: /* empty */
| input line
;
line
: text_line
| control_line
;
text_line
: '\n'
| token_list '\n' {
// TODO(alokp): Expand macros.
pp::TokenVector* out = context->output();
out->insert(out->end(), $1->begin(), $1->end());
delete $1;
}
;
control_line
: HASH '\n'
| HASH_DEFINE_OBJ replacement_list '\n' {
context->defineMacro(@1.first_line, pp::Macro::kTypeObj, $1, NULL, $2);
}
| HASH_DEFINE_FUNC '(' parameter_list ')' replacement_list '\n' {
context->defineMacro(@1.first_line, pp::Macro::kTypeFunc, $1, $3, $5);
}
| HASH_UNDEF IDENTIFIER '\n' {
context->undefineMacro($2);
}
| HASH_IF conditional_list '\n' {
pushConditionalBlock(context, $2 ? true : false);
}
| HASH_IFDEF IDENTIFIER '\n' {
pushConditionalBlock(context, context->isMacroDefined($2));
}
| HASH_IFNDEF IDENTIFIER '\n' {
pushConditionalBlock(context, !context->isMacroDefined($2));
}
| HASH_ELIF conditional_list '\n' {
}
| HASH_ELSE '\n' {
}
| HASH_ENDIF '\n' {
popConditionalBlock(context);
}
| HASH_ERROR '\n'
| HASH_PRAGMA '\n'
| HASH_EXTENSION '\n'
| HASH_VERSION '\n'
| HASH_LINE '\n'
;
replacement_list
: /* empty */ { $$ = NULL; }
| token_list
parameter_list
: /* empty */ { $$ = NULL; }
| IDENTIFIER {
$$ = new pp::TokenVector;
$$->push_back(new pp::Token(@1.first_line, IDENTIFIER, $1));
}
| parameter_list ',' IDENTIFIER {
$$ = $1;
$$->push_back(new pp::Token(@3.first_line, IDENTIFIER, $3));
}
conditional_list
: conditional_token {
$$ = new pp::TokenVector;
$$->push_back($1);
}
| conditional_list conditional_token {
$$ = $1;
$$->push_back($2);
}
;
token_list
: token {
$$ = new pp::TokenVector;
$$->push_back($1);
}
| token_list token {
$$ = $1;
$$->push_back($2);
}
;
conditional_token
: DEFINED IDENTIFIER {
}
| DEFINED '(' IDENTIFIER ')' {
}
| token
;
token
: operator {
$$ = new pp::Token(@1.first_line, $1, NULL);
}
| INT_CONSTANT {
$$ = new pp::Token(@1.first_line, INT_CONSTANT, $1);
}
| FLOAT_CONSTANT {
$$ = new pp::Token(@1.first_line, FLOAT_CONSTANT, $1);
}
| IDENTIFIER {
$$ = new pp::Token(@1.first_line, IDENTIFIER, $1);
}
;
operator
: '[' { $$ = '['; }
| ']' { $$ = ']'; }
| '<' { $$ = '<'; }
| '>' { $$ = '>'; }
| '(' { $$ = '('; }
| ')' { $$ = ')'; }
| '{' { $$ = '{'; }
| '}' { $$ = '}'; }
| '.' { $$ = '.'; }
| '+' { $$ = '+'; }
| '-' { $$ = '-'; }
| '/' { $$ = '/'; }
| '*' { $$ = '*'; }
| '%' { $$ = '%'; }
| '^' { $$ = '^'; }
| '|' { $$ = '|'; }
| '&' { $$ = '&'; }
| '~' { $$ = '~'; }
| '=' { $$ = '='; }
| '!' { $$ = '!'; }
| ':' { $$ = ':'; }
| ';' { $$ = ';'; }
| ',' { $$ = ','; }
| '?' { $$ = '?'; }
;
%%
int yylex(YYSTYPE* lvalp, YYLTYPE* llocp, pp::Context* context)
{
return context->lex(lvalp, llocp);
}
void yyerror(YYLTYPE* llocp, pp::Context* context, const char* reason)
{
}
void pushConditionalBlock(pp::Context* context, bool condition)
{
}
void popConditionalBlock(pp::Context* context)
{
}
namespace pp {
bool Context::parse()
{
yydebug = 1;
return yyparse(this) == 0 ? true : false;
}
} // namespace pp
/* A Bison parser, made by GNU Bison 2.4.2. */
/* Skeleton interface for Bison's Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2006, 2009-2010 Free Software
Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
HASH = 258,
HASH_UNDEF = 259,
HASH_IF = 260,
HASH_IFDEF = 261,
HASH_IFNDEF = 262,
HASH_ELSE = 263,
HASH_ELIF = 264,
HASH_ENDIF = 265,
DEFINED = 266,
HASH_ERROR = 267,
HASH_PRAGMA = 268,
HASH_EXTENSION = 269,
HASH_VERSION = 270,
HASH_LINE = 271,
HASH_DEFINE_OBJ = 272,
HASH_DEFINE_FUNC = 273,
INT_CONSTANT = 274,
FLOAT_CONSTANT = 275,
IDENTIFIER = 276
};
#endif
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
int ival;
std::string* sval;
pp::Token* tval;
pp::TokenVector* tlist;
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif
#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
typedef struct YYLTYPE
{
int first_line;
int first_column;
int last_line;
int last_column;
} YYLTYPE;
# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
# define YYLTYPE_IS_DECLARED 1
# define YYLTYPE_IS_TRIVIAL 1
#endif
//
// Copyright (c) 2011 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// stl_utils.h: Common STL utilities.
#ifndef COMMON_STLUTILS_H_
#define COMMON_STLUTILS_H_
namespace pp
{
struct Delete
{
template<class T>
void operator() (T x) { delete x; }
};
struct DeleteSecond
{
template<class A, class B>
void operator() (std::pair<A, B>& x) { delete x.second; }
};
} // namespace pp
#endif // COMMON_STLUTILS_H_
//
// Copyright (c) 2011 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef COMPILER_PREPROCESSOR_TOKEN_TYPE_H_
#define COMPILER_PREPROCESSOR_TOKEN_TYPE_H_
#include "pp_tab.h"
#endif // COMPILER_PREPROCESSOR_TOKEN_TYPE_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment