[go: up one dir, main page]

JPH06266561A - Method and system for inspecting type of program - Google Patents

Method and system for inspecting type of program

Info

Publication number
JPH06266561A
JPH06266561A JP5104593A JP5104593A JPH06266561A JP H06266561 A JPH06266561 A JP H06266561A JP 5104593 A JP5104593 A JP 5104593A JP 5104593 A JP5104593 A JP 5104593A JP H06266561 A JPH06266561 A JP H06266561A
Authority
JP
Japan
Prior art keywords
type
class
checking
program
variable
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
JP5104593A
Other languages
Japanese (ja)
Inventor
Masato Asami
真人 浅見
Yoichi Yamamoto
洋一 山本
Miyoko Namioka
美予子 浪岡
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hitachi Ltd
Original Assignee
Hitachi Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hitachi Ltd filed Critical Hitachi Ltd
Priority to JP5104593A priority Critical patent/JPH06266561A/en
Publication of JPH06266561A publication Critical patent/JPH06266561A/en
Pending legal-status Critical Current

Links

Landscapes

  • Devices For Executing Special Programs (AREA)

Abstract

(57)【要約】 【目的】強く型付けされたオブジェクト指向プログラミ
ング言語における型検査を効率よく行う方法を提供す
る。 【構成】データ管理システム120に格納されたクラス
定義121は、計算機システム10内のコンパイラ10
0でコンパイルされ、オブジェクト131、実行コード
133および型検査プログラム135が生成されて、該
オブジェクト131、実行コード133および型検査プ
ログラム135はオブジェクト管理システム130に格
納される。実行部110は、オブジェクト131を参照
しつつ型検査プログラム135を実行して型検査を行い
実行結果を出力する。
(57) [Abstract] [Purpose] To provide a method for efficiently performing type checking in a strongly typed object-oriented programming language. [Configuration] A class definition 121 stored in a data management system 120 is stored in a compiler 10 in a computer system 10.
0, the object 131, the execution code 133 and the type checking program 135 are generated, and the object 131, the execution code 133 and the type checking program 135 are stored in the object management system 130. The execution unit 110 executes the type checking program 135 while referring to the object 131, performs the type checking, and outputs the execution result.

Description

【発明の詳細な説明】Detailed Description of the Invention

【0001】[0001]

【産業上の利用分野】本発明は、強く型付けされたオブ
ジェクト指向プログラミング言語の型検査の方法に関す
る。
FIELD OF THE INVENTION The present invention relates to a method of type checking in a strongly typed object oriented programming language.

【0002】[0002]

【従来技術】プログラミング言語による表現・記述とい
う立場から、プログラム中に出現する特定の式が取りう
る値に関する制約として、プログラムの「型」が導入さ
れる。
2. Description of the Related Art From the standpoint of expression / description in a programming language, a "type" of a program is introduced as a restriction on the value that a specific expression appearing in the program can take.

【0003】本明細書で用いるオブジェクト指向プログ
ラミング言語など抽象データを扱うプログラミング言語
の型は、コンパイラに対して、コンパイルのための情報
(データの記憶領域の大きさなど)を知らせるためのも
のではなく、関数呼出やメッセージ送信などの整合性、
すなわち、プログラムの整合性を検査するための情報で
あることを明記しておく。
The type of programming language that handles abstract data, such as the object-oriented programming language used in this specification, is not intended to inform the compiler of information for compilation (size of data storage area, etc.). , Integrity of function call and message sending,
That is, it is specified that the information is for checking the consistency of the program.

【0004】また、プログラム中で実行される演算が適
正な型を持つデータに適用されるかどうかを検査する作
業を、「型検査」という。オブジェクト指向プログラミ
ング言語の型検査については、“岩波講座ソフトウエア
科学17 モデルと表現”(米澤明憲,柴山悦哉著、岩
波書店、1992年)pp.44〜61に詳述されてい
る。また、一般の型検査については、“コンパイラ
I”(A.V.エイホ,R.セシィ,J.D.ウルマン
共著、原田賢一訳、サイエンス社、1990年)pp.
417〜470に詳述されている。
The operation of checking whether the operation executed in the program is applied to the data having the proper type is called "type checking". For type checking of object-oriented programming languages, see "Iwanami Course Software Science 17 Models and Expressions" (Akinori Yonezawa, Etsushiya Shibayama, Iwanami Shoten, 1992) pp. 44-61. For general type checking, see “Compiler
I "(AV Eiho, R. Cethy, J. D. Ullman, Written by Kenichi Harada, Science, 1990) pp.
417-470.

【0005】この型検査には、静的型検査と動的型検査
の2種類がある。このうち、静的型検査は、プログラム
のコンパイル時に実行される。動的型検査は、ソースプ
ログラムをコンパイルしたコードに、型検査用のコード
を埋め込み、実行時に演算が適正な型を持つデータに適
用されるか否かを調べる検査である。
There are two types of type checking, static type checking and dynamic type checking. Of these, static type checking is executed when the program is compiled. The dynamic type check is a check for embedding a type checking code in a code obtained by compiling a source program and checking whether or not an operation is applied to data having an appropriate type at the time of execution.

【0006】プログラミング言語が強く型付けされてい
るとは、その言語の意味論として、コンパイラを通った
プログラムは、その言語が定める型検査に合格し、型安
全(適正でないデータに演算が適用されることはない)
であるということを保証することである。
A strongly typed programming language means that a program that has passed a compiler passes the type check defined by the language and is type-safe (the operation is applied to improper data). Nothing)
Is to guarantee that

【0007】従来の静的型検査(以下、静的型検査を型
検査と呼ぶ)は、コンパイラ内部の一つのルーチンとし
て実現されている。型検査は字句・構文解析部によって
生成された構文木に従って行われる。逆に言えば、字句
・構文解析部と独立に型検査を行うことはできない。
Conventional static type checking (hereinafter, static type checking is called type checking) is realized as one routine inside the compiler. The type check is performed according to the syntax tree generated by the lexical / syntactic analysis unit. Conversely, type checking cannot be performed independently of the lexical / syntactic analysis unit.

【0008】図2は、従来のオブジェクト指向プログラ
ミング言語のコンパイラにおける各フェーズを表したも
のである。200はコンパイラであり、クラス定義12
1を読み込み、メソッド実行コード133を伴うクラス
オブジェクト131を生成する。読み込んだクラス定義
121は、字句・構文解析部201によって構文木に変
換される。
FIG. 2 shows each phase in a conventional object-oriented programming language compiler. 200 is a compiler, and class definition 12
1 is read and the class object 131 with the method execution code 133 is generated. The read class definition 121 is converted into a syntax tree by the lexical / syntactic analysis unit 201.

【0009】この構文木に従い、型検査部202は、型
推論(プログラムの文面に与えられた、非明示な型に関
する情報を手がかりにして、文面中に現れる式の持ちう
る型を厳密な論理によって決定してゆくこと)を行い、
プログラムに型の誤りがないか検査する。もし、型の誤
り(適正でないデータに演算が適用されること)がなけ
れば、構文木は中間コード生成部203に渡され、中間
コードが生成される。
In accordance with this syntax tree, the type checking unit 202 uses type inference (information about the implicit type given in the text of the program as a clue, and uses strict logic to determine the types of expressions that appear in the text. Decide),
Check your program for typographical errors. If there is no type error (the operation is applied to invalid data), the syntax tree is passed to the intermediate code generation unit 203, and the intermediate code is generated.

【0010】中間コードは、コード最適化部204で最
適化処理を施され、コード生成部205で実行コードと
なる。一方、コンパイラのそれぞれのフェーズで解析さ
れた様々なクラス(所属する類)に関する情報は、クラ
スオブジェクトとして生成され、コード生成部205で
生成された実行コードをオブジェクトとしたメソッド実
行コード133とともに出力される。
The intermediate code is subjected to optimization processing by the code optimizing unit 204 and becomes an execution code by the code generating unit 205. On the other hand, information on various classes (classes) analyzed in each phase of the compiler is generated as a class object and is output together with the method execution code 133 in which the execution code generated by the code generation unit 205 is an object. It

【0011】[0011]

【発明が解決しようとする課題】このような従来の型検
査の方法では、次の様な場合に問題が起こる。
The conventional mold inspection method as described above has a problem in the following cases.

【0012】一つは、未定義の型を参照しているメソッ
ドの型検査である。
The first is type checking of a method that refers to an undefined type.

【0013】一般に、型検査の対象となるプログラムに
出現する型は、全て定義済みのものでなければならな
い。このために、そのメソッドを定義する前に、メソッ
ドが参照する型をクラスの定義に先だって全て定義しな
ければならないという定義順序の制約を設けたり、ファ
イルなどのコンパイル単位内に必ず参照された型が定義
されるという前提で、型変数を用いる方法などがとられ
ている。
Generally, all types appearing in a program subject to type checking must be defined. For this reason, before defining the method, there is a restriction on the definition order that all types referenced by the method must be defined prior to the definition of the class, or the type that is always referenced in a compilation unit such as a file is defined. Assuming that is defined, the method using type variables is taken.

【0014】しかし、一般にオブジェクト指向プログラ
ミング言語においては、型を宣言することなしにコンパ
イルすることが可能である。また、柔軟なオブジェクト
指向プログラミング環境の提供のために、クラス定義は
それぞれが独立していること、すなわち、定義順序やコ
ンパイル単位などを意識する必要がないことが望まし
い。
However, generally in an object-oriented programming language, it is possible to compile without declaring types. Also, in order to provide a flexible object-oriented programming environment, it is desirable that class definitions are independent of each other, that is, it is not necessary to be aware of the definition order or compilation unit.

【0015】したがって、参照している型が未定義であ
っても、とりあえずコンパイルを行い、参照している型
が定義されたとき、型検査を行い、プログラムの整合性
を検査する方法が考えられる。
Therefore, even if the referenced type is undefined, a method of compiling for the time being and performing type checking when the referenced type is defined to check the consistency of the program is conceivable. .

【0016】図3は、型の参照関係の例である。310
は、クラスtype1の定義であり、型type0を参照するメソ
ッドm11の定義311とメソッドm12の定義313をも
つ。同様に、320はクラスtype2の定義であり、型typ
e0を参照していないm21の定義321とtype0を参照する
メソッドm22の定義323をもつ。300はクラスtype0
の定義であり、メソッドm01の定義301とメソッドm02
の定義303をもつ。ここでtype0が未定義であったと
する。このとき、メソッド311、313、323の型
検査を行うことができない。そこで、とりあえず、この
3つのメソッドを型検査なしでコンパイルし、クラスty
pe0の定義300が行われたとき、型検査を行う。ここ
で問題なのは、メソッド311、313、323のコン
パイル時に行った字句・構文解析と全く同一の字句・構
文解析を、再び、型検査のときに行わなければならない
ということである。
FIG. 3 is an example of a type reference relationship. 310
Is a definition of the class type1 and has a definition 311 of a method m11 and a definition 313 of a method m12 that refer to the type type0. Similarly, 320 is the definition of the class type2, and the type typ
It has a definition 321 of m21 that does not refer to e0 and a definition 323 of a method m22 that refers to type0. 300 is class type0
Definition of method m01, definition 301 of method m01 and method m02
Has a definition 303. Here, it is assumed that type0 is undefined. At this time, the type checking of the methods 311, 313, and 323 cannot be performed. So, for the time being, compile these three methods without type checking, and
When the definition 300 of pe0 is made, type checking is performed. The problem here is that the lexical / syntactic analysis exactly the same as the lexical / syntactic analysis performed at the time of compiling the methods 311, 313, and 323 must be performed again at the time of type checking.

【0017】問題が起こるもう一つの場合として、クラ
スの更新(クラスの定義を変えること)に係わる型検査
がある。これは特に永続的オブジェクトを扱うシステ
ム、例えばオブジェクト指向データベースなどで大きな
問題となる。
Another case where problems occur is type checking involving class updates (changing class definitions). This is a big problem especially in systems that handle persistent objects, such as object-oriented databases.

【0018】前述の図3を用いて説明する。クラスtype
0の定義300を更新し、このために型type0の定義も更
新された場合を考える。この更新が矛盾なく行われたか
どうかを検査するためには、クラスtype0の定義300
の再コンパイルと型type0を参照していメソッド31
1、313、323の型検査を行う必要がある。
Description will be made with reference to FIG. Class type
Consider the case where the definition 300 of 0 is updated, and for this reason the definition of type type0 is also updated. To check whether this update is consistent, check the definition of class type0 300
Recompiling and referencing type type0 method 31
It is necessary to perform mold inspection of 1, 313 and 323.

【0019】従来の型検査の方法では、各メソッドの型
検査を字句・構文解析から行わなければならない。オブ
ジェクト指向データベースなど多くのクラスを管理する
システムでは、参照しているメソッドは非常に多くなる
と考えられ、これらをすべて、字句・構文解析から型検
査を行うのはかなりの負荷となる。
In the conventional type checking method, the type checking of each method must be performed by lexical / syntactic analysis. In a system that manages many classes such as an object-oriented database, it is considered that the number of methods that are referenced is extremely large, and performing type checking from lexical / syntactic analysis for all of these methods is a considerable load.

【0020】さらに問題が起こる場合として、メソッド
の再利用、特に、オブジェクト指向プログラミング言語
では標準的な機能となっている継承(あるクラスが、他
のクラスの変数およびメソッドをそのまま受け継ぐこ
と)に伴う型検査がある。
A further problem arises with the reuse of methods, in particular with inheritance, which is a standard feature of object-oriented programming languages (one class inherits variables and methods of another class as is). There is type inspection.

【0021】このとき、メソッドで使用されている、メ
ソッド外部で宣言された変数の型が、継承された先で変
化することがある。このため、メソッドは継承された先
で、プログラムの整合性が保てるかどうか、型検査を行
う必要がある。
At this time, the type of the variable used in the method and declared outside the method may change after being inherited. For this reason, the method must be type-checked at the inherited destination to see if the integrity of the program can be maintained.

【0022】図4は、メソッドの継承の様子を表してい
る。400はクラスtype0の定義であり、type00型の変
数Xを宣言している。401は、このメソッド外部で宣
言された変数Xを用いて定義されたメソッドm0である。
410はクラスtype1の定義であり、メソッド401を
クラスtype0から継承している。他に、メソッドm10とメ
ソッドm11もつ。クラスtype1の定義410では、変数X
は型type11と宣言されている。したがって、メソッド4
01は変数Xが型type11であってもプログラムの整合性
が保てるかどうか、型検査を行わなければならない。同
様に、420はクラスtype2の定義であり、メソッド4
01を継承し、他に、メソッドm2をもつ。変数Xは、型t
ype22として宣言されており、メソッド401は、変数X
の型をtype22として、型検査を行う必要がある。ここで
注意したいのは、クラスtype0の定義400におけるメ
ソッド401の型検査とクラスtype1の定義410にお
けるメソッド401の型検査とクラスtype2の定義42
0におけるメソッド401の型検査は、変数Xの型が異
なるだけで、他は全く同一である。しかし、それぞれの
型検査において、メソッド401の字句・構文解析から
行わなければならない。
FIG. 4 shows how a method is inherited. Reference numeral 400 denotes a definition of class type0, which declares a variable X of type00 type. 401 is a method m0 defined using a variable X declared outside this method.
Reference numeral 410 is a definition of class type1, and method 401 is inherited from class type0. In addition, it has method m10 and method m11. In the definition 410 of class type1, the variable X
Is declared as type type11. Therefore, method 4
01 must be type-checked to see if the program consistency can be maintained even if the variable X is of type type11. Similarly, 420 is the definition of class type2, and method 4
It inherits 01 and has a method m2. The variable X is of type t
It is declared as ype22, and method 401 is variable X
It is necessary to perform type checking with the type of as type22. It should be noted here that the type check of the method 401 in the definition 400 of the class type0 and the type check of the method 401 and the definition of the class type2 in the definition 410 of the class type1 42
The type check of the method 401 in 0 is exactly the same except that the type of the variable X is different. However, each type check must be performed from the lexical / syntactic analysis of method 401.

【0023】前述の3つの場合が示すように、すでにコ
ンパイルされたメソッドに対して型検査だけが必要な場
合にも、再び、字句・構文解析から行わなければならな
い。しかも、全く同一のメソッドの定義を何度も行わな
ければならないことが多いという問題が存在する。
As the above three cases show, even if only type checking is required for already compiled methods, it must be done again from lexical / parsing. Moreover, there is a problem in that it is often necessary to define exactly the same method many times.

【0024】本発明の目的は、強く型付けされたオブジ
ェクト指向プログラミング言語の型検査を効率よく行
う、さらに、詳しく述べれば、型検査をコンパイラのフ
ェーズから独立させるとともに、型検査の際に字句・構
文解析を行わないような型検査の方法を提供することに
ある。
An object of the present invention is to efficiently perform type checking of a strongly typed object-oriented programming language, and more specifically, to make the type checking independent of the compiler phase, and to make the lexical / syntax during the type checking. It is to provide a method of type checking that does not perform analysis.

【0025】本発明の他の目的は、コンパイルの際に、
クラス定義とは別に予め型の定義を宣言したりコンパイ
ルの順序を指定したりする必要がなく、強く型付けされ
たオブジェクト指向プログラミング言語のプログラマに
対する制約をできるだ少なくする方法を提供することに
ある。
Another object of the present invention is to compile
It is an object of the present invention to provide a method for reducing the restrictions on the programmer of a strongly typed object-oriented programming language without having to declare type definitions and specify the order of compilation separately from class definitions.

【0026】[0026]

【課題を解決するための手段】上記従来の問題点を考慮
して、本発明によれば、オブジェクト指向プログラミン
グ言語によって記述されたメソッドの定義および変数の
宣言を含むクラス定義をコンパイルするコンパイラを備
えた計算機システムにおいて、コンパイラは、クラス定
義により定義されるクラスの型に関する型情報を生成す
る型情報生成手段と、この型情報を保持する第1の保持
手段と、保持された型情報に基づいてメソッドの各々に
対して型検査を行なうための型検査プログラムを生成す
る型検査プログラム生成手段とを備えることができる。
In view of the above conventional problems, according to the present invention, there is provided a compiler for compiling a class definition including a method definition and a variable declaration written in an object-oriented programming language. In the computer system described above, the compiler is based on the type information generation means for generating type information about the type of the class defined by the class definition, the first holding means for holding this type information, and the held type information. A type check program generating means for generating a type check program for performing a type check for each of the methods can be provided.

【0027】さらに、前記システムは、コンパイラによ
り生成された型検査プログラムを保持する第2の保持手
段と、メソッドが参照すべき型に関する型情報を生成さ
れると、前記メソッドに対応する前記型検査プログラム
を前記第2の保持手段から取りだし、前記型に関する情
報に基づき実行する実行手段を備えることができる。
Further, the system, when second type holding means for holding the type checking program generated by the compiler and type information relating to the type to be referred to by the method are generated, the type checking corresponding to the method is performed. Execution means for extracting the program from the second holding means and executing it based on the information about the type can be provided.

【0028】[0028]

【作用】構文木に基づく型検査の手順は型検査プログラ
ムに記録されるため、その後の型検査においては、字句
・構文解析を行う必要がない。したがって、繰り返し型
検査を行う場合、型検査の効率が良くなる。
Since the type checking procedure based on the syntax tree is recorded in the type checking program, it is not necessary to perform the lexical / syntactic analysis in the subsequent type checking. Therefore, the efficiency of the mold inspection is improved when the repeated mold inspection is performed.

【0029】メソッド内部では確定しない型は、型変数
として扱われるため、様々な場合の型検査に柔軟に対応
することができる。
Since the type that is not determined inside the method is treated as a type variable, it is possible to flexibly deal with the type checking in various cases.

【0030】コンパイルと型検査が独立して行うことが
できるので、型検査によるプログラマへの制約が緩和さ
れる。
Since the compilation and the type checking can be performed independently, the restrictions imposed on the programmer by the type checking are relaxed.

【0031】[0031]

【実施例】以下、本発明の1実施例を図面を参照して説
明する。図1は、永続的オブジェクトを扱うシステムに
おける本発明の構成を表したものである。図5は、図1
におけるコンパイラ100の各フェーズの流れである。
DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS An embodiment of the present invention will be described below with reference to the drawings. FIG. 1 shows the configuration of the present invention in a system that handles persistent objects. FIG. 5 shows FIG.
The flow of each phase of the compiler 100 in FIG.

【0032】図1において、10は演算装置と記憶装置
をもつ計算機システムである。図1及び図5において、
120はファイルシステムやデータベースなどのテキス
トデータを管理することのできるシステムである。13
0は、オブジェクト指向データベースなどオブジェクト
を管理することのできるシステムである。121はクラ
ス定義であり、オブジェクトの構造や手続きを定義して
いる。これはプログラムに相当する。131はクラスオ
ブジェクトであり、そのクラスのインスタンスオブジェ
クトの生成器であり、クラス全体の様々を情報を管理す
る。133はメソッド実行コードであり、オブジェクト
がメッセージを受け取ったときに起動する手続きであ
る。135は、型検査プログラムであり、各メソッドに
対応している。133と135もオブジェクトであり、
クラスオブジェクト131の管理下にある。
In FIG. 1, reference numeral 10 is a computer system having an arithmetic unit and a storage device. 1 and 5,
Reference numeral 120 is a system capable of managing text data such as a file system and a database. Thirteen
0 is a system capable of managing objects such as an object-oriented database. Reference numeral 121 is a class definition, which defines the structure and procedure of the object. This corresponds to a program. Reference numeral 131 is a class object, which is a generator of an instance object of the class, and manages various information of the entire class. 133 is a method execution code, which is a procedure activated when an object receives a message. Reference numeral 135 denotes a type checking program, which corresponds to each method. 133 and 135 are also objects,
It is under the control of the class object 131.

【0033】図1において、コンパイラ100は、クラ
ス定義121を読み込み、クラスオブジェクト131を
生成する。この時、メソッド実行コードの他に型検査プ
ログラムも生成する。
In FIG. 1, the compiler 100 reads the class definition 121 and creates a class object 131. At this time, a type checking program is also generated in addition to the method execution code.

【0034】生成されたクラスオブジェクト131は1
30によって管理され、クラス名(型名)によって、そ
れぞれのクラスオブジェクトを呼び出すことができる。
クラス名と型名は同じであるので、型名によってその型
の定義情報があるクラスオブジェクトを得ることができ
る。
The generated class object 131 is 1
Each class object can be called by a class name (type name).
Since the class name and the type name are the same, it is possible to obtain the class object having the definition information of the type by the type name.

【0035】110は型検査プログラム実行部であり、
型検査プログラム135を実行し、135が対応するメ
ソッドの型検査を行う。型検査プログラムの実行に必要
な型の情報は型名に対応するクラスオブジェクトから得
る。もし、型検査プログラムが正しく実行できない場合
は、対応するメソッドに型の誤りが存在することを示
す。このとき、型検査プログラム実行部110は、型の
誤り情報112を出力する。このように、型検査プログ
ラム実行部は型検査プログラムを実行することによっ
て、型検査を行うことができる。したがって、型検査プ
ログラムをもつメソッドは、必要に応じて型検査を行う
ことが可能であり、その時、そのメソッドが定義されて
いるクラス定義の字句・構文解析を行う必要がない。
Reference numeral 110 denotes a type check program execution unit,
The type checking program 135 is executed, and the type checking of the method corresponding to 135 is performed. The type information required to execute the type checking program is obtained from the class object corresponding to the type name. If the type checking program cannot be executed correctly, it indicates that the corresponding method has a type error. At this time, the type check program execution unit 110 outputs the type error information 112. In this way, the type checking program execution unit can perform the type checking by executing the type checking program. Therefore, the method having the type checking program can perform the type checking as needed, and at that time, it is not necessary to perform the lexical / syntactic analysis of the class definition in which the method is defined.

【0036】クラスオブジェクト131、メソッド実行
コード133、型検査プログラム135がコンパイラの
どのフェーズで生成されるかを図5をもちいて説明す
る。
The phases of the compiler in which the class object 131, the method execution code 133, and the type checking program 135 are generated will be described with reference to FIG.

【0037】クラス定義121は、まず、字句・構文解
析部101によって構文木に変換される。この構文木を
解析し、文法規則と型推論規則の対応をもちいて型検査
プログラム生成部102で型検査プログラムを生成す
る。この部分は図2における従来のコンパイラ200の
型検査部203に相当する。しかし、型検査部203で
は、構文木に従って型推論を直接行っている。図5にお
ける、型検査プログラム生成部102では型推論そのも
のは行わずに、その型推論の方法を型検査プログラムと
して出力する。
The class definition 121 is first converted into a syntax tree by the lexical / syntactic analysis unit 101. This syntax tree is analyzed, and the type checking program generation unit 102 generates a type checking program using the correspondence between the grammar rules and the type inference rules. This portion corresponds to the type checking unit 203 of the conventional compiler 200 in FIG. However, the type checking unit 203 directly performs type inference according to the syntax tree. The type checking program generation unit 102 in FIG. 5 does not perform type inference itself, but outputs the type inference method as a type checking program.

【0038】構文木は、さらに、中間コード生成部10
3に渡され、中間コードを生成し、コード最適化部10
4で最適化処理を施され、コード生成部105によっ
て、メソッド実行コードとなる。コンパイラの一連の処
理において解析された様々な情報はクラスオブジェクト
としてオブジェクト生成部106によって出力される。
The syntax tree further includes the intermediate code generator 10
3, the intermediate code is generated, and the code optimization unit 10
The optimization processing is performed in 4, and the code generation unit 105 forms the method execution code. Various information analyzed in the series of processes of the compiler is output by the object generation unit 106 as a class object.

【0039】ここで、上述した実施例をさらに詳細に説
明するために前提となるクラスの定義方法とオブジェク
トの型について説明する。図6はオブジェクトの型の概
念図である。図7はクラスの定義例である。
Here, a class defining method and an object type, which are prerequisites for explaining the above-described embodiment in more detail, will be described. FIG. 6 is a conceptual diagram of object types. FIG. 7 shows an example of class definition.

【0040】図6において、オブジェクトの型は、その
オブジェクトにどのようなメッセージを送ることができ
るかというオブジェクトのインタフェースによって特徴
づけられる。このような型の定義を用いれば、型検査は
オブジェクトに正しくメッセージを送っているかどう
か、すなわち、メソッドの呼出が正しく行われるかどう
か−プログラムの整合性−の検査である。611、61
3はそれぞれメソッドの仕様であり、611はメソッド
名m01:であり、引数の型がtype2、戻り値の型がtype3で
あることを示す。同様に、613はメソッド名m02で、
引数無し、戻り値の型はtype1である。611と613
のようなメソッドが、クラスtype0において外部に公開
される形で定義されているとき、メソッドの仕様61
1、613の集合610を型type0の特徴と呼ぶ。オブ
ジェクト600が、型type0の特徴をもつとき、すなわ
ち、m01:やm02というメッセージを送ることができると
き、オブジェクト600は型type0であるという。逆
に、オブジェクト600が型type0として宣言されてい
るのであれば、オブジェクト600にメソッドの仕様6
15の様なメッセージを送ることは型の誤りとなる。
In FIG. 6, the type of an object is characterized by the object's interface of what messages can be sent to that object. With such a type definition, the type check is a check of whether the message is sent to the object correctly, that is, whether the method is called correctly-the integrity of the program. 611, 61
Reference numeral 3 is a method specification, 611 is a method name m01 :, and the argument type is type2 and the return value type is type3. Similarly, 613 is the method name m02,
There is no argument, and the return type is type1. 611 and 613
When a method such as is defined in the class type0 to be exposed to the outside, the method specification 61
A set 610 of 1, 613 is called a feature of type type0. An object 600 is said to be of type type0 when it has the characteristics of type type0, that is, when it can send the message m01: or m02. On the contrary, if the object 600 is declared as type type0, the method specification 6 is added to the object 600.
Sending a message like 15 is a typo.

【0041】図6で説明した型type0の特徴を定義した
ものが、図7のクラスtype0の定義である。図7におい
て、太字はプログラミング言語の予約語である。001
行において、このクラスの名前がtype0であることを宣
言している。002行は002行から012行までは、
クラスtype0のインスタンスオブジェクトに関する定義
であることを示す。003行はクラスtype0のインスタ
ンスオブジェクトがもつ変数の宣言で、変数Xは型type1
である。004行は以後の行で定義されたメソッドはオ
ブジェクトの外側から起動することができる、すなわ
ち、オブジェクト外部に公開されるメソッドであるとい
うことを表している。005行から009行までは、メ
ソッドm01:の定義である。005行はメソッドの名前が
m01:であり、引数x1の型はtype2、戻り値の型はtype3で
あることを示している。006行は、メソッド内で用い
る一時的な作業変数の宣言である。007行は、x1にメ
ッセージm2を送り、その結果を引数として、Xにメッセ
ージm1を送り、この結果をx2に代入するということを示
す式である。008行は、x2にメッセージm2を送り、そ
の結果をメソッドm01:の戻り値とするという意味の文で
ある。011行はメソッドm02の定義である。引数は持
たず、戻り値の型はtype1である。ただし、その詳細な
プログラムは省略している。以下、図中のクラス定義に
おいて“…”は省略を表すことにする。
The definition of the type type0 described in FIG. 6 is the definition of the class type0 in FIG. In FIG. 7, bold letters are reserved words of programming languages. 001
The line declares that the name of this class is type0. Line 002 is from line 002 to line 012,
Indicates that the definition is for an instance object of class type0. Line 003 is the declaration of the variable that the instance object of class type0 has, and variable X is type type1.
Is. Line 004 indicates that the method defined in the subsequent lines can be invoked from outside the object, that is, is a method exposed to the outside of the object. Lines 005 to 009 are the definition of the method m01 :. Line 005 is the name of the method
m01 :, indicating that the type of the argument x1 is type2 and the type of the return value is type3. Line 006 is a declaration of a temporary work variable used in the method. Line 007 is an expression indicating that the message m2 is sent to x1, the result is used as an argument, and the message m1 is sent to X, and the result is assigned to x2. The line 008 is a sentence meaning that the message m2 is sent to x2 and the result is used as the return value of the method m01 :. Line 011 is the definition of method m02. It has no arguments and the return type is type1. However, the detailed program is omitted. Hereinafter, “...” In the class definition in the figure, the omission is represented.

【0042】型検査プログラム及びその実行に必要な情
報を提供するクラスオブジェクトの構成を図8を用いて
詳細に説明する。
The structure of the type checking program and the class object that provides information necessary for its execution will be described in detail with reference to FIG.

【0043】図8はクラスオブジェクトの構成図であ
る。クラスオブジェクト131には、型検査プログラム
の実行に必要な、そのクラスによって定義された型の情
報が管理されている。801はクラス定義である。型検
査のときに型の誤りが見つかった場合、その誤りの位置
をクラス定義上で示すことができる。これはプログラマ
が誤りを訂正する際に有効である。803は変数表であ
る。この変数はオブジェクトの構造を示すものであり、
メソッドの外部で宣言されている。805はクラスオブ
ジェクトが表す型を参照しているクラスオブジェクトを
指す。クラスが更新されると影響を受けるクラスのこと
である。807は型階層情報である。オブジェクト指向
プログラミング言語では、継承機能などにより型に順序
をつけることがある。これを型階層という。型階層は型
T1であるオブジェクトが、必ず、型T2であるとき、T1≦
T2と定義することができる。このときT1はT2のサブタイ
プという。809はメソッド表である。メソッドの情報
が管理される。
FIG. 8 is a block diagram of a class object. The class object 131 manages the type information defined by the class, which is necessary for executing the type checking program. 801 is a class definition. If a type error is found during type checking, the position of the error can be indicated on the class definition. This is useful for programmers to correct errors. Reference numeral 803 is a variable table. This variable shows the structure of the object,
Declared outside the method. Reference numeral 805 indicates a class object that refers to the type represented by the class object. A class that is affected when the class is updated. Reference numeral 807 is type hierarchy information. In object-oriented programming languages, types may be ordered by the inheritance function. This is called a type hierarchy. Type hierarchy is type
If an object that is T1 is always of type T2, then T1 ≤
It can be defined as T2. At this time, T1 is called a subtype of T2. 809 is a method table. Method information is managed.

【0044】図9は、図8における変数表803の詳細
な構成図である。変数名をキーとして、その変数がどの
型として宣言されているか、そして、その宣言は、クラ
ス定義の何行目で行われているかを管理している。した
っがて、変数名901、型903、行番号905の項目
をもつ表である。
FIG. 9 is a detailed block diagram of the variable table 803 in FIG. Using the variable name as a key, it manages what type the variable is declared as, and what line of the class definition is made. Therefore, the table has the items of the variable name 901, the type 903, and the line number 905.

【0045】図10は、図8におけるメソッド表809
の詳細な構成図である。メソッド名1001をキーとし
てメソッドの仕様1003やメソッド実行コード13
3、型検査プログラム135を取り出せるようにしてい
る。1005はメソッドにおける型参照情報であり、こ
れは図8における型参照情報805の部分集合として表
現される。クラス間の型参照情報の他にメソッドレベル
での型参照情報を設けたのは、クラス更新の際の型検査
をできるだけ抑えようとしたためである。クラス間の型
参照情報だけでは、クラスに定義されたメソッド全てを
型検査の対象としなければならない。1007はメソッ
ド実行コードへのポインタ、1009は型検査プログラ
ムへのポインタである。
FIG. 10 shows the method table 809 shown in FIG.
3 is a detailed configuration diagram of FIG. Method specification 1003 and method execution code 13 using method name 1001 as a key
3. The type check program 135 can be taken out. 1005 is type reference information in the method, which is expressed as a subset of the type reference information 805 in FIG. The type reference information at the method level is provided in addition to the type reference information between classes, in order to suppress the type checking at the time of class update as much as possible. With only the type reference information between classes, all methods defined in a class must be subject to type checking. Reference numeral 1007 is a pointer to a method execution code, and 1009 is a pointer to a type checking program.

【0046】ここで、型検査プログラムの構成を図11
を参照して説明する。図11はメソッドの型検査プログ
ラム135の構成図である。型検査プログラムは、型変
数宣言部1110と型検査コード部1120からなる。
型変数宣言部はメソッド内部では型が確定できない外部
変数の型を型検査プログラム生成部が型変数として登録
する。したがって、外部変数名1111をキーとして型
検査プログラム生成部が生成した型変数1113を参照
する表となっている。
Here, the structure of the type checking program is shown in FIG.
Will be described with reference to. FIG. 11 is a configuration diagram of the method type checking program 135. The type checking program includes a type variable declaration section 1110 and a type checking code section 1120.
In the type variable declaration part, the type of the external variable whose type cannot be determined inside the method is registered as a type variable by the type check program generation part. Therefore, the table is a table that refers to the type variable 1113 generated by the type checking program generation unit using the external variable name 1111 as a key.

【0047】型検査コード部1120は、型検査の手順
を記述したものであり、例えば、型推論式などで実現す
る。行番号1123は型推論式が生成された文法要素の
クラス定義の行番号である。この行番号は、型推論式に
おいて、型の誤りが発見されたとき、その誤りの位置を
プログラマに知らせるものである。
The type check code section 1120 describes the type check procedure, and is realized by, for example, a type inference formula. Line number 1123 is the line number of the class definition of the grammar element for which the type inference expression was generated. This line number informs the programmer of the position of a type error when a type error is found in the type inference expression.

【0048】図11の型検査プログラムを生成する過程
を、図7のクラス定義と、図12の図7のクラス定義に
おいて定義されているメソッドに対応する型検査プログ
ラムの例を用いて説明する。図12において、1200
は、図7のクラスtype0の定義の005行から009行
において定義されたメソッドm01:の型検査プログラムで
ある。1210は型変数宣言部であり、1220は型検
査コード部である。型検査プログラムは構文解析に基づ
いて生成する。この様子を図7のクラス定義の行ごとに
説明する。
The process of generating the type checking program of FIG. 11 will be described with reference to the example of the type checking program corresponding to the method defined in the class definition of FIG. 7 and the class definition of FIG. In FIG. 12, 1200
Is a type checking program of the method m01: defined in lines 005 to 009 of the definition of the class type0 in FIG. 1210 is a type variable declaration part, and 1220 is a type check code part. The type checking program is generated based on the syntax analysis. This situation will be described for each line of the class definition in FIG. 7.

