typelist.h

来自「一个面向对像语言的编译器」· C头文件 代码 · 共 58 行

H
58
字号
/*
 *typelist.h
 *----------
 *typelist类,不需要修改此文件
 */
#ifndef _H_TypeList
#define _H_TypeList
#include "utility.h"

class Type;

class TypeList {

 private:
    Type * types[MaxDecla];
	int loc;
 public:
    // Create a new empty list
    TypeList() {loc=0;}

    // Returns count of elements currently in list
    int NumElements()
	{ return loc;}

    // Returns declaration at index in list. Indexing is 0-based.
    // Raises an assert if index is out of range.
    Type *Nth(int index)
	{ Assert(index >= 0 && index < loc);
	  return types[index];}

    // Inserts declaration at index, shuffling over others
    // Raises assert if index out of range
    void InsertAt(Type *d, int index)
	{ Assert(index >= 0 && index <= loc);
	  for(int i=loc+1;i>index;i--)
			types[i]=types[i-1];
	  types[index]=d;
	  loc++;
	}

    // Adds declaration to list end
    void Append(Type *d)
	{ 
		types[loc]=d;
		loc++;
	}

    // Removes declaration at index, shuffling down others
    // Raises assert if index out of range
    void RemoveAt(int index)
	{ Assert(index >= 0 && index < loc);
	  for(int i=index;i<loc;i++)
		types[i]=types[i+1];
	  loc--;
	}
};

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?