[ Pobierz całość w formacie PDF ]
.] );The optional tag is an identifier involved in locating a method withrespondsTo().The first declarator introduces the method name and resulttype, the remaining declarators introduce parameter names and types.Exactly one parameter name must be self to indicate the receiver of themethod call.A declarator is a simplified C declarator as described above, but there are two spe-cial cases:_nameintroduces name as the declarator name.The type is a pointer to aninstance of the current class or to the class for which a dynamically linkedmethod is overwritten.Such a pointer will be dereferenced by %casts asname within a method.Therefore, self must be introduced as _self, whereself is the dereferenced object or class for class methods and _self is theraw pointer.class @ nameintroduces name as a pointer to an instance of class.Such a pointer will notbe dereferenced but it will be checked by %casts.The result type of a method can employ class @.In this case, the result type isgenerated as a pointer to a struct class which is useful when implementingmethods, and which cannot be used other than for assignments to void * in appli-cation code.The result type should be void * for constructors and similar methodsto emphasize the generic aspects of construction.PreprocessingSubject to the lexical conventions described above, an implementation filesource.dc is copied to standard output.Lines starting with % are preprocessed asfollows:% class method {This is replaced by a C function header for method; the header is declaredstatic with the name class_method, unless method has static linkage.Inthe latter case, class is optional.ooc checks in all cases that the methodcan be specified for class.Function names are remembered as necessaryfor initialization of the description of class and the corresponding metaclassif any.There can be an optional tag preceding class unless method hasstatic linkage.%castsThis is replaced by definitions of local variables to securely dereferenceparameter pointers to objects in the current class.For statically linkedmethods this is followed by checks to verify the parameters pointing toobjects of other classes.%casts should be used where local variables canbe defined; for statically linked methods it must be the last definition.Notethat null pointers flunk the checks and terminate the calling program.C.1 Commands 211___________________________________________________________________________%initThis should be near the end of the implementation file.If the descriptionintroduced a new metaclass, a constructor for the metaclass, selectors forthe class, and initializations for the metaclass are generated.In either case,an initialization for the class is generated.If a method m does not have static linkage, there are two selectors: m with thesame parameters as the method selecting the method defined for self, andsuper_m with an explicit class description as an additional first parameter.Thesecond selector is used to pass a method call to the superclass of the class wherethe method is defined.If a dynamically linked or class method has a variable argument list, the selectorpasses va_list * app to the actual method.If a selector recognizes that it cannot be applied to its object, it calls forward andpasses its object, a pointer to a result area, or a null pointer, its own address, itsname as a string, and its entire argument list.forward should be a dynamicallylinked method in the root class; it can be used to forward a message from oneobject to another.TagsrespondsTo() is a method in the root class which takes an object and a tag, i.e., a Cstring containing an identifier, and returns either a null pointer or a selector whichwill accept the object and other parameters and call the method corresponding tothe tag.The tag under which a class or dynamically linked method can be found is definedas follows.The default is either the method name or tag in the method header inthe class description file:[ tag : ] declarator ( declarator { , declarator } [ ,.] );The method header in the implementation may overwrite the tag:% mtag: class method {The effective tag is mtag if specified, or tag if not.If mtag or tag is empty but thecolon is specified, respondsTo() cannot find the method.Report Fileooc uses report files containing all code fragments which ooc will generate.Namessuch as app for an argument list pointer can be changed in the report file.Only selfis built into ooc itself.A report file contains one or more reports.The usual lexical conventions apply.Each report is preceded by a line starting with % and containing the report namewhich may be enclosed by white space.The report name is arbitrary text but itmust be unique.A report consists of lines of words separated by single blanks or tabs, calledspaces.An empty word results between any two adjacent spaces or if a spacestarts or ends a line.212 Appendix C Manual___________________________________________________________________________An empty word, not at the beginning of an output line, is printed as a blank.In par-ticular, this means that two successive spaces in a report represent a single blankto be printed.Any word not starting with a back quote ` is printed as is.A word starting with `% causes a report to be printed.The report name is theremainder of the word.`#line followed by a word causes a line stamp to be printed if option -l is specified;the phrase is ignored otherwise.If the word is a class, method, or class com-ponent name, the line stamp refers to its position in a class description file.Other-wise, and in particular for empty words, the line stamp refers to the current inputfile position.A word starting with `{ starts a group.The group is terminated with a word startingwith `}.All other words starting with a back quote ` are replaced during printing.Some replacements are globally defined, others are set up by certain groups.Atable of replacements follows at the end of this section.Groups are either loops over parts of the database collected by ooc or they are con-ditionals based on a comparison.Words inside a group are printed under control ofthe loop or the comparison.Afterwards, printing continues with the word followingthe group
[ Pobierz całość w formacie PDF ]