モジュール Edit

概要 Edit

  0
  1
  2
  3
  4
#spanend
#spandel
Module:
#spanend
    ModuleDecl ExternalModuleDecls ModuleDef
#spandel
  • モジュール == 1つのソースファイル
  • モジュールには1つのpublicな型と0個以上のprivateな型を定義できる
  • モジュールには1つのシンボルを定義できる
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 
 
 
 
 
 
 
 
-
|
|
|
!
 
 
 
 
 
 
 
 
 
 
-
|
|
|
!
 
 
 
 
 
-
|
|
|
!
 
 
 
 
module Project.A; // Project名前空間のAという名前のモジュールをこのソースファイルで定義することを宣言
 
#spandel
pod A // publicな型はモジュールの最後の名前と同一である必要がある
#spanend
#spanadd
pod A // モジュールの名前と同じ必要がある
#spanend
{
    B b;
    C c;
    int b;
};
#spandel
 
#spanend
#spandel
// privateな型は何個でも宣言できる
#spanend
#spandel
private pod B 
#spanend
#spandel
{
#spanend
    int x;
#spandel
};
#spanend
#spandel
private pod C
#spanend
#spandel
{
#spanend
    float x;
#spandel
};
#spanend
#spandel
 
#spanend

モジュール宣言 - module Edit

  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
ModuleDecl:
    "module" ModulePath ";"
    "prototype" "module" ModulePath ";"
 
ModulePath:
    NamespacePath "." ModuleName
 
NamespacePath:
    Namespace
    Namespace "." NamespacePath
 
Namespace:
    Identifier
 
ModuleName:
    Identifier
  • ソースファイルの何よりも先に記述するキーワード
  • 1階層以上の名前空間とこのソースファイルで定義する型の名前を続けて記述する
すべてを展開すべてを収束
  1
  2
 
 
module Hoge.Foo; // Hoge名前空間のFooという型をこのソースで記述します
module Foo; // エラー:名前空間がない

外部モジュール宣言 - import/using Edit

  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
#spanend
#spandel
ExternalModuleDecls:
#spanend
    ExternalModuleDecl
    ExternalModuleDecl ExternalModuleDecls
 
#spandel
ExternalModuleDecl:
#spanend
    ImportExternalModule
    UsingExternalModule
- プロトタイプモジュールにはprototypeを前に付ける。(プロトタイプモジュールの項を参照)
- プロトタイプモジュールは''publicな''定数・変数・関数・ユーザー定義型を宣言する。
- プロトタイプモジュールの関数の実装や定数の値はランタイムで設定される。
 
#spandel
ImportExternalModule:
#spanend
    "import" ModulePath ";"
#spanadd
#code(d,){{
#spanend
#spanadd
prototype module Project.Vector3; // プロトタイプモジュールの宣言
#spanend
 
#spandel
UsingExternalModule
#spanend
    "using" ModulePath ";"
#spanadd
pod Vector3
#spanend
#spanadd
{
#spanend
   float x;
   float y;
   float z;
   float length()const; // プロトタイプモジュールなので関数の実体は
#spanadd
};
#spanend

外部モジュール宣言 - import/using Edit

  • 外部のモジュールを使う宣言
  • importキーワードを使うと名前空間付きのフルパスで記述する必要がある。
  • usingキーワードを使うと名前空間を省略することができる
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 
 
 
 
 
-
|
|
!
 
module Project.A;
using Project.B;
import Project.C;
 
class A
{
  B b; // usingを使ったのでProject.Bの"Project."の部分が省略できる
  Project.C c; // importを使ったので省略ができない
};

    ホーム 一覧 検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS