📄 writing_a_be
字号:
UTL_StrList *p)
: AST_Interface(n, ih, nih, p),
AST_Decl(AST_Decl::NT_interface, n, p),
UTL_Scope(AST_Decl::NT_interface)
{
}
AST_InterfaceFwd:
BE_InterfaceFwd::BE_InterfaceFwd(UTL_ScopedName *n,
UTL_StrList *p)
: AST_InterfaceFwd(n, p),
AST_Decl(AST_Decl::NT_interface_fwd, n, p)
{
}
AST_Module:
BE_Module::BE_Module(UTL_ScopedName *n,
UTL_StrList *p)
: AST_Decl(AST_Decl::NT_module, n, p),
UTL_Scope(AST_Decl::NT_module)
{
}
AST_Operation:
BE_Operation::BE_Operation(AST_Type *rt,
AST_Operation::Flags fl,
UTL_ScopedName *n,
UTL_StrList *p)
: AST_Operation(rt, fl, n, p),
AST_Decl(AST_Decl::NT_op, n, p),
UTL_Scope(AST_Decl::NT_op)
{
}
AST_PredefinedType:
BE_PredefinedType::BE_PredefinedType(
AST_PredefinedType::PredefinedType *pt,
UTL_ScopedName *n,
UTL_StrList *p)
: AST_PredefinedType(pt, n, p),
AST_Decl(AST_Decl::NT_pre_defined, n, p)
{
}
AST_Root:
BE_Root::BE_Root(UTL_ScopedName *n, UTL_StrList *p)
: AST_Module(n, p),
AST_Decl(AST_Decl::NT_module, n, p),
UTL_Scope(AST_Decl::NT_module)
{
}
AST_Sequence:
BE_Sequence::BE_Sequence(AST_Expression *ms, AST_Type *bt)
: AST_Sequence(ms, bt),
AST_Decl(AST_Decl::NT_sequence,
new UTL_ScopedName(new String("sequence"), NULL),
NULL)
{
}
AST_String:
BE_String::BE_String(AST_Expression *ms)
: AST_String(ms),
AST_Decl(AST_Decl::NT_string,
new UTL_ScopedName(new String("string"), NULL),
NULL)
{
}
AST_Structure:
BE_Structure::BE_Structure(UTL_ScopedName *n,
UTL_StrList *p)
: AST_Decl(AST_Decl::NT_struct, n, p),
UTL_Scope(AST_Decl::NT_struct)
{
}
AST_Type:
BE_Type::BE_Type(AST_Decl::NodeType nt,
UTL_ScopedName *n,
UTL_StrList *p)
: AST_Decl(nt, n, p)
{
}
AST_Typedef:
BE_Typedef::BE_Typedef(AST_Type *bt,
UTL_ScopedName *n,
UTL_StrList *p)
: AST_Typedef(bt, n, p),
AST_Decl(AST_Decl::NT_typedef, n, p)
{
}
AST_Union:
BE_Union::BE_Union(AST_ConcreteType *dt,
UTL_ScopedName *n,
UTL_StrList *p)
: AST_Union(dt, n, p),
AST_Structure(AST_Decl::NT_union, n, p),
AST_Decl(AST_Decl::NT_union, n, p),
UTL_Scope(AST_Decl::NT_union)
{
}
AST_UnionBranch:
BE_UnionBranch::BE_UnionBranch(AST_UnionLabel *fl,
AST_Type *ft,
UTL_ScopedName *n,
UTL_StrList *p)
: AST_UnionBranch(fl, ft, n, p),
AST_Field(ft, n, p),
AST_Decl(AST_Decl::NT_union_branch, n, p)
{
}
AST_UnionLabel:
BE_UnionLabel::BE_UnionLabel(AST_UnionLabel::UnionLabel lk,
AST_Expression *lv)
: AST_UnionLabel(lk, lv)
{
}
HOW TO USE THE ADD PROTOCOL
---------------------------
As explained the section SCOPE MANAGEMENT, the CFE manages scopes by
calling type-specific functions to add new nodes to the scope to be
augmented. These functions can be overridden in your BE classes to do work
specific to your BE class. For example, in a BE_module class, you might
override add_interface to do additional work.
The protocol defined by the "add_" functions is that they return NULL to
indicate failure. They return the node that was added (and which was given
as an argument) if the operation succeeded. Your functions in your BE class
should follow the same protocol.
The "add_" functions defined in the BE must call the overridden function in
the base class defind in the CFE in order for the CFE scope management
mechanism to work. Otherwise, the CFE does not get an opportunity to
augment its scopes with the new node to be added. It is good practice to
call the overridden "add_" function as the first action in your BE
function, because the success or failure of the CFE operation indicates
whether your function should complete its task or abort early.
Here is an example. Suppose you have defined a class BE_module which
inherits from AST_Module. You may wish to override the add_interface
function as follows:
class BE_Module : public virtual AST_Module
{
....
/*
* ADD protocol
*/
virtual AST_Interface *add_interface(AST_Interface *);
...
};
The implementation of this function would look something like the following:
AST_Interface *
BE_Module::add_interface(AST_Interface *new_in)
{
/*
* Check that the CFE operation succeeds. If it returns
* NULL, stop any further work
*/
if (AST_Module::add_interface(new_in) == NULL)
return NULL;
/*
* OK, non-NULL, this means the BE can do its own work here
*/
...
/*
* Finally, don't forget to return the argument to indicate
* success
*/
return new_in;
}
HOW TO MAINTAIN BE SPECIFIC INFORMATION
---------------------------------------
The CFE provides a special class AST_Root, a subclass of AST_Module. An
instance of the AST_Root class is used as the distinguished root of the
abstract syntax tree built during a parse.
Your BE can subclass BE_Root from AST_Root and override the create_root
operation in your BE_Generator class derived from AST_Generator. This will
cause the CFE to create an instance of your BE_Root class as the root of
the tree being constructed.
You can use the instance of the BE_Root class as a convenient place to
store information specific to an individual tree. For example, you could
add operations on the BE_Root class to count how many nodes of each class
are created.
HOW TO USE MEMBER DATA
----------------------
As explained above, the AST classes provide access and update functions for
manipulating data members. Your BE classes must use these functions when
they require access to data members defined in the AST classes, since the
data members themselves are private.
It is good practice to follow the same scheme in your BE classes. Make all
data members private. Prepend the names of all such fields with "pd_".
Define access functions with names equal to the name of the field without the
prefix. Define update functions according to need by prepending the name of
the access function with the prefix "set_".
Using these techniques will allow your BE to enjoy the same benefits that
are imparted onto the CFE. Your BE will be easier to move to a
multithreaded environment and its data members will be better protected and
hidden.
HOW TO BUILD A COMPLETE COMPILER
--------------------------------
We now have all information needed to write a BE and to link it in with the
CFE, to produce a complete IDL compiler.
The following assumes that your BE will be stored in the "be" directory
under the "release" directory. See the document ROADMAP for an explanation
of the directory structure of the source release. If you decide to use a
different directory to store your BE, you may have to modify the CPP_FLAGS in
"idl_make_vars" in the top-level directory to allow your BE to find the
include files it needs. You will also need to modify several targets in
the Makefile in the top-level directory to correctly compile your BE into a
library and to correctly link it in with the CFE to produce a complete
compiler.
You can get started quickly on writing your BE by modifying the sources
found in the "demo_be" directory. The Makefile supports all the the targets
that are needed to build a complete system and the maintenance target
"clean" which assists in keeping the files and directories tidy. The files
provided in the "demo_be" directory also provide all the API entry points
that are mandated by this document.
To build a complete compiler, invoke "make" or "make all" in the top-level
directory. This will compile your BE and all the CFE sources, if this is
the first invocation. On subsequent invocations this will recompile only
the modified files. You will rarely if at all modify the CFE sources, so
the overhead of compiling the CFE is incurred only the first time. To build
just your BE, you can invoke "make all" or "make" in the "demo_be"
directory. You can also, from the top-level directory, invoke "make
demo_be/libbe.a".
HOW TO OBTAIN ASSISTANCE
------------------------
First, read all the documents provided. If you have unanswered questions,
mail them to
idl-cfe@sun.com
Sun does not promise to support the IDL CFE source release in any manner.
However, we will attempt to answer questions and correct problems as time
allows.
NOTE:
SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
trademarks or registered trademarks of Sun Microsystems, Inc.
COPYRIGHT NOTICE
----------------
Copyright 1992, 1993, 1994 Sun Microsystems, Inc. Printed in the United
States of America. All Rights Reserved.
This product is protected by copyright and distributed under the following
license restricting its use.
The Interface Definition Language Compiler Front End (CFE) is made
available for your use provided that you include this license and copyright
notice on all media and documentation and the software program in which
this product is incorporated in whole or part. You may copy and extend
functionality (but may not remove functionality) of the Interface
Definition Language CFE without charge, but you are not authorized to
license or distribute it to anyone else except as part of a product or
program developed by you or with the express written consent of Sun
Microsystems, Inc. ("Sun").
The names of Sun Microsystems, Inc. and any of its subsidiaries or
affiliates may not be used in advertising or publicity pertaining to
distribution of Interface Definition Language CFE as permitted herein.
This license is effective until terminated by Sun for failure to comply
with this license. Upon termination, you shall destroy or return all code
and documentation for the Interface Definition Language CFE.
INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED AS IS WITH NO WARRANTIES OF
ANY KIND INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS
FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR ARISING FROM A COURSE OF
DEALING, USAGE OR TRADE PRACTICE.
INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED WITH NO SUPPORT AND WITHOUT
ANY OBLIGATION ON THE PART OF Sun OR ANY OF ITS SUBSIDIARIES OR AFFILIATES
TO ASSIST IN ITS USE, CORRECTION, MODIFICATION OR ENHANCEMENT.
SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES SHALL HAVE NO LIABILITY WITH
RESPECT TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY
INTERFACE DEFINITION LANGUAGE CFE OR ANY PART THEREOF.
IN NO EVENT WILL SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES BE LIABLE FOR
ANY LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL
DAMAGES, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
Use, duplication, or disclosure by the government is subject to
restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
Technical Data and Computer Software clause at DFARS 252.227-7013 and FAR
52.227-19.
Sun, Sun Microsystems and the Sun logo are trademarks or registered
trademarks of Sun Microsystems, Inc.
SunSoft, Inc.
2550 Garcia Avenue
Mountain View, California 94043
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -