Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Phase 1 state machines] Add a protected function for getting the state #530

Closed
2 tasks
bocchino opened this issue Nov 11, 2024 · 3 comments · Fixed by #532
Closed
2 tasks

[Phase 1 state machines] Add a protected function for getting the state #530

bocchino opened this issue Nov 11, 2024 · 3 comments · Fixed by #532
Assignees
Labels
code generation Issues related to code generation

Comments

@bocchino
Copy link
Collaborator

bocchino commented Nov 11, 2024

In Phase 1 state machines, the state machine instance variables are private in the auto-generated component base class. This is so that the implementation can't access the state machine instance directly; it has to go through the interface provided by the component base class. However, the implementation needs to be able to query the state of the state machine. So we need to add a protected function for getting the state to the component interface.

  • Revise code gen
  • Update unit tests
@bocchino bocchino added the code generation Issues related to code generation label Nov 11, 2024
@bocchino
Copy link
Collaborator Author

The state getter function should work the same way as it does for Phase 2 state machines. The current documentation is here:

https://github.com/bocchino/fprime/blob/fpp-state-machines/docs/Design/state-machines.md#541-implemented-functions

The current implementation is here:

private def getStateGetterFunction(smi: StateMachineInstance): CppDoc.Class.Member = {
val smiName = smi.getName
val smName = writeStateMachineImplType(smi.symbol)
functionClassMember(
Some(s"Get the state of state machine instance $smiName"),
s"${smiName}_getState",
Nil,
CppDoc.Type(s"$smName::State", Some(s"$componentClassName::$smName::State")),
lines(s"return this->m_stateMachine_$smiName.getState();"),
CppDoc.Function.NonSV,
CppDoc.Function.Const
)
}

@bocchino
Copy link
Collaborator Author

We should add the new function here:

def getFunctionMembers: List[CppDoc.Class.Member] = {
List.concat(
getOverflowHooks,
getSignalSendMember
)
}

@bocchino
Copy link
Collaborator Author

The unit tests to update are here:

https://github.com/nasa/fpp/tree/main/compiler/tools/fpp-to-cpp/test/component/base

./run in that directory will run the tests (you have to run ./install in fpp/compiler/tools first to install the tools). ./update-ref in that directory will update the reference output. A good procedure is

  1. Make changes to the code generator.
  2. Run ./update-ref
  3. Run git diff to make sure that everything looks good.
  4. Commit the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code generation Issues related to code generation
Projects
Development

Successfully merging a pull request may close this issue.

2 participants