view anagram/agcore/tree.cpp @ 8:ec2b657edf13

Add explicit lint-comment-style fallthrough annotations. GCC now assumes that if you don't have these you're making a mistake, which is annoying. XXX: This changeset updates the AG output files only (by hand) and is XXX: abusive - rebuilding them will erase the change. However, I need XXX: to get things to build before I can try to get AG to issue the XXX: annotations itself, so this seems like a reasonable expedient.
author David A. Holland
date Mon, 30 May 2022 23:51:43 -0400
parents 607e3be6bad8
children
line wrap: on
line source

/*
 * AnaGram, A System for Syntax Directed Programming
 * Copyright 1993-2002 Parsifal Software. All Rights Reserved.
 * See the file COPYING for license and usage terms.
 *
 * tree.cpp
 */

#include "assert.h"
#include "csexp.h"
#include "tree.h"

//#define INCLUDE_LOGGING
#include "log.h"



int parse_tree_map::operator < (const parse_tree_map &t) const {
  LOGSECTION_OFF("parse_tree_map::operator <");
  LOGV(expression != 0 ? expression->asString() : AgString());
  LOGV(t.expression != 0 ? t.expression->asString() : AgString());

  if (expression && t.expression) {
    return *expression < *t.expression;
  }
  if (expression == 0) {
    return t.expression != 0;
  }
  return 0;
}

ParseTree::ParseTree(unsigned x) 
  : KeyedObjectRegister<parse_tree_map>(x)
{}

ParseTree::ParseTree(const ParseTree &t)
  : KeyedObjectRegister<parse_tree_map>(t)
{}

void ParseTree::operator = (const ParseTree &t) {
  KeyedObjectRegister<parse_tree_map>::operator = (t);
}

ParseTree::ParseTree(CharSetExpression *x)
  : KeyedObjectRegister<parse_tree_map>(parse_tree_map(x))
{
  LOGSECTION("ParseTree::ParseTree");
  LOGV(index) LCV(x == 0 ? AgString() : x->asString());
  LOGV((int) x) LCV((int) descriptor->expression);

  if (descriptor->expression != x) {
    delete x;
  }
}

parse_tree_map &ParseTree::Map::operator [] (unsigned x) {
  assert(x < ParseTree::descriptorList.size());
  return ParseTree::descriptorList[x];
}

void ParseTree::reset() {
  LOGSECTION("ParseTree::reset");
  int n = descriptorList.size();
  while (n-- > 0) {
    delete descriptorList[n].expression;
  }
  KeyedObjectRegister<parse_tree_map>::reset();
  //descriptorList.push(parse_tree_map());
  ParseTree parseTree((CharSetExpression *) 0);
}

parse_tree_map::parse_tree_map()
  : expression(0), char_set(0)
{
  // Nothing to do
}

parse_tree_map::parse_tree_map(CharSetExpression *x)
  : expression(x), char_set(0)
{
  LOGSECTION("parse_tree_map::parse_tree_map");
  LOGV((int) this) LCV((int) x);
}

ParseTree::Map map_parse_tree;