Opened 15 years ago

Closed 15 years ago

#288 closed enhancement (fixed)

Support arbitrary nested scopes

Reported by: zirkel Owned by: Stephen Siegel
Priority: major Milestone: 1.1
Component: model Version: 1.1
Keywords: scope, local Cc:

Description

Currently variables can only be declared in certain scopes (global, beginning of function, etc.). We need to support variables in nested scopes.

  {...{int x;...}...}

Change History (2)

comment:1 by Stephen Siegel, 15 years ago

Component: frontmodel
Keywords: scope local added
Milestone: 1.1
Owner: set to Stephen Siegel
Status: newaccepted
Version: 1.1

Best way: add to model layer notion of "scope". Create a Scope class. A Scope tree is created during model construction. Every model location has an associated Scope node in that tree. The state of a Frame must be modified. Instead of just a list of local variables, it now has a stack of scope states, each of which has a list of local variables. When moving from one location to another, you need to see if the scope changes. The stack needs to be popped and pushed appropriately to reflect the change. When pushing, local variables must be initialized in the usual way.

Question: what if a branch leads to something in the middle of a block (goto or break, for example)? The variables should not have their initializations run, or should they? What does C say?

comment:2 by Stephen Siegel, 15 years ago

Resolution: fixed
Status: acceptedclosed

This has been implemented through the model layer. It remains for the new front end to be complete and use the new scoping functionality, but that is not part of this ticket.

Note: See TracTickets for help on using tickets.