📄 type.h
字号:
/*
* File: type.h
* -------------
* Objects of the Type class are used to store and compare type
* information for variables, functions, and classes.
*/
#ifndef _H_type
#define _H_type
#include <stdlib.h>
#include "decllist.h"
class Scope;
class Declaration;
class Type {
public:
// These are the four kinds of Types we will be dealing with
typedef enum { Base, Array, Class, Function } KindOfType;
private:
KindOfType typeCode;
char *typeName;
union { // need different fields for diff kinds, so use union
struct { Type *elemType; } arrayType;
struct { char *name;
Scope *fields;
Type *superclass; } classType;
struct { Type *returnType;
DeclList *formals; } fnType;
} info;
public:
// public constants for the base Type objects for built-ins
static Type *intType, *doubleType, *boolType, *voidType,
*nullType, *stringType, *errorType;
// ctor for new types
Type(KindOfType kind, const char *nameForType);
// Intended to be used for printing the type in error messages
const char *ToString() { return typeName; }
// some trivial predicate accessors
bool IsBaseType() { return typeCode == Base; }
bool IsArrayType() { return typeCode == Array; }
bool IsClassType() { return typeCode == Class; }
bool IsFunctionType() { return typeCode == Function; }
bool IsEquivalentTo(Type *other);
// Operations specific to ArrayType objects
static Type *NewArrayType(Type *elemType);
Type *GetArrayElemType();
// Operations specific to ClassType objects
static Type *NewClassType(const char *name, Type *super);
const char *GetClassName();
Scope *GetClassScope();
// Operations specific to FunctionType objects
static Type *NewFunctionType(Type *returnType, DeclList *formals);
Type *GetFnReturnType();
DeclList *GetFnFormals();
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -