Blame src/scan-code.h

Packit Service c3aa71
/* Bison code properties structure and scanner.
Packit Service c3aa71
Packit Service c3aa71
   Copyright (C) 2006-2007, 2009-2015 Free Software Foundation, Inc.
Packit Service c3aa71
Packit Service c3aa71
   This file is part of Bison, the GNU Compiler Compiler.
Packit Service c3aa71
Packit Service c3aa71
   This program is free software: you can redistribute it and/or modify
Packit Service c3aa71
   it under the terms of the GNU General Public License as published by
Packit Service c3aa71
   the Free Software Foundation, either version 3 of the License, or
Packit Service c3aa71
   (at your option) any later version.
Packit Service c3aa71
Packit Service c3aa71
   This program is distributed in the hope that it will be useful,
Packit Service c3aa71
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service c3aa71
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service c3aa71
   GNU General Public License for more details.
Packit Service c3aa71
Packit Service c3aa71
   You should have received a copy of the GNU General Public License
Packit Service c3aa71
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit Service c3aa71
Packit Service c3aa71
#ifndef SCAN_CODE_H_
Packit Service c3aa71
# define SCAN_CODE_H_
Packit Service c3aa71
Packit Service c3aa71
# include "location.h"
Packit Service c3aa71
# include "named-ref.h"
Packit Service c3aa71
Packit Service c3aa71
struct symbol_list;
Packit Service c3aa71
Packit Service c3aa71
/**
Packit Service c3aa71
 * Keeps track of the maximum number of semantic values to the left of a handle
Packit Service c3aa71
 * (those referenced by $0, $-1, etc.) that are required by the semantic
Packit Service c3aa71
 * actions of this grammar.
Packit Service c3aa71
 */
Packit Service c3aa71
extern int max_left_semantic_context;
Packit Service c3aa71
Packit Service c3aa71
/**
Packit Service c3aa71
 * A code passage captured from the grammar file and possibly translated,
Packit Service c3aa71
 * and/or properties associated with such a code passage.  Don't break
Packit Service c3aa71
 * encapsulation by modifying the fields directly.  Use the provided interface
Packit Service c3aa71
 * functions.
Packit Service c3aa71
 */
Packit Service c3aa71
typedef struct code_props {
Packit Service c3aa71
  /** Set by the init functions.  */
Packit Service c3aa71
  enum {
Packit Service c3aa71
    CODE_PROPS_NONE, CODE_PROPS_PLAIN,
Packit Service c3aa71
    CODE_PROPS_SYMBOL_ACTION, CODE_PROPS_RULE_ACTION
Packit Service c3aa71
  } kind;
Packit Service c3aa71
Packit Service c3aa71
  /**
Packit Service c3aa71
   * \c NULL iff \c code_props::kind is \c CODE_PROPS_NONE.
Packit Service c3aa71
   * Memory is allocated in an obstack freed elsewhere.
Packit Service c3aa71
   */
Packit Service c3aa71
  char const *code;
Packit Service c3aa71
  /** Undefined iff \c code_props::code is \c NULL.  */
Packit Service c3aa71
  location location;
Packit Service c3aa71
Packit Service c3aa71
  /**
Packit Service c3aa71
   * \c false iff either:
Packit Service c3aa71
   *   - \c code_props_translate_code has never previously been invoked for
Packit Service c3aa71
   *     the \c code_props that would contain the code passage associated
Packit Service c3aa71
   *     with \c self.  (That \c code_props is not the same as this one if this
Packit Service c3aa71
   *     one is for a RHS \c symbol_list node.  Instead, it's the \c code_props
Packit Service c3aa71
   *     for the LHS symbol of the same rule.)
Packit Service c3aa71
   *   - \c code_props_translate_code has been invoked for that \c code_props,
Packit Service c3aa71
   *     but the symbol value associated with this \c code_props was not
Packit Service c3aa71
   *     referenced in the code passage.
Packit Service c3aa71
   */
Packit Service c3aa71
  bool is_value_used;
Packit Service c3aa71
Packit Service c3aa71
  /**
Packit Service c3aa71
   * \c true iff this code is an action that is not to be deferred in
Packit Service c3aa71
   * a non-deterministic parser.
Packit Service c3aa71
   */
Packit Service c3aa71
  bool is_predicate;
Packit Service c3aa71
Packit Service c3aa71
  /**
Packit Service c3aa71
   * Whether this is actually used (i.e., not completely masked by
Packit Service c3aa71
   * other code props).  */
Packit Service c3aa71
  bool is_used;
Packit Service c3aa71
Packit Service c3aa71
  /** \c NULL iff \c code_props::kind is not \c CODE_PROPS_RULE_ACTION.  */
Packit Service c3aa71
  struct symbol_list *rule;
Packit Service c3aa71
Packit Service c3aa71
  /* Named reference. */
Packit Service c3aa71
  named_ref *named_ref;
Packit Service c3aa71
} code_props;
Packit Service c3aa71
Packit Service c3aa71
/**
Packit Service c3aa71
 * \pre
Packit Service c3aa71
 *   - <tt>self != NULL</tt>.
Packit Service c3aa71
 * \post
Packit Service c3aa71
 *   - \c self has been overwritten to contain no code.
Packit Service c3aa71
 */
