
Ctalk Language Reference Object Oriented Extensions for C Robert Kiesling Ctalk Language Reference. This manual describes Ctalk, version 0.0.66. Copyright c 2007-2015, Robert Kiesling Permission is granted to distribute this document under the terms of the GNU Free Docu- mentation License. See hundefinedi [GNU Free Documentation License], page hundefinedi. i Table of Contents Chapter 1: Introduction to Ctalk 1 1 Introduction to Ctalk Ctalk provides an extensions to the C programming language that allow programmers to use object oriented language features, like class objects, methods, operator overloading, and inheritance, in C programs. This manual describes Ctalk, version 0.0.66. If you are not familiar with object oriented programming concepts, you might like to read an introductory text on the subject. Using Ctalk requires that you are familiar with the concepts of object oriented programming, as well as the C language. This manual uses object oriented programming terms extensively. The next chapter describes how to use Ctalk to create programs and use the Ctalk com- piler's command line interface. The following chapters describe the class hierarchy, method application programming interface, the interface with C and its run-time libraries, and finally, some simple example programs. 1.1 C Language Conformance Ctalk conforms as closely as possible to the C language defined by International Standard ISO/IEC 9899, commonly known as C99. 1.2 Compiler Compatibility Ctalk is compatible with GNU GCC, version 2.95 and later. Ctalk recognizes GCC ex- tensions like function and data attributes, and the preprocessor can use directives like #include_next. Ctalk recognizes but does not process deprecated language extensions and preprocessor directives like #sccs and #unassert. To adapt Ctalk to another compiler, you may need to provide compiler-specific definitions. You will also need to add your compiler's definition file and initialization code, if necessary, to the file, src/ccompat.c, which contains the COMPAT_INCLUDE definition and functions for specific compilers. The ctpp preprocessor also contains system-specific definitions. Consult its documentation for details. Some Document Conventions When the term, \Ctalk," appears in this manual, it refers to the programming language, and when ctalk appears, it refers to the Ctalk compiler and libraries. identifier Names of classes, variables, methods and messages, file names, and source code examples appear in monospaced type. variable Metasyntactic variables and citations appear in italic or oblique type. Chapter 2: Using Ctalk 3 2 Using Ctalk Ctalk has two parts: a preprocessor and interpreter that translates Ctalk code into C, which a compiler can use to create an executable program, and a run-time library, which the compiler links with the executable. Ctalk has its own C99 compatible preprocessor, ctpp, which is described in its Texinfo manual, ctpp.info. To use ctalk, you must provide at least the name of the input file. Normally, you also provide the name of the output file with the-o ` ' option. If you use the conventions followed by GNU C, the output file is normally the base name of the input file with the extension `.i', as in this example. $ ctalk myprog.c -o myprog.i The ctalk program preprocesses myprog.c and translates it into standard C. After ctalk has finished, you can compile and link the output of ctalk to produce an executable pro- gram. $ gcc myprog.i -o myprog -lctalk More conveniently, the ctcc command combines these operations, with the appropriate command line options, to build an executable program. $ ctcc myprog.c -o myprog If you need to build a program for debugging, the ctdb command builds executables that you can debug with gdb. See hundefinedi [Debugging], page hundefinedi. For more information, refer to the ctalk(1), ctcc(1), ctdb(1), gcc(1), and gdb(1) manual pages. 2.1 Command Line Options --clearpreload Clear preloaded methods so they can be rewritten. -E Preprocess the input and exit. -h, --help Print a help message and exit. -I dir Add dir to the ctalk include search path. --keeppragmas Write pragmas untranslated to the output. --nolibinc Do not include Ctalk's system headers in the output. --nopreload Do not use preloaded methods. -o file Write the ctalk output to file. --printlibdirs Print the library directories and exit. 4 Ctalk --printtemplates Print the templates that Ctalk loads and caches (but does not necessarily send to the output). --progress Print dots to indicate Ctalk's progress. -P Do not output line number information. -s dir Add dir to the compiler system include search path. -V Print the Ctalk version number and exit. -v --verbose Print verbose warnings. This option also sets the --warnextension, --warnduplicatenames and --warnunresolvedselexpr options. --warnclasslibs Print the names of class libraries as they are loaded. --warnduplicatenames Print a warning when an object duplicates a C variable name. Because of the way Ctalk's just-in-time interpreter works, the front end prints warnings of any duplicate names. The variables and objects need not be in the same scope. Usually, though, Ctalk can make an intelligent decision about how to process objects and variables with duplicate names. This option does not affect errors caused by duplicate symbols or shadowing. --warnextension Print warnings for some compiler extensions. --warnunresolvedselfexpr Prints warnings if self appears in an argument block with either an instance variable label or an unresolvable method label following it. In expressions like these, the class of each element of a collection, when represented by self within the argument block, often can't be determined until run time. You can specify a class for self by placing a class cast expression (described in the section Class casting) before the self keyword. See hundefinedi [Class casting], page hundefinedi. For example, if a program contains an expression like this: List new textLines; ...The program adds items to textLines... textLines map { if (self length > 0) { ...do something... Chapter 2: Using Ctalk 5 } } Then the expression, self length would generate a warning due to the label, length, because the class membership of, self, which represents each succes- sive element of the, textLines, list, normally isn't determined until run time, and so the receiver class of length is also undetermined. However, if you know that textLines contains only String objects, then you can add a class cast expression in the argument block. textLines map { if ((String *)self length > 0) { ...do something... } } This tells the program to treat length's receiver, self, as a String object, so it's possible to determine, before the program is actually executed, whether, self length, is a valid expression. Chapter 3: Classes 7 3 Classes Class library files contain class and method definitions and are located inthe classes subdirectory. After installation, the libraries are in a ctalk include subdirectory defined by the macro CLASSLIBDIR when the program is built. 3.1 Class Hierarchy Object Bitmap DisplayFont X11Font X11Cursor X11FreeTypeFont X11Bitmap Boolean Collection Array List AssociativeArray SortedList Stream FileStream DirectoryStream ReadFileStream WriteFileStream TerminalStream ANSITerminalStream Win32TerminalStream X11TerminalStream NetworkStream TCPIPNetworkStream TCPIPNetworkStreamReader TCPIPNetworkStreamWriter TCPIPV6NetworkStream TCPIPV6NetworkStreamReader TCPIPV6NetworkStreamWriter UNIXNetworkStream UNIXNetworkStreamReader UNIXNetworkStreamWriter TreeNode Event Application ClassLibraryTree GLUTApplication ObjectInspector LibrarySearch 8 Ctalk Exception SystemErrnoException InputEvent SignalEvent SignalHandler Expr CFunction Magnitude Character String Float Integer CTime CalendarTime LongInteger Pen Point Line Rectangle Circle Method Pane ANSITerminalPane ANSIWidgetPane ANSIButtonPane ANSILabelPane ANSIListBoxPane ANSIMessageBoxPane ANSIProgressBarPane ANSIScrollingListBoxPane ANSIScrollPane ANSITextBoxPane ANSITextEntryPane ANSIYesNoBoxPane X11Pane GLXCanvasPane X11PaneDispatcher X11CanvasPane X11ButtonPane X11CheckBoxPane X11LabelPane X11ListPane X11MessageBoxPane X11ScrollBarPane X11TextEntryPane X11YesNoBoxPane X11TextEntryBox Chapter 3: Classes 9 X11ListBox X11FileSelectDialog X11TextPane X11TextEditorPane Symbol Key Vector 3.2 Object class Ctalk defines the Object class by default at run time. All other classes are subclasses of Object. Instance Variables value The value of the object. For classes that correspond to the C data types: Character, Float, Integer, LongInteger, and String, ctalk formats the value as it would appear as if output by the C printf function. When you use one of these classes in a C expression, ctalk translates the object's value to its C data type. Other classes may define value to return class specific data. Null Objects To help make Ctalk compatible with C, Ctalk defines the macro STR IS NULL, which checks whether the object's value evaluates to false in C. That means that objects that have the value `(null)', are an empty string, or if the object's value is a NULL pointer, all evaluate similarly. The STR IS NULL macro is defined in the include file ctalkdefs.h, so to use it, add the following line at the start of a class library. #include <ctalk/ctalkdefs.h> Ctalk also assigns an object the value of `(null)' when an object is created or when Ctalk encounters a C NULL in an expression (which is a macro that expands to `((void *)0)'). Instance Methods ! (void) Overloads the `!' prefix
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages436 Page
-
File Size-