Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 Nov 2002 23:45:07 -0800 (PST)
From:      Galen Sampson <galen_sampson@yahoo.com>
To:        current@freebsd.org
Subject:   Internal Compiler Error (not from ports)
Message-ID:  <20021113074507.30655.qmail@web14105.mail.yahoo.com>

next in thread | raw e-mail | index | archive | help
--0-1283656024-1037173507=:30222
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hello all,

After updating to -current sources last night I found that I can reproduce an
internal compiler error with my own source code.  I'm not sure if it is related
to the internal compiler error people are having with the ports are not.

the command:
   g++ -Wall -c btree.cpp

generates the error (source code attached).

To help track this down line 12 of btree.h is commented out.  Uncommenting this
line allows the compiler to produce a .o file.

If anyone is interested I will be happy to build a debug g++ if someone will
point me in the right direction to get that accomplished.  If you need me to
ident g++ or need more information feel free to ask.

regards,
Galen Sampson


__________________________________________________
Do you Yahoo!?
U2 on LAUNCH - Exclusive greatest hits videos
http://launch.yahoo.com/u2
--0-1283656024-1037173507=:30222
Content-Type: text/plain; name="btree.h"
Content-Description: btree.h
Content-Disposition: inline; filename="btree.h"

#ifndef BTREE_H
#define BTREE_H

#include <cstdlib>

#define N 7

template <class Key, class Element>
class BTree {
private:
	class Node;
//        class KeyNode;
        class DataNode;
        Node *root;
public:
	inline BTree();
	inline ~BTree();
	
	inline bool search(Key &, Element &) const;
	inline bool insert(Key &, Element &);
	inline bool remove(Key &, Element &);
};

#endif

--0-1283656024-1037173507=:30222
Content-Type: text/plain; name="btree.cpp"
Content-Description: btree.cpp
Content-Disposition: inline; filename="btree.cpp"

#include "btree.h"

/* BTree nested class Node definitions */
template <class Key, class Element>
class BTree<Key, Element>::Node {
public:
	Node *left;
	Node *right;
	
	inline Node();
	virtual bool search(Key &, Element &) const = 0;
	virtual bool insert(Node * &, Node * &, Key &, Element &) = 0;
	virtual bool remove(Node * &, Node * &, Key &, Element &) = 0;
protected:
	unsigned int numElements;
};

/* Node funtion definitions */
template <class Key, class Element>
inline BTree<Key, Element>::Node::Node()
:left(NULL), right(NULL), numElements(0)
{
}

/* KeyNode nested and inherited class definition */
template <class Key, class Element>
class BTree<Key, Element>::KeyNode : BTree<Key, Element>::Node {
public:
	bool search(Key &, Element &) const;
	bool insert(Node * &, Node * &, Key &, Element &);
	//bool remove(Node * &, Node * &, Key &, Element &);
private:
	class NodeItem {
	public:
		Key &k;
		BTree<Key, Element>::Node *child;
		NodeItem *next;
	};
	
	NodeItem *preHead;
	NodeItem *head;
	NodeItem *tail;
	NodeItem *splitPoint;
	
	KeyNode(Node *);
	inline NodeItem * _search(Key &k) const
	{
		/* preHead and head can _never_ be NULL;
		 * For a KeyNode to exist at least two DataNodes must exist
		 *
		 * This means it is not necessary to check if preHead == NULL
		 * and it is also not necessary to check if head == NULL
		 */
		if(k < head->k)
			return preHead;

		NodeItem *temp = head;
		while(temp->next != NULL && temp->next->k >= k)
			temp = temp->next;

		return temp;	
	}
};

template <class Key, class Element>
class BTree<Key, Element>::DataNode : BTree<Key, Element>::Node {
public:
	inline DataNode();
	bool search(Key &, Element &) const;
	bool insert(Node * &, Node * &, Key &, Element &);
	bool remove(Node * &, Node * &, Key &, Element &);
private:
	class NodeItem {
	public:
		Key &k;
		Element &e;
		NodeItem *next;
	};

	NodeItem *head;
	NodeItem *tail;
	NodeItem *splitPoint;
	
	DataNode(Node *);
};

/* BTree function definitions */
template <class Key, class Element>
inline BTree<Key, Element>::BTree()
{
	root = new DataNode();
}

template <class Key, class Element>
inline BTree<Key, Element>::~BTree()
{
	delete root;
}

template <class Key, class Element>
inline bool BTree<Key, Element>::search(Key &k, Element &e) const
{
	return root->search(k, e);
}