【0049】(1)005行 メソッドm01:は型type2の引数x1を入力とし、型type3の
オブジェクト出力とすることが解析される。この解析結
果をコンパイラの記号表(図示せず)に登録する。同様
に、 (2)006行 一時変数x2が型type2であることが解析され、記号表に
登録される。
(1) Line 005 It is analyzed that the method m01: inputs the argument x1 of the type type2 and outputs it as an object of the type type3. This analysis result is registered in the symbol table (not shown) of the compiler. Similarly, (2) Line 006: Temporary variable x2 is analyzed to be of type type2 and registered in the symbol table.

【0050】(3)007行 この行は、次の3つの式に分解することができる。 (a)引数x1にメッセージm2を送る。 (b)(a)の結果を引数として、変数Xにメッセージm
1:を送る。 (c)(b)の結果を一時変数x2に代入する。
(3) Line 007 This line can be decomposed into the following three expressions. (A) Send the message m2 to the argument x1. (B) Using the result of (a) as an argument, the message m is stored in variable X.
Send 1: (C) The result of (b) is substituted into the temporary variable x2.

【0051】この3つの式について、型検査プログラム
の生成の過程を説明する。
The process of generating the type checking program for these three expressions will be described.

【0052】(a)記号表を引き、引数x1は、型type2
であることが判明する。したがって、型検査は、型type
2のオブジェクトは、メッセージm2を送ることができ、
その結果、何らかのオブジェクトを出力するかどうかを
検査することになる。これを型推論式として表現すると
type2 => m2:→t1となる。引数の型はメソッド内部で
宣言されたものであるから、メソッドの外部がどう変更
されようとも、引数x1の型がtype2であることは不変で
ある。したがって、確定した値type2として表現する。
しかし、型type2のオブジェクトにメッセージm2を送っ
た結果、出力されるオブジェクトの型は、クラスtype2
の定義に依存するものである。したがって、型は確定で
きず、型変数t1とする。この型推論式と、この型推論式
がクラス定義の007行から生成されたことを記録する
ための行番号007を型検査プログラムの型検査コード
部1220に登録する。
(A) Draw a symbol table and the argument x1 is of type type2
Turns out to be Therefore, type checking is
2 objects can send message m2,
As a result, it will be checked whether to output any object. If we express this as a type inference expression
type2 => m2: → t1. Since the type of the argument is declared inside the method, the type of the argument x1 remains type2 no matter how the outside of the method is changed. Therefore, it is expressed as the fixed value type2.
However, as a result of sending message m2 to an object of type type2, the type of the output object is class type2
It depends on the definition of. Therefore, the type cannot be determined, and the type variable is t1. This type inference expression and the line number 007 for recording that this type inference expression was generated from line 007 of the class definition are registered in the type check code section 1220 of the type check program.

【0053】(b)変数Xは、メソッド外部の変数であ
るため、その型をメソッド内部で確定することはできな
い。そこで、変数Xの型を型変数t0として表現し、型変
数宣言部1210に外部変数名X、型変数t0として登録
する。この時の型推論式は、引数x1にメッセージm2を送
った結果のオブジェクトの型t1を用いて、t0 => m1::t
1→t2と表現する。これは、型t0のオブジェクトはメッ
セージm1:を送ることができ、その引数の型はt1で、出
力の型はt2であることを表す。この型推論式をそのクラ
ス定義における行番号007と共に、型検査コード部1
220に登録する。
(B) Since the variable X is a variable outside the method, its type cannot be determined inside the method. Therefore, the type of the variable X is expressed as a type variable t0 and registered in the type variable declaration unit 1210 as an external variable name X and a type variable t0. The type inference expression at this time is t0 => m1 :: t using the type t1 of the object resulting from sending the message m2 to the argument x1.
Expressed as 1 → t2. This means that an object of type t0 can send the message m1 :, its argument type is t1, and its output type is t2. This type inference expression together with the line number 007 in the class definition is used in the type check code part 1
Register 220.

【0054】(c)記号表から一時変数x2は、型type2
であることがわかる。一時変数は、メソッド内部で宣言
されるので、その型は確定している。したがって、変数
Xにメッセージm1:を送った結果、出力されたオブジェク
トの型t2は、type2のサブタイプであれば良いことにな
る。これをt2≦type2と表現し、行番号007と共に型
検査コード部1220に登録する。
(C) From the symbol table, the temporary variable x2 is of type type2
It can be seen that it is. Since the temporary variable is declared inside the method, its type is fixed. Therefore, the variable
As a result of sending the message m1: to X, the type t2 of the output object should be a subtype of type2. This is expressed as t2 ≦ type2 and registered in the type check code part 1220 together with the line number 007.

【0055】(4)008行 型type2である一時変数x2にメッセージm2を送り、その
結果をメソッドm01:の出力とする。型type2のオブジェ
クトにメッセージm2を送るという式に対しての型推論式
はすでに登録されているので、省略が可能である。本実
施例の型検査コード部1220では、省略を行ってい
る。したがって、型type2のオブジェクトにメッセージm
2を送った結果、出力されるオブジェクトの型はt1と言
うことになる。メソッドm01:の出力の型は記号表から、
型type3であることがわかるので、型t1はtype3のサブタ
イプであるという型推論式t1≦type3を行番号008を
付けて、型検査コード部1220に登録する。
(4) The message m2 is sent to the temporary variable x2 which is the 008 line type 2 and the result is the output of the method m01 :. The type inference expression for the expression that sends the message m2 to the object of type type2 is already registered, so it can be omitted. The type check code part 1220 of this embodiment is omitted. Therefore, the message m in the object of type type2
As a result of sending 2, the type of the output object is t1. From the symbol table, the output type of method m01:
Since it is known that the type is type3, the type inference expression t1 ≦ type3 that the type t1 is a subtype of type3 is added to the type check code part 1220 with a line number 008.

【0056】(5)009行 メソッドm01:の定義が終了したことがわかり、メソッド
m01:の実行コードと型検査プログラム1200を生成す
る。このように、構文解析に基づいて、メソッドごとに
型検査プログラムを生成し、クラスオブジェクトによっ
て管理する。
(5) Line 009 It is understood that the definition of the method m01: is completed, and the method
The execution code of m01: and the type checking program 1200 are generated. In this way, a type checking program is generated for each method based on the syntax analysis and managed by the class object.

【0057】次に、型検査プログラムを用いて、クラス
をコンパイルし、型検査を行う場合の処理手順を図13
の流れ図を参照して説明する。クラスをコンパイルし、
型検査を行うためには、コンパイルされるクラスが参照
する型がすべて定義されてなければならない。したがっ
て、参照する型を定義しているクラス定義はすでに、コ
ンパイルされているか、または、一緒にコンパイルされ
る必要がある。ここでは、参照し合う複数のクラスを一
緒にコンパイルすることを前提として説明を行う。
Next, FIG. 13 shows a processing procedure for compiling a class and performing type checking using a type checking program.
This will be described with reference to the flowchart of FIG. Compile the class,
In order to perform type checking, all types referenced by the compiled class must be defined. Therefore, the class definition defining the referencing type must already be compiled or compiled together. Here, the description will be given on the assumption that a plurality of classes that refer to each other are compiled together.

【0058】図13は、複数のクラス定義をコンパイル
する手順を示した流れ図である。ステップ1310で
は、各クラス定義をコンパイルする。各クラス定義のコ
ンパイル順序(定義順序)は任意である。この一つのフ
ェーズとして、各クラスに定義されている各メソッド定
義のコンパイルがある(ステップ1311)。ステップ
1311において、メソッドの実行コードを生成すると
ともに、型検査プログラム135を生成する。この時点
では、コンパイルされていないクラス定義がある、すな
わち、未定義の型が存在するために、型検査プログラム
を実行することはできない。
FIG. 13 is a flow chart showing the procedure for compiling a plurality of class definitions. In step 1310, each class definition is compiled. The compilation order (definition order) of each class definition is arbitrary. As one of the phases, there is compilation of each method definition defined in each class (step 1311). In step 1311, the method execution code is generated and the type checking program 135 is generated. At this point, the type checking program cannot run because there are uncompiled class definitions, that is, there are undefined types.

【0059】コンパイルされた各クラスは、継承処理が
施され(ステップ1302)、各クラスオブジェクトを
生成する(ステップ1303)。クラスオブジェクトは
それぞれの型の情報を管理しているため、ステップ13
03が終了すると、ステップ1311において生成した
型検査プログラム135が実行可能となる。そこで、ク
ラスオブジェクトを参照しながら、型検査プログラムを
実行し、各クラスに定義されたメソッドの型検査を行う
(ステップ1304)。この型検査の結果を判定し(ス
テップ1305)、型の誤りが存在しなければ終了(ス
テップ1307)、型の誤りが存在するならば、エラー
メッセージの出力などの誤り処理を行い(ステップ13
06)終了する。
Each compiled class is subjected to inheritance processing (step 1302) and each class object is generated (step 1303). Since the class object manages the information of each type, step 13
When 03 ends, the type checking program 135 generated in step 1311 can be executed. Therefore, the type checking program is executed while referring to the class object to check the type of the method defined in each class (step 1304). The result of this type check is determined (step 1305), and if there is no type error, the process ends (step 1307). If there is a type error, error processing such as output of an error message is performed (step 13).
06) Finish.

【0060】図13のステップ1304の型検査、すな
わち、型検査プログラムの実行方法の一例を上述した図
12の型検査プログラム1200を中心にして説明す
る。型検査プログラム1200は、図7のメソッドm01:
の定義から生成したものであり、型type1、型type2、型
type3を参照している。したがって、図12の型検査プ
ログラムを実行するためには、クラスtype1、クラスtyp
e2、クラスtype3の定義がコンパイルされている必要が
ある。ただし、これらのクラスの定義が、図7のクラス
type0の定義よりも先である必要はない。
An example of the method of executing the type checking of step 1304 of FIG. 13, that is, the method of executing the type checking program will be described with a focus on the type checking program 1200 of FIG. 12 described above. The type checking program 1200 uses the method m01:
It is generated from the definition of, type type1, type type2, type
Refers to type3. Therefore, in order to execute the type checking program of FIG. 12, class type1 and class typ
The definitions of e2 and class type3 need to be compiled. However, the definition of these classes is
It need not precede the definition of type0.

【0061】クラスtype1、クラスtype2、クラスtype3
の定義を図14に示した。1401はクラスtype1、1
403はクラスtype2、1405はクラスtype3の定義で
ある。クラスtype3の定義1405の002行はクラスt
ype3のスーパークラスがクラスtype2であること表し、
クラスtype3はクラスtype2の性質を継承する。
Class type1, class type2, class type3
The definition of is shown in FIG. 1401 is class type1, 1
403 is a definition of class type2, and 1405 is a definition of class type3. 002 line of definition 1405 of class type3 is class t
Indicates that the superclass of ype3 is class type2,
Class type3 inherits the properties of class type2.

