Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / ast / ast_annotation_member.cpp
blobd15d73b557a4982326b7fdb24a2bacc4f9507ef0
1 /**
2 * Abstract Syntax Tree Node for a Member Value of an Annotation
3 */
5 #include "ast_annotation_member.h"
6 #include "ast_type.h"
7 #include "utl_scope.h"
9 #include "ast_enum.h"
10 #include "ast_enum_val.h"
12 AST_Decl::NodeType const AST_Annotation_Member::NT =
13 AST_Decl::NT_annotation_member;
15 AST_Annotation_Member::AST_Annotation_Member (
16 AST_Expression::ExprType expr_type, AST_Type *type, UTL_ScopedName *name)
17 : AST_Decl (NT, name),
18 AST_Field (type, name, vis_NA),
19 expr_type_ (expr_type),
20 value_ (0)
24 AST_Annotation_Member::AST_Annotation_Member (
25 AST_Decl::NodeType nt,
26 AST_Expression::ExprType expr_type, AST_Type *type, UTL_ScopedName *name)
27 : AST_Decl (nt, name),
28 AST_Field (nt, type, name, vis_NA),
29 expr_type_ (expr_type),
30 value_ (0)
34 AST_Annotation_Member::AST_Annotation_Member (
35 UTL_ScopedName *name,
36 AST_Annotation_Member *other)
37 : AST_Decl (name, dynamic_cast<AST_Decl*>(other)),
38 AST_Field (name, dynamic_cast<AST_Field*>(other)),
39 expr_type_ (other->expr_type ()),
40 value_ (other->value () ?
41 new AST_Expression (other->value (), other->expr_type ()) : 0)
45 AST_Annotation_Member::~AST_Annotation_Member ()
47 delete value_;
50 void
51 AST_Annotation_Member::destroy ()
53 if (value_)
55 value_->destroy ();
57 AST_Field::destroy ();
60 IMPL_NARROW_FROM_DECL (AST_Annotation_Member);
61 IMPL_NARROW_FROM_SCOPE (AST_Annotation_Member);
63 void
64 AST_Annotation_Member::dump (ACE_OSTREAM_TYPE &o)
66 AST_Field::dump (o);
67 if (field_type () && value_)
69 dump_i (o, " default ");
70 if (field_type ()->node_type () == AST_Decl::NT_enum)
72 dynamic_cast<AST_Enum*> (field_type ())->
73 lookup_by_value (value_)->name ()->dump (o);
75 else
77 value_->dump (o);
82 AST_Expression *
83 AST_Annotation_Member::value ()
85 return value_;
88 void
89 AST_Annotation_Member::value (AST_Expression *value)
91 if (value_)
93 value_->destroy ();
94 delete value_;
97 value_ = value;
100 AST_Expression::ExprType
101 AST_Annotation_Member::expr_type ()
103 return expr_type_;
106 bool
107 AST_Annotation_Member::invalid_value ()
109 return !value () || !value ()->ev ();