template <class Key, class Element>
inline bool BTree<Key, Element>::insert(Key &k, Element &e)
{
	Node *p = root;
	return root->insert(p, k, e);
}

template <class Key, class Element>
inline bool BTree<Key, Element>::remove(Key &k, Element &e)
{
	Node *p = root;
	return root->remove(p, k, e);
}

/* KeyNode function definitions */
template <class Key, class Element>
BTree<Key, Element>::KeyNode::KeyNode(Node *l)
:preHead(l->splitPoint), head(l->splitPoint->next), tail(l->tail)
{
	numElements = l->numElements / 2;
	left = l;
	right = l->right, 
	preHead->next = NULL;
}

template <class Key, class Element>
bool BTree<Key, Element>::KeyNode::search(Key &k, Element &e) const
{
	return _search(k)->child->search(k, e);	
}

template <class Key, class Element>
bool BTree<Key, Element>::KeyNode::insert(Node * &p, Node * &toAdd, Key &k, Element &e)
{
	bool toReturn;
	
	NodeItem *temp = _search(k);
	Node *newNode = NULL;
	
	toReturn = temp->child->insert(p, newNode, k, e);

	if(newNode != NULL)
	{
		numElements++;
		
		if(temp == preHead)
		{
			preHead->next = head;
			head = preHead;
			preHead = new NodeItem(k, newNode, NULL);
		}
		else
		{
			temp->next = new NodeItem(k, newNode, temp->next);
			if(temp == tail)
			{
				tail = temp->next;
			}
		}
	}
	
	if(numElements > N)
	{
		Node *newRight = new KeyNode(this);
		if(right != NULL)
		{
			right->left = newRight;
		}
		right = newRight;

		if(p == this)
		{
			p = new KeyNode(this, newRight);
		}
		else
		{
			toAdd = newRight;
		}
	}

	return toReturn;
}

/*
template <class Key, class Element>
bool BTree<Key, Element>::KeyNode::remove(Node * &, Key &, Element &)
{
	return true;
}
*/

/*
template <class Key, class Element>
inline BTree<Key, Element>::KeyNode::NodeItem *
BTree<Key, Element>::KeyNode::_search(Key &k) const
{
	/* preHead and head can _never_ be NULL;
	 * For a KeyNode to exist at least two DataNodes must exist
	 *
	 * This means it is not necessary to check if preHead == NULL
	 * and it is also not necessary to check if head == NULL
	 */
	 /*
	if(k < head->k)
		return preHead;

	NodeItem *temp = head;
	while(temp->next != NULL && temp->next->k >= k)
		temp = temp->next;

	return temp;	
}
*/

/* DataNode function definitions */
template <class Key, class Element>
inline BTree<Key, Element>::DataNode::DataNode()
:head(NULL), tail(NULL)
{
}

template <class Key, class Element>
BTree<Key, Element>::DataNode::DataNode(Node *l)
:head(l->splitPoint->next), tail(l->tail)
{
	numElements = l->numElements / 2;
	left = l;
	right = l->right, 
	preHead->next = NULL;
}

template <class Key, class Element>
bool BTree<Key, Element>::DataNode::search(Key &k, Element &e) const
{
	NodeItem *temp = head;
	while(temp != NULL && k != temp->k)
		temp = temp->next;

	if(temp == NULL)
	{
		return false;
	}

	e = temp->e;
	return true;	
}

template <class Key, class Element>
bool BTree<Key, Element>::DataNode::insert(Node * &p, Node * &toAdd, Key &k, Element &e)
{
	bool toReturn;

	if(head == NULL)
	{
		head = new NodeItem();
		head->k = k;
		head->e = e;
		head->next = NULL;
	}
	else
	{
		NodeItem *temp = head;
		while(temp->next != NULL && k <= temp->k)
			temp = temp->next;

		if(k == temp->k)
		{
			return false;
		}

		NodeItem *toInsert = new NodeItem();
		toInsert->k = k;
		toInsert->e = e;
		if(temp == head)
		{
			toInsert->next = head;
			head = toInsert;
		}
		else if(temp == tail)
		{
			tail->next = toInsert;
			tail = toInsert;
		}
		else
		{
			toInsert->next = temp->next->next;
			temp->next = toInsert;
		}
	}
		
	toReturn = true;
	
	if(numElements > N)
	{
		Node *newRight = new DataNode(this);
		if(right != NULL)
		{
			right->left = newRight;
		}
		right = newRight;

		if(p == this)
		{
			p = new KeyNode(this, newRight);
		}
		else
		{
			toAdd = newRight;
		}
	}

	return toReturn;
}


--0-1283656024-1037173507=:30222--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021113074507.30655.qmail>