⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scope.h

📁 一个面向对像语言的编译器
💻 H
字号:
/*
 * File: scope.h
 * -------------
 * The Scope class will be used to manage scopes, sort of
 * table used to map identifier names to Declaration objects.
 * The ScopeStack class keeps a stack of Scope objects to handle the
 * nested scopes.
 */

#ifndef _H_scope
#define _H_scope

#include "hashtable.h"
/*#include "declaration.h"
#include "assert.h"
#define Assert assert*/
#define MaxNest 32

class Declaration;
class Type;
class ScopeStack ;



class Scope { 
  public:
   typedef enum {Global, Class, Function, Local} KindOfScope;

  private:
 
    KindOfScope scopeCode;
    Hashtable *table;
	Type *classType;
  public:
	  Declaration * NextDecla();
	  Declaration * FirstDecla();
    Scope(KindOfScope s);       // for local/global
    Scope(Declaration *fn);     // for fn
    Scope(Type *classType);     // for class

    bool IsGlobalScope()         { return scopeCode == Global; }
    bool IsLocalScope()          { return scopeCode == Local; }
    bool IsClassScope()          { return scopeCode == Class; }
    bool IsFunctionScope()       { return scopeCode == Function; }

    Type *GetClassType();        // only for class scopes
    void CopyFieldsFromParent(Scope *parent); // only for class scopes

    Declaration *Lookup(const char *identifier);
    bool Declare(Declaration *decl);

};
 
class ScopeStack {
  private:
    
    Scope *stack[MaxNest];
    int top;

  public:
	  Scope * GetClassScope();

    ScopeStack();

    typedef enum { Shallow, Deep } TypeOfLookup;

    Declaration *Lookup(const char *identifier, TypeOfLookup lk = Deep);
    bool Declare(Declaration *decl); 

    void PushScope(Scope *scope);
    void PopScope();

    Scope *GetCurrentScope();
};

#endif

⌨️ 快捷键说明

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