Skip to content

Commit

Permalink
(Jovial) Moved SgJovialBitVal to Rosebud and regenerated code
Browse files Browse the repository at this point in the history
Here's the steps for moving a Jovial AST node definition from ROSETTA
to Rosebud, assuming the class is named "SgJovialFoo":

1. Create the file src/AstNodes/Jovial/SgJovialFoo.h. In this file,
   declare the class with the proper base class. Standard ROSE header
   files are included automatically, but you might need to include
   more. See examples in src/AstNodes/BinaryAnalysis/*.h.

       `class SgJovialFoo: public SgWhatever {`

2. Search for "JovialFoo" (the class name without the leading "Sg") in
   src/ROSETTA/src/*.C. You'll find a smattering of things scattered all
   over the place. Copy these things to the new SgJovialFoo.h file as
   follows:

   a. `NEW_TERMINAL_MACRO(JovialFoo, "JovialFoo", "SOME_TAG");`

      Remove this line. It is not needed. The "SOME_TAG" string will
      always be generated as "JovialFooTag".

   b. `JovialFoo` in the NEW_NONTERMINAL_MACRO for the base class.

      Replace `JovialFoo` with `*lookupTerminal(terminalList, "JovialFoo")`

   c. Calls to "setFunctionSource", "setFunctionPrototype",
      "setDataPrototype", and "editSubstitute".

      If the indicated text to copy is empty, delete this line.

      If the indicated text is for the SgJovialFoo class definition
      and is copied verbatim by ROSETTA (no substitutions) then move
      it to the new SgJovialFoo.h file.

      If the indicated text is for an SgJovialFoo member
      definition (i.e., a member function implementation) and is
      copied verbatim by ROSETTA, then move it to a new SgJovialFoo.C
      file somewhere under the $ROSE/src directory. There's no reason
      it needs to be copied by ROSETTA.

      In other cases, when ROSETTA does text substitutions during the
      copy, my experience has been that all this junk could have been
      designed using C++ directly (virtual dispatch, template
      metaprogramming, introspection) instead of being generated. But
      since that's an improvement for another day, the temporary
      solution is to add `#pragma rosetta ...` to the new
      SgJovialFoo.h file. The "..." part is everything after
      "JovialFoo." Example: `JovialFoo.setFunctionSource("X","Y");`
      will become `#pragma rosetta setFunctionSource("X","Y")`. The
      trailing semicolon is optional and usually omitted in pragmas.

3. Regenerate files. See $ROSE/src/generated/README.md. In short, go
   to $ROSE_BUILD/src/Rosebud and run

      $ROSE_SOURCE/src/Rosebud/generate ./rosebud

4. Build like normal. For `make` this probably means you'll need to do
   a `make clean` first. More modern build systems handle things
   automatically.

If you want to do this for nodes other than Jovial or BinaryAnalysis,
see the previous commit for how Jovial was set up and do something similar.

RPM-395
  • Loading branch information
matzke1 committed Apr 21, 2023
1 parent 78ad282 commit 37824db
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 15 deletions.
14 changes: 14 additions & 0 deletions src/AstNodes/Jovial/SgJovialBitVal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class SgJovialBitVal: public SgValueExp {

[[using Rosebud: rosetta, ctor_arg]]
std::string valueString;

// FIXME[Robb Matzke 2023-04-21]: These pragmas are compatibility of last resort. Please remove when possible because in my
// experience most of this stuff doesn't need to be generated--it can be written directly in C++ using virtual functions,
// template meta programming, and introspection rather than text substitution.
#pragma rosetta setFunctionSource("SOURCE_EMPTY_POST_CONSTRUCTION_INITIALIZATION", "../Grammar/Expression.code")
#pragma rosetta setFunctionPrototype("HEADER_JOVIAL_BIT_VALUE_EXPRESSION", "../Grammar/Expression.code")
#pragma rosetta setFunctionSource("SOURCE_JOVIAL_BIT_VALUE_EXPRESSION","../Grammar/Expression.code")
#pragma rosetta setFunctionSource("SOURCE_GET_TYPE_GENERIC","../Grammar/Expression.code");
#pragma rosetta editSubstitute("GENERIC_TYPE", "SgJovialBitType");
};
13 changes: 2 additions & 11 deletions src/ROSETTA/src/expression.C
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ Grammar::setUpExpressions ()
NEW_TERMINAL_MACRO (Float80Val, "Float80Val", "FLOAT_80_VAL" );
NEW_TERMINAL_MACRO (Float128Val, "Float128Val", "FLOAT_128_VAL" );
NEW_TERMINAL_MACRO (AdaFloatVal, "AdaFloatVal", "ADA_FLOAT_VAL" );
NEW_TERMINAL_MACRO (JovialBitVal, "JovialBitVal", "JOVIAL_BIT_VAL" );

// DQ (7/31/2014): Added support for C++11 nullptr constant value expression (using type nullptr_t).
NEW_TERMINAL_MACRO (NullptrValExp, "NullptrValExp", "NULLPTR_VAL" );
Expand Down Expand Up @@ -439,7 +438,8 @@ Grammar::setUpExpressions ()
LongIntVal | LongLongIntVal | UnsignedLongLongIntVal | UnsignedLongVal | FloatVal |
DoubleVal | LongDoubleVal | ComplexVal | UpcThreads | UpcMythread |
TemplateParameterVal | NullptrValExp | Char16Val | Char32Val | Float80Val |
Float128Val | VoidVal | AdaFloatVal | JovialBitVal /* | LabelAddressVal */,
Float128Val | VoidVal | AdaFloatVal |
*lookupTerminal(terminalList, "JovialBitVal"),
"ValueExp","ValueExpTag", false);

