summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL
diff options
context:
space:
mode:
authorgokhale <asgokhale@users.noreply.github.com>1997-11-15 18:33:50 +0000
committergokhale <asgokhale@users.noreply.github.com>1997-11-15 18:33:50 +0000
commitb106fb2da35e0e61cf5effa1c8f678b89243f7e0 (patch)
treecf9e0cce0c7a8bd600d1e7d0c4288476d63dec6d /TAO/TAO_IDL
parent8db1570d67ff78facdca94a59861f62f611a8c1e (diff)
downloadATCD-b106fb2da35e0e61cf5effa1c8f678b89243f7e0.tar.gz
typecodes for typedefs, and some work on unions with string members
CVS: CVS:
Diffstat (limited to 'TAO/TAO_IDL')
-rw-r--r--TAO/TAO_IDL/be/be_constant.cpp57
-rw-r--r--TAO/TAO_IDL/be/be_interface.cpp4
-rw-r--r--TAO/TAO_IDL/be/be_state.cpp27
-rw-r--r--TAO/TAO_IDL/be/be_typedef.cpp114
-rw-r--r--TAO/TAO_IDL/be_include/be_codegen.h2
5 files changed, 142 insertions, 62 deletions
diff --git a/TAO/TAO_IDL/be/be_constant.cpp b/TAO/TAO_IDL/be/be_constant.cpp
index a9355cd3a27..4ca500d34d5 100644
--- a/TAO/TAO_IDL/be/be_constant.cpp
+++ b/TAO/TAO_IDL/be/be_constant.cpp
@@ -2,7 +2,7 @@
//
// = LIBRARY
// TAO IDL
-//
+//
// = FILENAME
// be_constant.cpp
//
@@ -12,9 +12,9 @@
//
// = AUTHOR
// Copyright 1994-1995 by Sun Microsystems, Inc.
-// and
+// and
// Aniruddha Gokhale
-//
+//
// ============================================================================
#include "idl.h"
@@ -35,30 +35,17 @@ be_constant::be_constant (AST_Expression::ExprType et,
: AST_Constant (et, v, n, p),
AST_Decl (AST_Decl::NT_const, n, p)
{
- // computes the repoID
- compute_repoID ();
-
- // computes the fully scoped name
- compute_fullname ();
-
- // compute the flattened fully scoped name
- compute_flatname ();
}
// ----------------------------------------
// CODE GENERATION METHODS
// ----------------------------------------
-// Generates the client-side header information for the constant
-int
+// Generates the client-side header information for the constant
+int
be_constant::gen_client_header (void)
{
TAO_OutStream *ch; // output stream
- TAO_NL nl; // end line
- be_scope *scope; // scope
-
- // Macro to avoid "warning: unused parameter" type warning.
- ACE_UNUSED_ARG (nl);
// retrieve a singleton instance of the code generator
TAO_CodeGen *cg = TAO_CODEGEN::instance ();
@@ -68,12 +55,10 @@ be_constant::gen_client_header (void)
// if we are defined in the outermost scope, then the value is assigned
// to us here itself, else it will be in the *.cpp file
-
+
ch->indent (); // start from whatever indentation level we were at
*ch << "static const " << this->exprtype_to_string () << " " << local_name ();
- scope = be_scope::narrow_from_scope (this->defined_in ()); // retrieve
- // our scope
- if (scope->scope_node_type () == AST_Decl::NT_root)
+ if (this->is_nested ())
{
// We were defined at the outermost scope. So we put the value in the
// header itself
@@ -85,15 +70,10 @@ be_constant::gen_client_header (void)
}
// Generates the client-side stubs for the constant
-int
+int
be_constant::gen_client_stubs (void)
{
TAO_OutStream *cs; // output stream
- TAO_NL nl; // end line
- be_scope *scope; // scope
-
- // Macro to avoid "warning: unused parameter" type warning.
- ACE_UNUSED_ARG (nl);
// retrieve a singleton instance of the code generator
TAO_CodeGen *cg = TAO_CODEGEN::instance ();
@@ -101,14 +81,12 @@ be_constant::gen_client_stubs (void)
cs = cg->client_stubs ();
- scope = be_scope::narrow_from_scope (this->defined_in ()); // retrieve
- // our scope
- if (scope->scope_node_type () != AST_Decl::NT_root)
+ if (this->is_nested ())
{
// for those constants not defined in the outer most scope, they get
- // assigned to their values in the
+ // assigned to their values in the
cs->indent (); // start from whatever indentation level we were at
- *cs << "const " << this->exprtype_to_string () << " " << name ();
+ *cs << "const " << this->exprtype_to_string () << " " << this->name ();
*cs << " = " << this->constant_value ();
*cs << ";\n\n";
}
@@ -116,8 +94,8 @@ be_constant::gen_client_stubs (void)
return 0;
}
-// Generates the server-side header information for the constant
-int
+// Generates the server-side header information for the constant
+int
be_constant::gen_server_header (void)
{
// nothing to be done
@@ -125,7 +103,7 @@ be_constant::gen_server_header (void)
}
// Generates the server-side skeletons for the constant
-int
+int
be_constant::gen_server_skeletons (void)
{
// nothing to be done
@@ -133,7 +111,7 @@ be_constant::gen_server_skeletons (void)
}
// Generates the client-side inline information
-int
+int
be_constant::gen_client_inline (void)
{
// nothing to be done
@@ -141,7 +119,7 @@ be_constant::gen_client_inline (void)
}
// Generates the server-side inline
-int
+int
be_constant::gen_server_inline (void)
{
// nothing to be done
@@ -151,7 +129,7 @@ be_constant::gen_server_inline (void)
char *
be_constant::exprtype_to_string (void)
{
- switch (this->et ())
+ switch (this->et ())
{
case AST_Expression::EV_short:
return "CORBA::Short";
@@ -192,4 +170,3 @@ be_constant::exprtype_to_string (void)
// Narrowing
IMPL_NARROW_METHODS2 (be_constant, AST_Constant, be_decl)
IMPL_NARROW_FROM_DECL (be_constant)
-
diff --git a/TAO/TAO_IDL/be/be_interface.cpp b/TAO/TAO_IDL/be/be_interface.cpp
index fccfc0218fa..6c3a63f5f1d 100644
--- a/TAO/TAO_IDL/be/be_interface.cpp
+++ b/TAO/TAO_IDL/be/be_interface.cpp
@@ -205,7 +205,7 @@ int be_interface::gen_client_header (void)
// generate a TAO-specific _bind method similar to what Orbix and VisiBroker
// have
*ch << "static " << this->local_name () << "_ptr _bind (const char *host, "
- << "CORBA::ULong port, const char *key, CORBA::Environment &env);\n\n";
+ << "CORBA::UShort port, const char *key, CORBA::Environment &env);\n\n";
// generate code for the interface definition by traversing thru the
// elements of its scope. We depend on the front-end to have made sure
@@ -367,7 +367,7 @@ int be_interface::gen_client_stubs (void)
// the _bind method
*cs << this->name () << "_ptr " << this->name () << "::_bind (" <<
- "const char *host, CORBA::ULong port, const char *key, " <<
+ "const char *host, CORBA::UShort port, const char *key, " <<
"CORBA::Environment &env)" << nl;
*cs << "{\n";
cs->incr_indent ();
diff --git a/TAO/TAO_IDL/be/be_state.cpp b/TAO/TAO_IDL/be/be_state.cpp
index 160b13df689..d79ca94e212 100644
--- a/TAO/TAO_IDL/be/be_state.cpp
+++ b/TAO/TAO_IDL/be/be_state.cpp
@@ -595,7 +595,12 @@ be_state_union_public_ci::gen_code (be_type *bt, be_decl *d, be_type *type)
nl;
}
*os << "// set the value" << nl;
- *os << "this->" << ub->local_name () << "_ = val;\n";
+ *os << "if (!this->" << ub->local_name () << "_) // does not exist"
+ << nl ;
+ *os << "\tthis->" << ub->local_name () <<
+ "_ = new CORBA::String_var (val);" << nl;
+ *os << "else" << nl;
+ *os << "\t*this->" << ub->local_name () << "_ = val;\n";
}
else
{
@@ -637,7 +642,12 @@ be_state_union_public_ci::gen_code (be_type *bt, be_decl *d, be_type *type)
nl;
}
*os << "// set the value" << nl;
- *os << "this->" << ub->local_name () << "_ = val;\n";
+ *os << "if (!this->" << ub->local_name () << "_) // does not exist"
+ << nl ;
+ *os << "\tthis->" << ub->local_name () <<
+ "_ = new CORBA::String_var (val);" << nl;
+ *os << "else" << nl;
+ *os << "\t*this->" << ub->local_name () << "_ = val;\n";
}
else
{
@@ -679,7 +689,12 @@ be_state_union_public_ci::gen_code (be_type *bt, be_decl *d, be_type *type)
nl;
}
*os << "// set the value" << nl;
- *os << "this->" << ub->local_name () << "_ = val;\n";
+ *os << "if (!this->" << ub->local_name () << "_) // does not exist"
+ << nl ;
+ *os << "\tthis->" << ub->local_name () <<
+ "_ = new CORBA::String_var (val);" << nl;
+ *os << "else" << nl;
+ *os << "\t*this->" << ub->local_name () << "_ = val;\n";
}
else
{
@@ -702,7 +717,7 @@ be_state_union_public_ci::gen_code (be_type *bt, be_decl *d, be_type *type)
" (void) const // get method" << nl;
*os << "{\n";
os->incr_indent ();
- *os << "return this->" << ub->local_name () << "_;\n";
+ *os << "return *this->" << ub->local_name () << "_;\n";
os->decr_indent ();
*os << "}\n\n";
}
@@ -849,12 +864,12 @@ be_state_union_private_ch::gen_code (be_type *bt, be_decl *d, be_type *type)
os->indent (); // start from current indentation
if (bt->node_type () == AST_Decl::NT_typedef)
{
- *os << bt->nested_type_name (bu, "_var") << " " << ub->local_name () <<
+ *os << bt->nested_type_name (bu, "_var") << " *" << ub->local_name () <<
"_;\n";
}
else
{
- *os << "CORBA::String_var " << ub->local_name () << "_;\n";
+ *os << "CORBA::String_var *" << ub->local_name () << "_;\n";
}
}
break;
diff --git a/TAO/TAO_IDL/be/be_typedef.cpp b/TAO/TAO_IDL/be/be_typedef.cpp
index c736c6bde86..cdb4fe843fe 100644
--- a/TAO/TAO_IDL/be/be_typedef.cpp
+++ b/TAO/TAO_IDL/be/be_typedef.cpp
@@ -54,11 +54,13 @@ be_typedef::gen_client_header (void)
{
be_type *bt; // type node
be_state *s; // state based code gen object
+ TAO_OutStream *ch; // client header
if (!this->cli_hdr_gen_) // not already generated
{
// retrieve a singleton instance of the code generator
TAO_CodeGen *cg = TAO_CODEGEN::instance ();
+ ch = cg->client_header ();
cg->push (TAO_CodeGen::TAO_TYPEDEF_CH);
cg->node (this); // pass ourselves. For typedefs, this is very important,
// because other nodes's code generation may depend on
@@ -75,6 +77,22 @@ be_typedef::gen_client_header (void)
return -1;
}
+ // generate the typecode decl for this typedef node
+ if (this->is_nested ())
+ {
+ // we have a scoped name
+ ch->indent ();
+ *ch << "static CORBA::TypeCode_ptr " << this->tc_name
+ ()->last_component () << ";\n\n";
+ }
+ else
+ {
+ // we are in the ROOT scope
+ ch->indent ();
+ *ch << "extern CORBA::TypeCode_ptr " << this->tc_name
+ ()->last_component () << ";\n\n";
+ }
+
cg->pop ();
this->cli_hdr_gen_ = I_TRUE;
}
@@ -89,9 +107,6 @@ be_typedef::gen_client_stubs (void)
be_type *bt;
be_state *s; // state based code gen object
- // Macro to avoid "warning: unused parameter" type warning.
- ACE_UNUSED_ARG (nl);
-
if (!this->cli_stub_gen_)
{
// retrieve a singleton instance of the code generator
@@ -115,31 +130,28 @@ be_typedef::gen_client_stubs (void)
return -1;
}
-#if 0
// generate the typecode information here
cs->indent (); // start from current indentation level
*cs << "static const CORBA::Long _oc_" << this->flatname () << "[] =" <<
nl;
*cs << "{\n";
cs->incr_indent (0);
- // note that we just need the parameters here and hence we generate the
- // encapsulation for the parameters
- bt = this->primitive_base_type ();
- if (bt->gen_encapsulation () == -1)
+ if (this->gen_encapsulation () == -1)
{
- ACE_ERROR ((LM_ERROR, "Error generating encapsulation\n\n"));
+ ACE_ERROR ((LM_ERROR, "Error generating typecode\n\n"));
return -1;
}
cs->decr_indent ();
*cs << "};" << nl;
*cs << "static CORBA::TypeCode _tc__tc_" << this->flatname () <<
- " (CORBA::tk_struct, sizeof (_oc_" << this->flatname () <<
+ " (CORBA::tk_alias, sizeof (_oc_" << this->flatname () <<
"), (unsigned char *) &_oc_" << this->flatname () <<
", CORBA::B_FALSE);" << nl;
*cs << "CORBA::TypeCode_ptr " << this->tc_name () << " = &_tc__tc_" <<
this->flatname () << ";\n\n";
-#endif
+
+
this->cli_stub_gen_ = I_TRUE;
cg->pop ();
}
@@ -200,25 +212,101 @@ be_typedef::gen_server_inline (void)
int
be_typedef::gen_typecode (void)
{
+ TAO_OutStream *cs; // output stream
+ TAO_NL nl; // end line
+ TAO_CodeGen *cg = TAO_CODEGEN::instance ();
+
+ cs = cg->client_stubs ();
+ cs->indent (); // start from whatever indentation level we were at
+
+ *cs << "CORBA::tk_alias, // typecode kind for typedefs" << nl;
+ *cs << this->tc_encap_len () << ", // encapsulation length\n";
+ // now emit the encapsulation
+ cs->incr_indent (0);
+ if (this->gen_encapsulation () == -1)
+ {
+ return -1;
+ }
return 0;
}
long
be_typedef::tc_size (void)
{
- return 0;
+ // 4 bytes for enumeration, 4 bytes for storing encap length val, followed by the
+ // actual encapsulation length
+ return 4 + 4 + this->tc_encap_len ();
}
+// generate encapsulation. A typedef is an alias to its base type
int
be_typedef::gen_encapsulation (void)
{
+ TAO_OutStream *cs; // output stream
+ TAO_NL nl; // end line
+ TAO_CodeGen *cg = TAO_CODEGEN::instance ();
+ long i, arrlen;
+ long *arr; // an array holding string names converted to array of longs
+ be_type *bt; // base type
+
+ cs = cg->client_stubs ();
+ cs->indent (); // start from whatever indentation level we were at
+
+ *cs << "TAO_ENCAP_BYTE_ORDER, // byte order" << nl;
+ // generate repoID
+ *cs << (ACE_OS::strlen (this->repoID ())+1) << ", ";
+ (void)this->tc_name2long (this->repoID (), arr, arrlen);
+ for (i=0; i < arrlen; i++)
+ {
+ cs->print ("0x%x, ", arr[i]);
+ }
+ *cs << " // repository ID = " << this->repoID () << nl;
+
+ // generate name
+ *cs << (ACE_OS::strlen (this->local_name ()->get_string ())+1) << ", ";
+ (void)this->tc_name2long(this->local_name ()->get_string (), arr, arrlen);
+ for (i=0; i < arrlen; i++)
+ {
+ cs->print ("0x%x, ", arr[i]);
+ }
+ *cs << " // name = " << this->local_name () << nl;
+
+ // generate typecode for the base type
+ bt = be_type::narrow_from_decl (this->base_type ());
+ if (!bt || (bt->gen_typecode () == -1))
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "be_typedef::gen_encapsulation failed for base type\n"),
+ -1);
+ }
return 0;
}
long
be_typedef::tc_encap_len (void)
{
- return 0;
+ if (this->encap_len_ == -1) // not computed yet
+ {
+ be_type *bt; // base type
+ this->encap_len_ = 4; // holds the byte order flag
+
+ this->encap_len_ += this->repoID_encap_len (); // repoID
+
+ // do the same thing for the local name
+ this->encap_len_ += this->name_encap_len ();
+
+ // add the encapsulation length of our base type
+ bt = be_type::narrow_from_decl (this->base_type ());
+ if (!bt)
+ {
+ ACE_ERROR ((LM_ERROR,
+ "be_typedef::tc_encap_len - bad base type\n"));
+ return 0;
+ }
+ this->encap_len_ += bt->tc_encap_len ();
+
+ }
+ return this->encap_len_;
}
// Narrowing
diff --git a/TAO/TAO_IDL/be_include/be_codegen.h b/TAO/TAO_IDL/be_include/be_codegen.h
index fb67433e254..f0cd8fa1ea0 100644
--- a/TAO/TAO_IDL/be_include/be_codegen.h
+++ b/TAO/TAO_IDL/be_include/be_codegen.h
@@ -18,7 +18,7 @@
#if !defined (TAO_BE_CODEGEN_H)
#define TAO_BE_CODEGEN_H
-#define NAMEBUFSIZE 128
+#define NAMEBUFSIZE 1024
// maximum length of static buffers used to store names
class TAO_CodeGen