【0062】図14のクラスtype1、type2、type3の定
義をコンパイルした結果得られる型に関する情報は、図
15の型名とその型のオブジェクトがインタフェースと
してもつメソッドの仕様の対1510と、型階層の情報
1520である。これらはクラス(型)別にクラスオブ
ジェクトによって管理されるが、説明の便宜上、一つの
図にまとめた。図15の1510において、図14の1
401のクラス定義から、型名がtype1、インタフェー
スとしてメソッドm1:をもち、その引数のオブジェクト
のはtype2であり、出力されるオブジェクトの型はtype3
であるような型が定義される。図14の1403のクラ
ス定義からは、型名がtype2、インタフェースとしてメ
ソッドm2をもち、出力されるオブジェクトの型はtype3
であるような型が定義され、さらに、図14の1405
のクラス定義からは、型名がtype3、インタフェースと
してメソッドm2とm3をもち、メソッドm2は、型type2か
ら継承されたものであり、メソッドm3は、型type2のオ
ブジェクトを出力するような型が定義される。
The information on the types obtained as a result of compiling the definitions of the classes type1, type2, and type3 in FIG. 14 is the type name in FIG. 15 and the pair of specification 1510 of the method that the object of that type has as an interface, and the type hierarchy. This is information 1520. These are managed by class objects for each class (type), but they are summarized in one figure for convenience of explanation. In 1510 of FIG. 15, 1 in FIG.
From the class definition 401, the type name is type1, the method has m1: as an interface, the argument object is type2, and the output object type is type3.
A type is defined such that From the class definition 1403 in FIG. 14, the type name is type2, the method m2 is an interface, and the type of the output object is type3.
14 is defined in FIG.
From the class definition of, the type name is type3, it has methods m2 and m3 as interfaces, method m2 is inherited from type type2, and method m3 defines a type that outputs an object of type type2. To be done.

【0063】また、これらの型の定義から、型type2の
オブジェクトと型type3のオブジェクトにはメッセージm
2を送ることができるが、メッセージm3を送ることがで
きるのは型type3のオブジェクトだけであることがわか
る。このことは、型type2のオブジェクトが現れること
ができるところには、型type3のオブジェクトを用いて
もかまわないことを表している。しかし、その逆はでき
ない。このとき、type3はtype2のサブタイプであり、図
15の1520のように表現する。
From the definition of these types, the message m is assigned to the objects of type type2 and type3.
It turns out that 2 can be sent, but message m3 can only be sent by objects of type type3. This means that you can use an object of type type3 where an object of type type2 can appear. But the opposite is not possible. At this time, type3 is a subtype of type2 and is expressed as 1520 in FIG.

【0064】では、型検査プログラムの実行の手順を図
16の流れ図に基づき、上述の図11を参照して説明す
る。型検査プログラムの実行が開始(ステップ160
1)されると、まず、型変数宣言部1110の型変数に
型を代入する(ステップ1603)。代入される型は、
外部変数名1111で示される変数が、型検査を行うと
きに宣言されている型である。この情報は、型検査プロ
グラム実行部が起動されるときに外部から渡される。型
変数が代入されると、型検査コード部1120の型推論
式1121を実行する(ステップ1611)。
Now, the procedure of executing the type checking program will be described with reference to the above-mentioned FIG. 11 based on the flowchart of FIG. Execution of the type checking program starts (step 160).
Then, the type is first assigned to the type variable of the type variable declaration unit 1110 (step 1603). The type to be assigned is
The variable indicated by the external variable name 1111 is the type declared when performing the type check. This information is passed from outside when the type checking program execution unit is started. When the type variable is substituted, the type inference expression 1121 of the type check code unit 1120 is executed (step 1611).

【0065】この実行が正常に終了したかどうか判断
(ステップ1613)し、正常終了であれば、次の型推
論式に移る。もし、実行エラーが起こった場合は、実行
エラーの内容からエラーの原因を解析し、クラス定義で
の行番号とともに記録する(ステップ1615)。ステ
ップ1611、ステップ1613及びステップ1615
を全ての型推論式が実行されるまで繰り返す(161
0)。全ての型推論式の実行が終了した後、ステップ1
615で記録された実行エラーが存在するかを調べる
(ステップ1605)。もし、実行エラーが存在しない
のであれば、型の誤りが無いという情報を返して終了す
る(ステップ1607)。実行エラーが存在すれば、ス
テップ1615で記録された情報を型の誤り情報として
返し、終了する(ステップ1609)。
It is judged whether or not this execution is normally completed (step 1613), and if it is normally completed, the process proceeds to the next type inference expression. If an execution error occurs, the cause of the error is analyzed from the content of the execution error and recorded together with the line number in the class definition (step 1615). Step 1611, Step 1613 and Step 1615
Is repeated until all type inference expressions are executed (161
0). Step 1 after execution of all type inference expressions
It is checked whether the execution error recorded in 615 exists (step 1605). If there is no execution error, the information that there is no type error is returned and the process ends (step 1607). If there is an execution error, the information recorded in step 1615 is returned as pattern error information and the process ends (step 1609).

【0066】図16の流れ図で説明した型検査プログラ
ムの実行方法を、例を用いて具体的に説明する。例は、
図12の型検査プログラムを、図7のクラスtype0の定
義における変数の型宣言に基づいて、実行する過程であ
る。なお、図7のクラス定義はコンパイル済みであり、
図7の003行において、変数Xが、型type1であること
は、クラスtype0のクラスオブジェクトによって管理さ
れている。また、参照している型に関する情報は、図1
5を参照する。ただし、実際はクラスオブジェクトによ
って管理されている。
The method of executing the type checking program described in the flow chart of FIG. 16 will be specifically described by using an example. An example is
This is a process of executing the type checking program of FIG. 12 based on the variable type declaration in the definition of the class type0 of FIG. The class definition in Figure 7 has been compiled,
In line 003 of FIG. 7, the fact that the variable X is of type type1 is managed by the class object of class type0. See also Figure 1 for information about referenced types.
See 5. However, it is actually managed by the class object.

【0067】図12において、型検査プログラムの実行
は、まず、型変数宣言部1210に宣言されている型変
数の値を外部変数名を用いて確定する。型変数t0は、そ
の外部変数名Xを用いて、クラスtype0のクラスオブジェ
クトから、値type1が代入される。
In the execution of the type check program in FIG. 12, first, the value of the type variable declared in the type variable declaration unit 1210 is determined using the external variable name. The type variable t0 is assigned the value type1 from the class object of the class type0 using the external variable name X.

【0068】次に、型検査コード部1220の各型推論
式を並びの順に実行する。型推論式type2=>m2:→t1
は、まず、型名type2をもちいて、メッセージm2によっ
て起動されるメソッドm2を調べる。図15の1510か
ら、型名type2の型はm2というメソッドをもち、出力の
オブジェクトの型がtype3であることがわかる。よっ
て、型変数t1にtype3を代入する。次に型推論式t0=>m
1::t1→t2を実行する。型変数t0にはtype1、t1にはtyp
e3が代入されているので、型名type1をもちいて、引数
として型type3のオブジェクトをとるようなメソッドm1:
を調べる。同様に図15の1510から型変数t2にtype
3を代入する。ここで図15の1510の型名type1のメ
ソッドm1:の仕様は、引数として型type2のオブジェクト
をとることになっている。しかし、図15の1520の
型階層から、型type3は型type2のサブタイプであるの
で、引数として型type3のオブジェクトをとることは誤
りではない。
Next, the type inference expressions of the type check code part 1220 are executed in the order of arrangement. Type inference expression type2 => m2: → t1
First looks up the method m2 invoked by the message m2 using the type name type2. It can be seen from 1510 in FIG. 15 that the type of type name type2 has a method m2 and the type of the output object is type3. Therefore, type3 is assigned to the type variable t1. Then type inference expression t0 => m
1 :: t1 → t2 is executed. Type1 for type variable t0, typ for t1
Since e3 is assigned, method m1: which uses the type name type1 and takes an object of type type3 as an argument.
Find out. Similarly, from 1510 in FIG. 15 to type variable t2 type
Substitute 3 Here, the specification of the method m1: of the type name type1 in 1510 of FIG. 15 is to take an object of the type type2 as an argument. However, from the type hierarchy of 1520 in FIG. 15, since the type type3 is a subtype of the type type2, it is not an error to take an object of the type type3 as an argument.

【0069】次に型推論式t2≦type2を実行する。型変
数t2にはtype3が代入されているので、図15の152
0より、正しく実行できる。型推論式t1≦type3は、型
変数t1にtype3が代入されているのでこの式も正しい。
したがって、図12の型検査プログラムは図7のクラス
定義においては、誤りなく実行することができる。すな
わち、図7のクラス定義のメソッドm01:の定義には型の
誤りがなく、プログラムの整合性が保証される。
Next, the type inference expression t2 ≦ type2 is executed. Since type3 has been assigned to the type variable t2, 152 in FIG.
It can be executed correctly from 0. The type inference expression t1 ≦ type3 is also correct because type3 is assigned to the type variable t1.
Therefore, the type checking program of FIG. 12 can be executed without error in the class definition of FIG. That is, there is no type error in the definition of the method m01: of the class definition of FIG. 7, and the consistency of the program is guaranteed.

【0070】本発明の型検査の方法は、継承処理によっ
てプログラムの整合性を保つことができるかどうかの検
査にも有効である。次に、継承処理に伴う型検査の方法
を図17の流れ図と図18のクラス定義の例を用いて説
明する。
The type checking method of the present invention is also effective for checking whether the consistency of programs can be maintained by inheritance processing. Next, a method of type checking associated with inheritance processing will be described with reference to the flowchart of FIG. 17 and the example of class definition of FIG.

【0071】図18はクラスtype4の定義である。00
2行でクラスtype0はクラスtype4のスーパークラスであ
ることを宣言している。したがって、クラスtype4はク
ラスtype0で定義されたメソッドm01:などを継承する。
上述したように、メソッドm01:は外部変数Xを参照す
る。クラスtype0では、変数Xは型type1として宣言され
ている。この宣言のもとでは、メソッドm01:はプログラ
ムの整合性が保証されることは上述した通りである。し
かし、クラスtype4では、変数Xは型type2として宣言さ
れている(図18の004行)。このとき、メソッドm0
1:のプログラムの整合性の検査が必要となる。このプロ
グラムの整合性の検査を、型検査プログラムをもちいる
ことにより、メソッドの再コンパイルをすることなく、
行うことができる。ただし、図17の流れ図で説明する
継承処理に伴う型検査は、すでに、他のクラスはコンパ
イルされ、クラスオブジェクトとして管理されている中
に、新たなクラスを定義し、コンパイルするという状況
を前提としている。図13の流れ図で説明した複数のク
ラスをコンパイルする場合、継承処理に伴う型検査は、
他の型検査と同じように、継承処理の後、図13のステ
ップ1304で行う。
FIG. 18 shows the definition of class type4. 00
In line 2 we declare that class type0 is a superclass of class type4. Therefore, the class type4 inherits the method m01: etc. defined in the class type0.
As described above, the method m01: refers to the external variable X. In class type0, variable X is declared as type type1. As described above, under this declaration, the method m01: guarantees program consistency. However, in class type4, variable X is declared as type type2 (line 004 in FIG. 18). At this time, the method m0
It is necessary to check the consistency of the program of 1 :. By using a type checking program, you can check the integrity of this program without recompiling the method.
It can be carried out. However, the type check involved in the inheritance process described in the flowchart of FIG. 17 is based on the premise that a new class is defined and compiled while other classes are already compiled and managed as class objects. There is. When compiling multiple classes described in the flow chart of FIG. 13, the type checking involved in inheritance processing is
As with other type checks, after the inheritance process, step 1304 of FIG. 13 is performed.

【0072】クラスtype0のメソッドm01:の型検査プロ
グラム(図12)はすでに生成されている。この型検査
プログラムを用いて、クラスtype4に継承されたメソッ
ドm01:のプログラムの整合性の検査、すなわち、型検査
を行う。
The type checking program (FIG. 12) of the method m01: of the class type0 has already been generated. Using this type checking program, the consistency of the program of the method m01: inherited by the class type4, that is, the type checking is performed.

【0073】図17において、まず、クラスtype0のク
ラスオブジェクトから、継承するメソッドm01:の型検査
プログラム(図12)を得る(ステップ1701)。型
検査プログラムの型変数宣言部(図12の1210)か
ら、継承先であるクラスtype4において外部変数が再宣
言されているかを調べる。再宣言されていなければ、そ
のまま継承処理を行う(ステップ1707)。クラスty
pe4では、変数Xが型type2として再宣言されているの
で、図12の1210の型変数t0に型type2を代入する
(ステップ1703)。
In FIG. 17, first, the type checking program (FIG. 12) of the inherited method m01: is obtained from the class object of class type0 (step 1701). From the type variable declaration part (1210 in FIG. 12) of the type checking program, it is checked whether the external variable is redeclared in the class type4 which is the inheritance destination. If it has not been redeclared, the inheritance process is performed as it is (step 1707). Class ty
In pe4, since the variable X is redeclared as the type type2, the type type2 is assigned to the type variable t0 of 1210 in FIG. 12 (step 1703).

【0074】この後、上述した通り、図12の型検査コ
ード部1220の型推論式を順に実行する(ステップ1
704)。そして、実行の結果、型の誤りの有無を調べ
(ステップ1705)、無ければ継承処理(ステップ1
707)を、あれば誤り処理(ステップ1706)を行
い、継承処理を終了する。この場合は、図12の型推論
式t0=>m1::t1→t2が正しく実行できない。なぜなら
ば、型変数t0には型type2が代入されており、型type2は
m1:というメッセージを送ることができないことが、図
15から判明するからである。したがって、型の誤りが
存在し、誤り処理として、型推論式t0=>m1::t1→t2に
付けられた行番号007と共にエラーメッセージを出力
する。したがって、クラスtype0からクラスtype4へのメ
ソッドm01:の継承は正しく行われないことがわかる。
Thereafter, as described above, the type inference expressions of the type check code section 1220 of FIG. 12 are sequentially executed (step 1
704). Then, as a result of the execution, the presence or absence of a type error is checked (step 1705).
707), if any, error processing (step 1706) is performed, and the inheritance processing ends. In this case, the type inference expression t0 => m1 :: t1 → t2 in FIG. 12 cannot be correctly executed. Because the type variable t0 is assigned the type type2, and the type type2 is
This is because it is found from FIG. 15 that the message m1: cannot be sent. Therefore, there is a type error, and as an error process, an error message is output together with the line number 007 attached to the type inference expression t0 => m1 :: t1 → t2. Therefore, it can be seen that the inheritance of the method m01: from the class type0 to the class type4 is not performed correctly.

【0075】さらに本発明の型検査の方法はクラス更新
(クラス定義の変更)におけるプログラムの整合性の検
査にも有効である。クラスの更新を行ったとき、そのク
ラスを参照しているクラスに影響を与える場合が多い。
その影響によって、影響を与えられたクラスのプログラ
ムの整合性が保証できるのかどうかを検査する必要があ
る。もし、プログラムの整合性が保証できないのであれ
ば、クラスの更新をやり直すなり、影響を与えたクラス
を更新するなどの必要があるからである。この検査は、
永続的オブジェクトを扱うシステムにおいては、より重
大なものとなる。
The type checking method of the present invention is also effective for checking the consistency of programs in class updating (class definition change). When updating a class, it often affects the class that refers to the class.
It is necessary to check whether or not the effect can guarantee the integrity of the program of the affected class. If the integrity of the program cannot be guaranteed, it is necessary to update the class again and update the affected class. This test is
It becomes even more critical in systems that deal with persistent objects.

【0076】このクラス更新におけるプログラムの整合
性の検査を型検査プログラムを用いて行うことにより、
効率よく行うことができる。なぜならば、影響を受ける
各クラスを再びコンパイルすることなく、すでに生成さ
れている型検査プログラムを実行するだけでよいからで
ある。
By checking the consistency of the program in this class update using the type checking program,
It can be done efficiently. This is because it is only necessary to run the type checker program that has already been generated without recompiling each affected class.

【0077】では、このクラス更新における型検査の方
法を、図19の流れ図に従い、図7のクラスtype0及び
図15のクラスtype1,type2,type3の定義をもちいて
説明する。図14のクラスtype1の定義1401を更新
する。更新の内容は004行の引数xの型type2をtype3
に修正するというものである。図19において、まず、
更新したクラスtype1の定義をコンパイルする(ステッ
プ1901)。コンパイルが終了した時点でクラスtype
1を参照しているクラスがあるかどうかを調べる(ステ
ップ1902)。クラスの参照情報は、それぞれのクラ
スオブジェクトで管理されている。更新したクラスtype
1を参照しているクラスがないのであれば、更新による
影響はないので終了する(ステップ1905)。
Now, the type checking method in the class update will be described with reference to the flow chart of FIG. 19 by using the definitions of the class type0 of FIG. 7 and the classes type1, type2 and type3 of FIG. The definition 1401 of the class type1 in FIG. 14 is updated. The content of the update is the type3 of the argument x of line 004
It is to be corrected to. In FIG. 19, first,
The updated definition of class type1 is compiled (step 1901). Class type at the end of compilation
It is checked whether there is a class that refers to 1 (step 1902). The reference information of the class is managed by each class object. Updated class type
If there is no class that refers to 1, the update is not affected and the process ends (step 1905).

【0078】しかし、更新したクラスtype1を参照して
いるクラスがあるのであれば、参照しているクラスすべ
てについて、プログラムの整合性の検査を行う(ステッ
プ1910)。どのクラスも型の誤りがないかどうかを
調べ(ステップ1903)、なければ、クラスtype1の
更新は正しく行われたことになり、終了する(ステップ
1905)。一つでも誤りが存在すれば、クラスtype1
の更新は正しく行えないために、更新の取消など誤り処
理を行い(ステップ1920)、終了する(ステップ1
905)。
However, if there is a class that refers to the updated class type1, the consistency of the program is checked for all the referenced classes (step 1910). Whether or not any class has a type error is checked (step 1903), and if there is no type error, it means that the update of the class type1 has been correctly performed, and the process ends (step 1905). If even one error exists, class type1
Cannot be updated correctly, error processing such as cancellation of update is performed (step 1920), and the process ends (step 1).
905).

【0079】図20は、クラスtype0、type1、type2、t
ype3の参照関係をグラフとして表したものである。節は
クラスを表す。すなわち、節2001はクラスtype1
を、節2002はクラスtype2を、節2003はクラスt
ype3を、節2004はクラスtype0を表す。矢印は参照
関係を表し、矢印の方向は影響を与える方向である。例
えば節2001のクラスtype1を更新すると、節200
4のクラスtype0に影響を与える。矢印の方向を逆に読
めば、クラスtype0はクラスtype1を参照しているという
ことになる。
FIG. 20 shows classes type0, type1, type2, and t.
This is a graph showing the reference relationship of ype3. Sections represent classes. That is, section 2001 is of class type1
, Section 2002 is class type2, Section 2003 is class t
ype3 and section 2004 represent class type0. The arrow indicates the reference relationship, and the direction of the arrow is the influencing direction. For example, if you update the class type1 in section 2001,
Affects class 0 of class 4. If you read the arrow in the opposite direction, it means that class type0 refers to class type1.

【0080】上述したとおり、クラスtype0はクラスtyp
e1を参照しているので、クラスtype1の更新によって影
響を受ける。したがって、クラスtype0は、プログラム
の整合性の検査を行わなければならない。ここで、図1
9にもどり、ステップ1910の参照しているクラスの
プログラムの整合性の検査の過程をクラスtype0の場合
を用いて説明する。まず、クラスtype0の情報を得る
(ステップ1911)。これは、クラスtype0のクラス
オブジェクトを得ることである。
As described above, the class type0 is the class typ
As it refers to e1, it is affected by the update of class type1. Therefore, class type0 must perform a program consistency check. Here, FIG.
Returning to step 9, the process of checking the consistency of the program of the referenced class in step 1910 will be described using the case of class type0. First, information on class type0 is obtained (step 1911). This is to get a class object of class type0.

【0081】次に、type1を参照しているすべてのメソ
ッドの型検査プログラムを得る(ステップ1912)。
そして、それぞれについて型検査プログラムを実行する
(ステップ1913)。実行の結果を調べ(ステップ1
903)、型の誤りがあれば、そのメソッドはクラスty
pe1の更新によって、プログラムの整合性を保てなくな
ったことを表す。したがって、誤り処理を行い(ステッ
プ1920)、次のメソッドの検査に進む。クラスtype
0のメソッドm01:は、クラスtype1を参照するが、上述し
たクラスtype1の更新によって、プログラムの整合性が
破壊されることはない。図12のメソッドm01:の型検査
プログラムにおいて、クラスtype1を参照している型推
論式はt0=>m1::t1→t2であり、型変数t0には型type1
が、型変数t1には型type3が代入されている。クラスtyp
e1におけるメソッドm1:の引数がtype3に変わっても、正
しく実行することができる。
Next, the type checking programs of all the methods that refer to type1 are obtained (step 1912).
Then, the type checking program is executed for each (step 1913). Examine the results of the execution (step 1
903), if the type is incorrect, the method is class ty
Indicates that the program integrity could not be maintained due to the update of pe1. Therefore, error processing is performed (step 1920) and the process proceeds to the inspection of the next method. Class type
The method m01: of 0 refers to the class type1, but the update of the class type1 does not destroy the program consistency. In the type checking program for the method m01: in FIG. 12, the type inference expression referencing the class type1 is t0 => m1 :: t1 → t2, and the type variable t0 has the type type1.
However, the type type3 is assigned to the type variable t1. Class typ
Even if the argument of the method m1: in e1 changes to type3, it can be executed correctly.

【0082】オブジェクト指向プログラム言語では、型
をパラメタで表現するクラスの定義方法が提供されてい
る場合がある。例えば、要素の型をパラメタとしてリス
トのクラスを定義する。このクラスは、要素の型を定め
て、整数のリスト、文字列のリストなどとして使用す
る。一つのリストのクラスの定義によって、様々な型の
要素をもつリストのクラスを生成することになる。
The object-oriented programming language may provide a method of defining a class that represents a type with parameters. For example, define a list class with the element type as a parameter. This class defines the element type and uses it as a list of integers, a list of strings, etc. A single list class definition will generate a list class with various types of elements.

【0083】図21は、型をパラメタで表現するクラス
定義の例である。001行は型$typeをパラメタとした
クラスtype5($type)の定義であることを表している。太
字はプログラミング言語の予約語である。002行、0
03行は図7において説明した通りである。004行は
メソッドm5:が引数x1をとり、型type3のオブジェクトを
出力することを表す。ただし、引数x1の型はパラメタ$t
ypeである。005行はメソッドm5:の本体であり、引数
x1にメッセージm2を送った結果をメソッドの出力として
返す。
FIG. 21 is an example of a class definition in which a type is expressed by parameters. Line 001 represents the definition of class type5 ($ type) with type $ type as a parameter. Bold letters are reserved words for programming languages. 002 line, 0
Line 03 is as described in FIG. Line 004 represents that the method m5: takes an argument x1 and outputs an object of type type3. However, the type of argument x1 is parameter $ t
It is ype. Line 005 is the body of method m5:
The result of sending the message m2 to x1 is returned as the output of the method.

【0084】このクラスを使用する場合は、type5(type
2)などと表現する。このとき、パラメタ$typeはtype2に
置き換わる。パラメタ$typeは、任意の型と置き換える
ことができるわけではない。図21の場合、パラメタ$t
ypeで型宣言した引数x1にメッセージm2を送っているの
で、少なくとも、パラメタ$typeと置き換えることので
きる型は、メッセージm2を送ることのできる型でなけれ
ばならない。パラメタに正しい型を指定しているかどう
かを検査しなければ、実行時にエラーを起こす可能性が
大きくなる。このような検査も、型検査プログラムを用
いることにより、パラメタに型を指定するたびに、パラ
メタを用いたクラスtype5($type)のコンパイルをする
ことなく、行うことができる。
When using this class, type5 (type
2) and so on. At this time, the parameter $ type is replaced with type2. The parameter $ type cannot be replaced with any type. In the case of FIG. 21, parameter $ t
Since the message m2 is sent to the argument x1 which is type-declared by ype, at least the type that can be replaced with the parameter $ type must be the type that can send the message m2. If you don't check that you have specified the correct type for the parameter, you are more likely to get an error at run time. By using the type checking program, such checking can be performed without compiling the class type5 ($ type) using the parameter each time the type is specified in the parameter.

【0085】図22は、パラメタを用いたクラスtype5
($type)に定義されているメソッドm5:の型検査プログ
ラムである。図21の004行において、パラメタ$typ
eによって型宣言されている引数x1の型は、メソッドの
中では確定しないので、外部変数の型と同じように、型
変数t0をもちいて表現される。これは、型変数宣言部2
210に登録される。型検査コード部2220は、図1
2の型検査コード部1220と同様に生成する。
FIG. 22 shows a class type5 using parameters.
This is the type checking program for the method m5: defined in ($ type). In line 004 of FIG. 21, parameter $ typ
Since the type of the argument x1 which is type-declared by e is not fixed in the method, it is expressed by using the type variable t0 like the type of the external variable. This is the type variable declaration part 2
Registered at 210. The mold inspection code section 2220 is shown in FIG.
It is generated similarly to the second type check code part 1220.

【0086】例えば、図14の型type2を用いて、クラ
スtype5(type2)を生成し、型検査プログラム2200を
実行すると、型変数t0にtype2が代入され、型推論式t0=
>m2:→t1は正しく実行できる。しかし、図14の型typ
e1を用いて、クラスtype5(type1)を生成し、型検査プロ
グラム2200を実行すると、型変数t0にtype1が代入
され、型推論式t0=>m2:→t1は正しく実行できない。し
たがって、type5(type1)という使い方は誤りであること
が、この検査によりわかる。
For example, when the type type2 of FIG. 14 is used to generate a class type5 (type2) and the type checking program 2200 is executed, type2 is substituted for the type variable t0, and the type inference expression t0 =
> m2: → t1 can be executed correctly. However, the type typ in Fig. 14
When a class type5 (type1) is generated using e1 and the type checking program 2200 is executed, type1 is assigned to the type variable t0, and the type inference expression t0 => m2: → t1 cannot be correctly executed. Therefore, this check shows that the usage of type5 (type1) is incorrect.

【0087】上述の実施例では、永続的オブジェクトを
扱うシステムが前提となっている。しかし、本発明の型
検査の方法は、ファイルシステムなどを用いたオブジェ
クト指向プログラミング言語に対しても適用が可能であ
る。図23は、ファイルシステムを用いた、本発明の構
成図である。上述の実施例における永続的オブジェクト
を管理する機能や、クラスオブジェクトなどの代わり
に、型情報辞書をもつことを特徴とする。
The above-described embodiment is premised on a system that handles persistent objects. However, the type checking method of the present invention can also be applied to an object-oriented programming language using a file system or the like. FIG. 23 is a block diagram of the present invention using a file system. It is characterized by having a type information dictionary instead of the function of managing persistent objects and class objects in the above-mentioned embodiment.

【0088】10は図1と同様な計算機システムであ
る。2300はコンパイラで、プログラムのモジュール
の定義2320を読み込み、モジュールの実行コード2
330、型情報辞書2340及びモジュールの型検査プ
ログラム2350を生成する。型検査プログラムの実行
は、型検査プログラム実行部2310において、型情報
辞書2340を参照しながら行う。型検査プログラムの
実行、すなわち、型検査の結果、型の誤りが存在するの
であれば、型検査プログラム実行部2310は型の誤り
情報を出力する。型検査プログラムの構成、生成方法、
実行方法などは、上述の実施例と同様である。
A computer system 10 is the same as that shown in FIG. 2300 is a compiler, which reads the module definition 2320 of the program and executes the module execution code 2
330, a type information dictionary 2340, and a module type check program 2350 are generated. The type check program is executed by the type check program execution unit 2310 with reference to the type information dictionary 2340. If there is a type error as a result of the execution of the type checking program, that is, the type checking, the type checking program execution unit 2310 outputs the type error information. Configuration of type check program, generation method,
The execution method and the like are the same as those in the above-described embodiment.

【0089】図24は型情報辞書の構成である。上述の
実施例における個々のクラスオブジェクトが管理してい
る情報をまとめて管理する。すなわち、型名によって、
その型の情報や型が定義されたクラスの情報を管理す
る。2401は型名であり、型及びクラス情報へのエン
トリとなる。2402は変数表であり、オブジェクトの
静的構造を表す変数の一覧である。関数などのモジュー
ルからみれば、外部変数になる。2403は型参照情報
である。2404はそのクラスが定義されているファイ
ル名である。2405はファイルにおけるクラス定義の
位置を示す行番号である。2406はそのクラスに定義
されている関数(モジュール)の表である。上述の実施
例におけるメソッド表(図8の809)に相当する。関
数表2406は、関数名2411、関数の仕様241
2、実行コード2413、型検査プログラム2414を
管理する。
FIG. 24 shows the structure of the type information dictionary. Information managed by each class object in the above-described embodiment is managed collectively. That is, depending on the model name,
It manages the information of the type and the class in which the type is defined. 2401 is a type name, which is an entry to the type and class information. A variable table 2402 is a list of variables that represent the static structure of the object. From the perspective of a module such as a function, it becomes an external variable. 2403 is type reference information. 2404 is a file name in which the class is defined. 2405 is a line number indicating the position of the class definition in the file. 2406 is a table of functions (modules) defined in the class. This corresponds to the method table (809 in FIG. 8) in the above embodiment. The function table 2406 includes a function name 2411 and a function specification 241.
2. Manage the execution code 2413 and the type checking program 2414.

【0090】このように、永続的オブジェクト管理機能
やクラスオブジェクトを用いなくとも、型情報辞書を生
成することにより、型検査プログラムを用いた型検査が
可能となる。
Thus, without using the persistent object management function or class object, by generating the type information dictionary, the type check using the type check program can be performed.

【0091】なお、上記実施例においては、コンパイラ
におけるコンパイル時に型検査プログラムを生成するよ
うにしているが、これに限らず、クラス定義を直接解析
して型情報を生成し、この型情報に基づいて型検査プロ
グラムを生成するようにしてもよい。
Although the type checking program is generated at the time of compilation in the compiler in the above embodiment, the present invention is not limited to this, the class definition is directly analyzed to generate the type information, and the type information is generated based on the type information. A type checking program may be generated.

【0092】[0092]

【発明の効果】以上述べたように、本発明によれば、構
文解析など従来のコンパイラの各フェーズと独立に型検
査を行うことができるため、継承処理、クラスの更新、
型のパラメタをもつクラス定義など、同一のソースプロ
グラムに対し、何度も型検査を行わなければならない場
合において、効率的な型検査を行うことができる。さら
に、コンパイルに対し、型検査を遅延することができる
ため、クラス定義とは別に、予め型の定義を宣言した
り、コンパイルの順序を指定する必要がなくなり、強い
型付けによるプログラマに対する制約を軽減することが
できる。
As described above, according to the present invention, since it is possible to perform type checking independently of each phase of a conventional compiler such as syntax analysis, inheritance processing, class updating,
Efficient type checking can be performed when the same source program, such as a class definition having a type parameter, must be repeatedly type checked. Furthermore, since type checking can be delayed for compilation, it is not necessary to declare type definitions in advance and specify the order of compilation separately from class definitions, which alleviates restrictions on programmers due to strong typing. be able to.

【図面の簡単な説明】[Brief description of drawings]

【図1】本発明を永続的オブジェクト管理システムにお
いて適用した場合の構成図である。
FIG. 1 is a configuration diagram when the present invention is applied to a persistent object management system.

【図2】従来の一般的なコンパイラの各フェーズを示す
図である。
FIG. 2 is a diagram showing each phase of a conventional general compiler.

【図3】型の参照関係の模式図である。FIG. 3 is a schematic diagram of a reference relationship between molds.

【図4】クラスの継承の模式図である。FIG. 4 is a schematic diagram of class inheritance.

【図5】本発明によるコンパイラの各フェーズを示す図
である。
FIG. 5 is a diagram showing each phase of the compiler according to the present invention.

【図6】オブジェクトの型の概念図である。FIG. 6 is a conceptual diagram of object types.

【図7】クラス定義の例を示す図である。FIG. 7 is a diagram showing an example of a class definition.

【図8】クラスオブジェクトの構成図である。FIG. 8 is a configuration diagram of a class object.

【図9】図8における変数表の構成図である。9 is a configuration diagram of a variable table in FIG.

【図10】図8におけるメソッド表の構成図である。10 is a configuration diagram of a method table in FIG.

【図11】型検査プログラムの構成図である。FIG. 11 is a configuration diagram of a mold inspection program.

【図12】図7の例において定義されたメソッドに対応
する型検査プログラムの例を示す図である。
12 is a diagram showing an example of a type checking program corresponding to the method defined in the example of FIG.

【図13】複数のクラスをコンパイルし、型検査する処
理手順を表した流れ図である。
FIG. 13 is a flowchart showing a processing procedure of compiling a plurality of classes and performing type checking.

【図14】図7のクラス定義が参照しているクラスの定
義例を示す図である。
14 is a diagram showing a definition example of a class referred to by the class definition of FIG. 7. FIG.

【図15】図14のクラス定義をコンパイルすることに
よって得られる型に関する情報の一覧を示す図である。
FIG. 15 is a diagram showing a list of types of information obtained by compiling the class definition of FIG.

【図16】型検査プログラム実行の処理手順を表した流
れ図である。
FIG. 16 is a flowchart showing a processing procedure for executing a type checking program.

【図17】継承処理に伴う型検査の処理手順を表した流
れ図である。
FIG. 17 is a flowchart showing a processing procedure of a type check associated with inheritance processing.

【図18】継承処理に伴う型検査の過程を説明するため
のクラス定義例を示す図である。
FIG. 18 is a diagram showing a class definition example for explaining the process of type checking associated with inheritance processing.

【図19】クラス更新に伴う型検査の処理手順を表した
流れ図である。
FIG. 19 is a flowchart showing a processing procedure of a type check accompanying a class update.

【図20】クラスの参照関係を表した有向グラフを示す
図である。
FIG. 20 is a diagram showing a directed graph showing a reference relationship of classes.

【図21】型をパラメタとしてもつクラス定義の例を示
す図である。
FIG. 21 is a diagram showing an example of a class definition having a type as a parameter.

【図22】図21の例において定義されたメソッドに対
応する型検査プログラムの例を示す図である。
22 is a diagram showing an example of a type checking program corresponding to the method defined in the example of FIG.

【図23】本発明をファイルなどで管理されるオブジェ
クト指向プログラミング言語に適用した場合のシステム
ブロック図である。
FIG. 23 is a system block diagram when the present invention is applied to an object-oriented programming language managed by files or the like.

【図24】図23における型情報辞書の構成図である。FIG. 24 is a configuration diagram of a type information dictionary in FIG. 23.

【符号の説明】[Explanation of symbols]

10…計算機システム、100…コンパイラ、110…
型検査プログラム実行部、112…型の誤り情報、12
0…データ管理システム、121…クラス定義、130
…オブジェクト管理システム、131…クラスオブジェ
クト、133…メソッド実行コード、135…型検査プ
ログラム。
10 ... Computer system, 100 ... Compiler, 110 ...
Type check program execution unit, 112 ... Type error information, 12
0 ... Data management system, 121 ... Class definition, 130
... object management system, 131 ... class object, 133 ... method execution code, 135 ... type checking program.

Claims (14)

【特許請求の範囲】[Claims] 【請求項1】オブジェクト指向プログラミング言語によ
って記述された、メソッドの定義および変数の宣言を含
む第1のクラス定義をコンパイルし、 該コンパイルにより、前記クラス定義により定義される
クラスの型に関する第1の型情報を生成し、 該第1の型情報に基づいて前記メソッドの各々に対して
型検査を行なうための型検査プログラムを生成し、 前記メソッドが参照すべき型に関する第2のクラス定義
がコンパイルされて該クラス定義により定義されるクラ
スの型に関する第2の型情報を生成し、 前記メソッドに対応する前記型検査プログラムを前記第
1および第2の型情報に基づき実行することを特徴とす
るプログラムの型検査方法。
1. Compiling a first class definition, written in an object-oriented programming language, including method definitions and variable declarations, the compiling of a first class definition for a type of a class defined by the class definition. Generate type information, generate a type checking program for performing type checking on each of the methods based on the first type information, and compile a second class definition for a type to which the method refers And generating second type information regarding the type of the class defined by the class definition, and executing the type checking program corresponding to the method based on the first and second type information. Program type checking method.
【請求項2】請求項1において、前記クラス定義をコン
パイルせずに直接解析することにより、前記型情報を生
成することを特徴とするプログラムの型検査方法。
2. The program type checking method according to claim 1, wherein the type information is generated by directly analyzing the class definition without compiling it.
【請求項3】請求項1において、前記メソッドが自己の
内部で宣言している型以外の型を参照している場合にの
み、前記メソッドの型検査を行なうための型検査プログ
ラムを生成することを特徴とするプログラムの型検査方
法。
3. The method according to claim 1, wherein the type checking program for performing the type checking of the method is generated only when the method refers to a type other than the type declared inside itself. A method for checking the type of a program.
【請求項4】請求項1において、前記型検査プログラム
を生成するステップにおいて、対応するメソッドが参照
している外部の変数の変数名と該変数の型を表す型変数
との対応関係を管理する型変数宣言部と、前記型変数を
用いて型検査を行なう手順を示した型検査コード部とを
生成し、前記型検査プログラムが前記型変数宣言部と前
記型検査コード部とで構成されるようにすることを特徴
とするプログラムの型検査方法。
4. The method according to claim 1, wherein in the step of generating the type checking program, a correspondence between a variable name of an external variable referenced by a corresponding method and a type variable representing the type of the variable is managed. A type variable declaration part and a type check code part showing a procedure for performing a type check using the type variable are generated, and the type check program is composed of the type variable declaration part and the type check code part. A method for checking the type of a program, characterized by:
【請求項5】請求項4において、前記型検査コード部
は、対応するメソッドの引数や前記メソッド内部の変数
の型宣言から直接推論することができない型を型変数と
し、前記メソッドの引数および前記メソッド内部の変数
の型を型定数とすることを特徴とするプログラムの型検
査方法。
5. The type checking code section according to claim 4, wherein the type argument is a type variable that cannot be directly inferred from the type argument of the corresponding method or the type declaration of the variable inside the method, and the type argument and the A method for checking the type of a program, characterized in that the type of the variable inside the method is a type constant.
【請求項6】請求項4において、前記型検査コード部
は、型を推論するための型推論式と該型推論式に対応す
る行番号とを有し、該行番号は前記型推論式を生成する
基となったクラス定義内における位置を示すための情報
を格納していて、前記型検査プログラムの前記型推論式
を前記第1および第2の型情報に基づき実行して型の誤
りが検出されると、該誤りが検出された型推論式に対応
する行番号を出力することを特徴とするプログラムの型
検査方法。
6. The type checking code section according to claim 4, wherein the type checking code part has a type inference expression for inferring a type and a line number corresponding to the type inference expression, and the line number indicates the type inference expression. Information for indicating the position in the class definition that is the basis of generation is stored, and the type inference expression of the type checking program is executed based on the first and second type information, and a type error is detected. When it is detected, the line number corresponding to the type inference expression in which the error is detected is output, and the type checking method of the program.
【請求項7】請求項6において、前記メソッドの型検査
を行なう際に、前記メソッドに対応する型検査プログラ
ムの型変数宣言部に宣言されている型変数に、該型変数
に対応する型を代入し、前記型推論式を実行し、該実行
により型の誤りが検出されると、該誤りに関する情報お
よび前記型推論式に対応する行番号を出力することを特
徴とするプログラムの型検査方法。
7. The type variable declared in the type variable declaration part of the type checking program corresponding to the method, when performing the type checking of the method, according to claim 6, Substituting, executing the type inference expression, and when a type error is detected by the execution, the information about the error and the line number corresponding to the type inference expression are output. .
【請求項8】請求項6において、前記型の誤りが検出さ
れるのは、前記第1および第2の型情報を参照できなか
った場合または型変数に型を代入できなかった場合であ
ることを特徴とするプログラムの型検査方法。
8. The method according to claim 6, wherein the type error is detected when the first and second type information cannot be referenced or the type cannot be assigned to the type variable. A method for checking the type of a program.
【請求項9】請求項4において、コンパイルされたメソ
ッドを継承する場合において、継承されるメソッドが、
継承先で正しく実行できるかどうかの検査を、前記メソ
ッドに対応する型検査プログラムの型変数宣言部の型変
数に、継承先のクラス定義において宣言された対応する
変数の型を代入し、前記型検査プログラムを実行するこ
とを特徴とするプログラムの型検査方法。
9. The inherited method according to claim 4, when inheriting the compiled method,
To check whether it can be correctly executed at the inheritance destination, assign the type of the corresponding variable declared in the class definition of the inheritance destination to the type variable of the type variable declaration part of the type checking program corresponding to the method, and A program type checking method characterized by executing a checking program.
【請求項10】請求項9において、前記継承されるメソ
ッドが定義されたクラス定義における変数の型を、前記
メソッドに対応する型検査プログラムの型変数宣言部の
前記型変数の初期値として記憶しておくことにより、継
承先のクラス定義における変数の型と前記初期値とが異
なる場合にのみ型検査を行うことを特徴とするプログラ
ムの型検査方法。
10. The method according to claim 9, wherein the type of the variable in the class definition in which the inherited method is defined is stored as an initial value of the type variable in the type variable declaration part of the type checking program corresponding to the method. By doing so, the type checking method of the program is characterized in that the type checking is performed only when the type of the variable in the inherited class definition and the initial value are different.
【請求項11】請求項1において、前記クラス定義を変
更する更新を行なう際に、該更新がすでにコンパイルさ
れているクラス定義に対して整合性を保証できるもので
あるかどうかの検査を、更新したクラスを参照するクラ
スの各メソッドに対応する型検査プログラムを実行する
ことにより行うことを特徴とするプログラムの型検査方
法。
11. The method according to claim 1, wherein, when performing an update that changes the class definition, a check is performed as to whether or not the update can guarantee the consistency with respect to the already compiled class definition. Type checking method for a program, which is performed by executing a type checking program corresponding to each method of a class that refers to the created class.
【請求項12】請求項1において、前記クラスの型に関
する情報は、クラス名すなわち型名、前記クラスのクラ
ス定義、該クラス定義で宣言されている変数と継承され
た変数の表、型の参照情報、および前記クラス定義で定
義されたメソッドと継承されたメソッドの表から成り、
クラス名を指定することにより、前記クラスの型に関す
る情報を得ることができることを特徴とするプログラム
の型検査方法。
12. The information according to claim 1, wherein the class type information includes a class name, that is, a type name, a class definition of the class, a table of variables declared in the class definition and inherited variables, and a type reference. Information and a table of methods defined and inherited in the class definition,
A type checking method for a program, wherein information on the type of the class can be obtained by specifying a class name.
【請求項13】オブジェクト指向プログラミング言語に
よって記述された型をパラメタとした第1のクラス定義
において、前記パラメタの値が確定しないままコンパイ
ルを行い、前記パラメタを含む型に関する第1の型情報
と、前記パラメタを含む第1の型検査プログラムとを生
成し、第2のクラス定義をコンパイルして前記パラメタ
に代入される型を含む第2の型情報が生成されると、前
記代入される型が前記第1のクラス定義に対して正しい
か否かの検査を、前記第1の型検査プログラムに前記型
を代入して実行することにより行なうことを特徴とする
プログラムの型検査方法。
13. A first class definition using a type described as a parameter in an object-oriented programming language as a parameter, compiling without determining the value of the parameter, and first type information regarding the type including the parameter, When the first type checking program including the parameter is generated, and the second class definition is compiled to generate the second type information including the type assigned to the parameter, the assigned type becomes A type checking method for a program, wherein the checking of whether the first class definition is correct is performed by substituting the type into the first type checking program and executing the program.
【請求項14】オブジェクト指向プログラミング言語に
よって記述されたメソッドの定義および変数の宣言を含
むクラス定義をコンパイルするコンパイラを備えた計算
機システムにおいて、 前記コンパイラは、 前記クラス定義により定義されるクラスの型に関する型
情報を生成する型情報生成手段と、 前記生成された型情報を保持する第1の保持手段と、 前記保持された型情報に基づいて前記メソッドの各々に
対して型検査を行なうための型検査プログラムを生成す
る型検査プログラム生成手段と、 を備え、 前記システムは、さらに、 前記コンパイラにより生成された型検査プログラムを保
持する第2の保持手段と、 前記メソッドが参照すべき型に関する型情報が生成され
ると、前記メソッドに対応する前記型検査プログラムを
前記第2の保持手段から取りだし、前記型に関する情報
に基づき実行する実行手段を備えることを特徴とする計
算機システム。
14. A computer system comprising a compiler for compiling a class definition including a method definition and a variable declaration written in an object-oriented programming language, wherein the compiler relates to a type of a class defined by the class definition. Type information generating means for generating type information, first holding means for holding the generated type information, and a type for performing type checking on each of the methods based on the held type information. A type checking program generating means for generating a checking program; the system further includes a second holding means for holding the type checking program generated by the compiler; and type information about a type to be referred to by the method. Is generated, the type checking program corresponding to the method is Computer system characterized in that it comprises execution means for taking out from the holding means, to execute on the basis of information on the type.
JP5104593A 1993-03-11 1993-03-11 Method and system for inspecting type of program Pending JPH06266561A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP5104593A JPH06266561A (en) 1993-03-11 1993-03-11 Method and system for inspecting type of program

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP5104593A JPH06266561A (en) 1993-03-11 1993-03-11 Method and system for inspecting type of program

Publications (1)

Publication Number Publication Date
JPH06266561A true JPH06266561A (en) 1994-09-22

Family

ID=12875838

Family Applications (1)

Application Number Title Priority Date Filing Date
JP5104593A Pending JPH06266561A (en) 1993-03-11 1993-03-11 Method and system for inspecting type of program

Country Status (1)

Country Link
JP (1) JPH06266561A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2006302285A (en) * 2005-04-18 2006-11-02 Sun Microsyst Inc Implementation of generic types while maintaining migration compatibility
JP2013214255A (en) * 2012-04-04 2013-10-17 Meidensha Corp Simulation method in software development support system
JP2017516210A (en) * 2014-04-22 2017-06-15 オラクル・インターナショナル・コーポレイション Structure identification of dynamically generated pattern base classes

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2006302285A (en) * 2005-04-18 2006-11-02 Sun Microsyst Inc Implementation of generic types while maintaining migration compatibility
JP2013214255A (en) * 2012-04-04 2013-10-17 Meidensha Corp Simulation method in software development support system
JP2017516210A (en) * 2014-04-22 2017-06-15 オラクル・インターナショナル・コーポレイション Structure identification of dynamically generated pattern base classes

Similar Documents

Publication Publication Date Title
US7962904B2 (en) Dynamic parser
Paakki Attribute grammar paradigms—a high-level methodology in language implementation
Ernst et al. An empirical analysis of C preprocessor use
US5313387A (en) Re-execution of edit-compile-run cycles for changed lines of source code, with storage of associated data in buffers
US20070226720A1 (en) System and Method for Efficiently Passing Information Between Compiler and Post-Compile-Time Software
Wood On the equivalence of XML patterns
Sadilek et al. Prototyping visual interpreters and debuggers for domain-specific modelling languages
Zhou et al. VST-A: a foundationally sound annotation verifier
Schröer The GENTLE Compiler Construction System
Varró et al. Automated program generation for and by model transformation systems
Evans Using specifications to check source code
Bajczi et al. C for yourself: comparison of front-end techniques for formal verification
JPH06266561A (en) Method and system for inspecting type of program
Christiansen et al. Symbolic constraints for meta-logic programming
Farnum Pattern-based languages for prototyping of compiler optimizers
Öqvist Contributions to declarative implementation of static program analysis
Blazy et al. Partial evaluation for the understanding of Fortran programs
van Laarhoven et al. Formalising and analysing SMMT models using the mCRL2 toolset
Atterer Automatic test data generation from VDM-SL specifications
Aldrich Coverage analysis for model-based design tools
Blunk et al. Prototyping domain specific languages as extensions of a general purpose language
de Bruin et al. Improving Agda’s module system
Nita et al. Automatic transformation of bit-level C code to support multiple equivalent data layouts
EP1785848A1 (en) Method and apparatus for semantic checking of program code
Di Iorio et al. A Self-Applicable Partial Evaluator for ASM