NEW_NONTERMINAL_MACRO (ExprListExp,
Expand Down Expand Up @@ -869,7 +869,6 @@ Grammar::setUpExpressions ()
Float80Val.setFunctionSource ( "SOURCE_EMPTY_POST_CONSTRUCTION_INITIALIZATION", "../Grammar/Expression.code" );
Float128Val.setFunctionSource ( "SOURCE_EMPTY_POST_CONSTRUCTION_INITIALIZATION", "../Grammar/Expression.code" );
AdaFloatVal.setFunctionSource ( "SOURCE_EMPTY_POST_CONSTRUCTION_INITIALIZATION", "../Grammar/Expression.code" );
JovialBitVal.setFunctionSource ( "SOURCE_EMPTY_POST_CONSTRUCTION_INITIALIZATION", "../Grammar/Expression.code" );

VoidVal.setFunctionSource ( "SOURCE_EMPTY_POST_CONSTRUCTION_INITIALIZATION", "../Grammar/Expression.code" );

Expand Down Expand Up @@ -1835,10 +1834,6 @@ Grammar::setUpExpressions ()
AdaFloatVal.setDataPrototype ( "std::string", "valueString", "= \"\"",
CONSTRUCTOR_PARAMETER, BUILD_ACCESS_FUNCTIONS, NO_TRAVERSAL, NO_DELETE);

JovialBitVal.setFunctionPrototype ( "HEADER_JOVIAL_BIT_VALUE_EXPRESSION", "../Grammar/Expression.code" );
JovialBitVal.setDataPrototype ( "std::string", "valueString", "= \"\"",
CONSTRUCTOR_PARAMETER, BUILD_ACCESS_FUNCTIONS, NO_TRAVERSAL, NO_DELETE);

// DQ (11/28/2011): Adding template declaration support in the AST (see test2011_164.C).
TemplateParameterVal.setFunctionPrototype ( "HEADER_TEMPLATE_PARAMETER_VALUE_EXPRESSION", "../Grammar/Expression.code" );
TemplateParameterVal.setDataPrototype ( "int", "template_parameter_position", "= -1",
Expand Down Expand Up @@ -3093,7 +3088,6 @@ Grammar::setUpExpressions ()
Float80Val.setFunctionSource ( "SOURCE_FLOAT_80_VALUE_EXPRESSION","../Grammar/Expression.code" );
Float128Val.setFunctionSource ( "SOURCE_FLOAT_128_VALUE_EXPRESSION","../Grammar/Expression.code" );
AdaFloatVal.setFunctionSource ( "SOURCE_ADA_FLOAT_VALUE_EXPRESSION","../Grammar/Expression.code" );
JovialBitVal.setFunctionSource ( "SOURCE_JOVIAL_BIT_VALUE_EXPRESSION","../Grammar/Expression.code" );
AdaUnitRefExp.setFunctionSource ( "SOURCE_ADA_UNIT_REF_EXPRESSION","../Grammar/Expression.code" );
AdaTaskRefExp.setFunctionSource ( "SOURCE_ADA_TASK_REF_EXPRESSION","../Grammar/Expression.code" );
AdaProtectedRefExp.setFunctionSource ( "SOURCE_ADA_PROTECTED_REF_EXPRESSION","../Grammar/Expression.code" );
Expand Down Expand Up @@ -3388,7 +3382,6 @@ Grammar::setUpExpressions ()
Float128Val.setFunctionSource ( "SOURCE_GET_TYPE_GENERIC","../Grammar/Expression.code" );
ComplexVal.setFunctionSource ( "SOURCE_GET_TYPE_COMPLEX","../Grammar/Expression.code" );
AdaFloatVal.setFunctionSource ( "SOURCE_GET_TYPE_GENERIC","../Grammar/Expression.code" );
JovialBitVal.setFunctionSource ( "SOURCE_GET_TYPE_GENERIC","../Grammar/Expression.code" );

VoidVal.setFunctionSource ( "SOURCE_GET_TYPE_GENERIC","../Grammar/Expression.code" );

Expand Down Expand Up @@ -3446,8 +3439,6 @@ Grammar::setUpExpressions ()
// \todo set type according to Asis frontend
AdaFloatVal.editSubstitute ( "GENERIC_TYPE", "SgTypeFloat" );

JovialBitVal.editSubstitute ( "GENERIC_TYPE", "SgJovialBitType" );

ComplexVal.editSubstitute ( "GENERIC_TYPE", "SgTypeComplex" );

VoidVal.editSubstitute ( "GENERIC_TYPE", "SgTypeVoid" );
Expand Down
73 changes: 73 additions & 0 deletions src/ROSETTA/src/jovialNodes.C
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,85 @@ DOCUMENTATION_should_never_be_defined;
// base down to the leaves, we need to make sure that doxygen sees the base classes before the derived classes. So
// just list all the non-leaf classes here.
#ifdef DOCUMENTATION
class SgValueExp;
#endif // DOCUMENTATION

#ifndef DOCUMENTATION
void Grammar::setUpJovialNodes() {
#endif // !DOCUMENTATION


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SgJovialBitVal -- MACHINE GENERATED; DO NOT MODIFY --
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

DECLARE_LEAF_CLASS(JovialBitVal);

#ifdef DOCUMENTATION
class SgJovialBitVal: public SgValueExp {
#endif // DOCUMENTATION

#ifndef DOCUMENTATION
JovialBitVal.setDataPrototype(
"std::string", "valueString", "",
NO_CONSTRUCTOR_PARAMETER, NO_ACCESS_FUNCTIONS, NO_TRAVERSAL, NO_DELETE, COPY_DATA);
#endif // !DOCUMENTATION

#ifndef DOCUMENTATION
JovialBitVal.setFunctionSource("SOURCE_EMPTY_POST_CONSTRUCTION_INITIALIZATION", "../Grammar/Expression.code");
#endif // !DOCUMENTATION

#ifndef DOCUMENTATION
JovialBitVal.setFunctionPrototype("HEADER_JOVIAL_BIT_VALUE_EXPRESSION", "../Grammar/Expression.code");
#endif // !DOCUMENTATION

#ifndef DOCUMENTATION
JovialBitVal.setFunctionSource("SOURCE_JOVIAL_BIT_VALUE_EXPRESSION","../Grammar/Expression.code");
#endif // !DOCUMENTATION

#ifndef DOCUMENTATION
JovialBitVal.setFunctionSource("SOURCE_GET_TYPE_GENERIC","../Grammar/Expression.code");
#endif // !DOCUMENTATION

#ifndef DOCUMENTATION
JovialBitVal.editSubstitute("GENERIC_TYPE", "SgJovialBitType");
#endif // !DOCUMENTATION

DECLARE_OTHERS(JovialBitVal);
#if defined(SgJovialBitVal_OTHERS) || defined(DOCUMENTATION)

public:
std::string const& get_valueString() const;
void set_valueString(std::string const&);
// FIXME[Robb Matzke 2023-04-21]: These pragmas are compatibility of last resort. Please remove when possible because in my
// experience most of this stuff doesn't need to be generated--it can be written directly in C++ using virtual functions,
// template meta programming, and introspection rather than text substitution.

public:
/** Destructor. */
virtual ~SgJovialBitVal();

public:
/** Default constructor. */
SgJovialBitVal();

public:
/** Constructor. */
explicit SgJovialBitVal(std::string const& valueString);

protected:
/** Initialize all properties that have explicit initial values.
*
* This function is mostly for use in user-defined constructors where the user desires to initialize
* all the properties but does not know the names of the data members that store the property values.
* This function initializes the properties that have explicit initializations within this class, but
* does not recursively initialize base classes. */
void initializeProperties();
#endif // SgJovialBitVal_OTHERS
#ifdef DOCUMENTATION
};
#endif // DOCUMENTATION

#ifndef DOCUMENTATION
} // Grammar::setUpBinaryInstruction
#endif // !DOCUMENTATION
4 changes: 2 additions & 2 deletions src/generated/Jovial/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# This file was generated by Rosebud
#

add_library(roseGenerated OBJECT
stub.C)
add_library(roseGenerated OBJECT
SgJovialBitVal.C)

add_dependencies(roseGeneratedJovial rosetta_generated)
2 changes: 1 addition & 1 deletion src/generated/Jovial/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ include $(top_srcdir)/config/Makefile.for.ROSE.includes.and.libs
AM_CPPFLAGS = $(ROSE_INCLUDES)
noinst_LTLIBRARIES = libroseGeneratedJovial.la
libroseGeneratedJovial_la_SOURCES = \
stub.C
SgJovialBitVal.C
33 changes: 33 additions & 0 deletions src/generated/Jovial/SgJovialBitVal.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Implementation for SgJovialBitVal -- MACHINE GENERATED; DO NOT MODIFY --
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <featureTests.h>
#include <sage3basic.h>

std::string const&
SgJovialBitVal::get_valueString() const {
return p_valueString;
}

void
SgJovialBitVal::set_valueString(std::string const& x) {
this->p_valueString = x;
set_isModified(true);
}

SgJovialBitVal::~SgJovialBitVal() {
destructorHelper();
}

SgJovialBitVal::SgJovialBitVal() {}

// The association between constructor arguments and their classes:
// property=valueString class=SgJovialBitVal
SgJovialBitVal::SgJovialBitVal(std::string const& valueString)
: p_valueString(valueString) {}

void
SgJovialBitVal::initializeProperties() {
}

2 changes: 1 addition & 1 deletion src/generated/Jovial/Tupfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

include_rules
run $(librose_compile) \
stub.C
SgJovialBitVal.C

0 comments on commit 37824db

Please sign in to comment.