Packit Service c3aa71
void code_props_none_init (code_props *self);
Packit Service c3aa71
Packit Service c3aa71
/** Equivalent to \c code_props_none_init.  */
Packit Service c3aa71
# define CODE_PROPS_NONE_INIT                   \
Packit Service c3aa71
  {                                             \
Packit Service c3aa71
    /* .kind = */ CODE_PROPS_NONE,              \
Packit Service c3aa71
    /* .code = */ NULL,                         \
Packit Service c3aa71
    /* .location = */ EMPTY_LOCATION_INIT,      \
Packit Service c3aa71
    /* .is_value_used = */ false,               \
Packit Service c3aa71
    /* .is_predicate = */ false,                \
Packit Service c3aa71
    /* .is_used = */ false,                     \
Packit Service c3aa71
    /* .rule = */ NULL,                         \
Packit Service c3aa71
    /* .named_ref = */ NULL                     \
Packit Service c3aa71
  }
Packit Service c3aa71
Packit Service c3aa71
/** Initialized by \c CODE_PROPS_NONE_INIT with no further modification.  */
Packit Service c3aa71
extern code_props code_props_none;
Packit Service c3aa71
Packit Service c3aa71
/**
Packit Service c3aa71
 * \pre
Packit Service c3aa71
 *   - <tt>self != NULL</tt>.
Packit Service c3aa71
 *   - <tt>code != NULL</tt>.
Packit Service c3aa71
 *   - \c code is an untranslated code passage containing no Bison escapes.
Packit Service c3aa71
 *   - \c code was extracted from the grammar file at \c code_loc.
Packit Service c3aa71
 * \post
Packit Service c3aa71
 *   - \c self has been overwritten to represent the specified plain code
Packit Service c3aa71
 *     passage.
Packit Service c3aa71
 *   - \c self will become invalid if the caller frees \c code before invoking
Packit Service c3aa71
 *     \c code_props_translate_code on \c self.
Packit Service c3aa71
 */
Packit Service c3aa71
void code_props_plain_init (code_props *self, char const *code,
Packit Service c3aa71
                            location code_loc);
Packit Service c3aa71
Packit Service c3aa71
/**
Packit Service c3aa71
 * \pre
Packit Service c3aa71
 *   - <tt>self != NULL</tt>.
Packit Service c3aa71
 *   - <tt>code != NULL</tt>.
Packit Service c3aa71
 *   - \c code is an untranslated code passage.  The only Bison escapes it
Packit Service c3aa71
 *     might contain are $$ and \@$, referring to a single symbol.
Packit Service c3aa71
 *   - \c code was extracted from the grammar file at \c code_loc.
Packit Service c3aa71
 * \post
Packit Service c3aa71
 *   - \c self has been overwritten to represent the specified symbol action.
Packit Service c3aa71
 *   - \c self will become invalid if the caller frees \c code before invoking
Packit Service c3aa71
 *     \c code_props_translate_code on \c self.
Packit Service c3aa71
 */
Packit Service c3aa71
void code_props_symbol_action_init (code_props *self, char const *code,
Packit Service c3aa71
                                    location code_loc);
Packit Service c3aa71
Packit Service c3aa71
/**
Packit Service c3aa71
 * \pre
Packit Service c3aa71
 *   - <tt>self != NULL</tt>.
Packit Service c3aa71
 *   - <tt>code != NULL</tt>.
Packit Service c3aa71
 *   - <tt>rule != NULL</tt>.
Packit Service c3aa71
 *   - \c code is the untranslated action of the rule for which \c rule is the
Packit Service c3aa71
 *     LHS node.  Thus, \c code possibly contains Bison escapes such as $$, $1,
Packit Service c3aa71
 *     $2, etc referring to the values of the rule.
Packit Service c3aa71
 *   - \c code was extracted from the grammar file at \c code_loc.
Packit Service c3aa71
 * \post
Packit Service c3aa71
 *   - \c self has been overwritten to represent the specified rule action.
Packit Service c3aa71
 *   - \c self does not claim responsibility for the memory of \c rule.
Packit Service c3aa71
 *   - \c self will become invalid if:
Packit Service c3aa71
 *     - The caller frees \c code before invoking \c code_props_translate_code
Packit Service c3aa71
 *       on \c self.
Packit Service c3aa71
 *     - The caller frees \c rule.
Packit Service c3aa71
 */
Packit Service c3aa71
void code_props_rule_action_init (code_props *self, char const *code,
Packit Service c3aa71
                                  location code_loc, struct symbol_list *rule,
Packit Service c3aa71
                                  named_ref *name, bool is_predicate);
Packit Service c3aa71
Packit Service c3aa71
/**
Packit Service c3aa71
 * \pre
Packit Service c3aa71
 *   - If there's a code passage contained in \c self and it contains Bison
Packit Service c3aa71
 *     escapes, all grammar declarations have already been parsed as they may
Packit Service c3aa71
 *     affect warnings and complaints issued here.
Packit Service c3aa71
 * \post
Packit Service c3aa71
 *   - All M4-special symbols and Bison escapes have been translated in
Packit Service c3aa71
 *     \c self->code.
Packit Service c3aa71
 *   - <tt>self->code != self->code\@pre</tt> unless
Packit Service c3aa71
 *     <tt>self->code\@pre = NULL</tt>.
Packit Service c3aa71
 */
Packit Service c3aa71
void code_props_translate_code (code_props *self);
Packit Service c3aa71
Packit Service c3aa71
/**
Packit Service c3aa71
 * \pre
Packit Service c3aa71
 *   - None.
Packit Service c3aa71
 * \post
Packit Service c3aa71
 *   - The dynamic memory allocated by the previous invocation of
Packit Service c3aa71
 *     \c code_props_translate_code (if any) was freed.  The \c code_props
Packit Service c3aa71
 *     instance for which \c code_props_translate_code was invoked is now
Packit Service c3aa71
 *     invalid.
Packit Service c3aa71
 */
Packit Service c3aa71
void code_scanner_last_string_free (void);
Packit Service c3aa71
Packit Service c3aa71
/**
Packit Service c3aa71
 * \pre
Packit Service c3aa71
 *   - None.
Packit Service c3aa71
 * \post
Packit Service c3aa71
 *   - All dynamic memory allocated during invocations of
Packit Service c3aa71
 *     \c code_props_translate_code (if any) has been freed.  All \c code_props
Packit Service c3aa71
 *     instances may now be invalid.
Packit Service c3aa71
 */
Packit Service c3aa71
void code_scanner_free (void);
Packit Service c3aa71
Packit Service c3aa71
#endif /* !SCAN_CODE_H_ */