/** Find or create a buffer for the input BufferSymbol */ public BufferScope getBufferForReference(TableBuffer symbol) { BufferScope buffer = getBufferScope(symbol, BufferScope.Strength.REFERENCE); if (buffer == null) buffer = getBufferForReferenceSub(symbol); // Yes, add reference to outer blocks, even if we got this buffer from // an outer block. Might have blocks in between which need the reference // to be added. addBufferScopeReferences(buffer); return buffer; } // getBufferForReference
/** * Called by Frame.setFrameScopeBlock() - not intended to be called by any client code. This should only be called by * the Frame object itself. Adds a frame to this or the appropriate parent block. Returns the scoping block. Frames * are scoped to FOR and REPEAT blocks, or else to a symbol scoping block. They may also be scoped with a DO WITH * FRAME block, but that is handled elsewhere. */ public Block addFrame(Frame frame) { if (canScopeFrame()) { frames.add(frame); return this; } else return parent.addFrame(frame); }
/** * Create a "strong" buffer scope. This is called within a DO FOR or REPEAT FOR statement. * * @param anode Is the RECORD_NAME node. It must already have the BufferSymbol linked to it. */ @Override public void strongScope(JPNode anode) { currentBlock.addStrongBufferScope((RecordNameNode) anode); }
/** * From the nearest frame scoping block, get the default (possibly unnamed) frame if it exists. Returns null if no * default frame has been established yet. */ public Frame getDefaultFrame() { if (defaultFrame != null) return defaultFrame; if (!canScopeFrame()) return parent.getDefaultFrame(); return null; }
/** Attempt to get or raise a BufferScope in this block. */ private BufferScope getBufferScope(TableBuffer symbol, BufferScope.Strength creating) { // First try to find an existing buffer scope for this symbol. BufferScope buff = findBufferScope(symbol); if (buff != null) return buff; return getBufferScopeSub(symbol, creating); }
@Override public void funcDef(JPNode funcAST, JPNode idAST) { LOG.trace("Entering funcDef {} {}", funcAST, idAST); /* * If this function definition had a function forward declaration, then we use the block and scope from that * declaration, in case it is where the parameters were defined. (You can define the params in the FORWARD, and * leave them out at the body.) * * However, if this statement re-defines the formal args, then we use this statement's scope - because the formal * arg names from here will be in effect rather than the names from the FORWARD. (The names don't have to match.) */ if (!currentRoutine.getParameters().isEmpty()) return; TreeParserSymbolScope forwardScope = funcForwards.get(idAST.getText()); if (forwardScope != null) { Routine routine = (Routine) forwardScope.getRootBlock().getNode().getSymbol(); scopeSwap(forwardScope); BlockNode blocknode = (BlockNode) funcAST; blocknode.setBlock(currentBlock); blocknode.setSymbol(routine); routine.setDefOrIdNode(blocknode); currentRoutine = routine; } }
private BufferScope getBufferForReferenceSub(TableBuffer symbol) { if (!canScopeBufferReference(symbol)) return parent.getBufferForReferenceSub(symbol); return new BufferScope(this, symbol, BufferScope.Strength.REFERENCE); }
/** * In the nearest frame scoping block, set the default implicit (unnamed) frame. This should only be called by the * Frame object itself. Returns the Block that scopes the frame. */ public Block setDefaultFrameImplicit(Frame frame) { if (canScopeFrame()) { this.defaultFrame = frame; frames.add(frame); return this; } else return parent.setDefaultFrameImplicit(frame); }
/** * Create a "weak" buffer scope. This is called within a FOR or PRESELECT statement. * * @param symbol The RECORD_NAME node. It must already have the BufferSymbol linked to it. */ public BufferScope addWeakBufferScope(TableBuffer symbol) { BufferScope buff = getBufferScope(symbol, BufferScope.Strength.WEAK); if (buff == null) buff = new BufferScope(this, symbol, BufferScope.Strength.WEAK); // Yes, add reference to outer blocks, even if we got this buffer from // an outer block. Might have blocks in between which need the reference // to be added. addBufferScopeReferences(buff); bufferScopes.add(buff); // necessary in case this is DO..PRESELECT block return buff; } // addWeakBufferScope
currentBlock.setParent(b); String buffName = recordAST.getText(); ITable table; currentBlock.addHiddenCursor(recordNode);
private BufferScope getBufferScopeSub(TableBuffer symbol, BufferScope.Strength creating) { BufferScope buff = parent.getBufferScopeSub(symbol, creating); if (buff != null) return buff; return null; if (!canScopeBufferReference(symbol)) return null;
case REFUP: case UPDATING: recordNode.setBufferScope(currentBlock.getBufferForReference(buffer)); break; case INITWEAK: recordNode.setBufferScope(currentBlock.addWeakBufferScope(buffer)); break; default:
/** Beginning of a block. */ @Override public void blockBegin(JPNode blockAST) { LOG.trace("Entering blockBegin {}", blockAST); BlockNode blockNode = (BlockNode) blockAST; currentBlock = pushBlock(new Block(currentBlock, blockNode)); blockNode.setBlock(currentBlock); }
/** * Create a "strong" buffer scope. This is called within a DO FOR or REPEAT FOR statement. A STRONG scope prevents the * scope from being raised to an enclosing block. Note that the compiler performs additional checks here that we * don't. * * @param node The RECORD_NAME node. It must already have the BufferSymbol linked to it. */ public void addStrongBufferScope(RecordNameNode node) { TableBuffer symbol = node.getTableBuffer(); BufferScope buff = new BufferScope(this, symbol, BufferScope.Strength.STRONG); bufferScopes.add(buff); addBufferScopeReferences(buff); node.setBufferScope(buff); } // addStrongBufferScope
/** Find nearest BufferScope for a BufferSymbol, if any */ private BufferScope findBufferScope(TableBuffer symbol) { for (BufferScope buff : bufferScopes) { if (buff.getSymbol() != symbol) continue; if (buff.getBlock() == this) return buff; } if (parent != null && symbol.getScope().getRootBlock() != this) return parent.findBufferScope(symbol); return null; }
/** * Initialize the frame and set the frame scope if not done already. Returns the frameScopeBlock. * * @see #isInitialized() */ public Block initialize(Block block) { if (initialized) return frameScopeBlock; initialized = true; if (frameScopeBlock == null) frameScopeBlock = block.addFrame(this); return frameScopeBlock; }
@Override public void funcDef(JPNode funcAST, JPNode idAST) { LOG.trace("Entering funcDef {} {}", funcAST, idAST); /* * If this function definition had a function forward declaration, then we use the block and scope from that * declaration, in case it is where the parameters were defined. (You can define the params in the FORWARD, and * leave them out at the body.) * * However, if this statement re-defines the formal args, then we use this statement's scope - because the formal * arg names from here will be in effect rather than the names from the FORWARD. (The names don't have to match.) */ if (!currentRoutine.getParameters().isEmpty()) return; TreeParserSymbolScope forwardScope = funcForwards.get(idAST.getText()); if (forwardScope != null) { Routine routine = (Routine) forwardScope.getRootBlock().getNode().getSymbol(); scopeSwap(forwardScope); BlockNode blocknode = (BlockNode) funcAST; blocknode.setBlock(currentBlock); blocknode.setSymbol(routine); routine.setDefOrIdNode(blocknode); currentRoutine = routine; } }
private BufferScope getBufferForReferenceSub(TableBuffer symbol) { if (!canScopeBufferReference(symbol)) return parent.getBufferForReferenceSub(symbol); return new BufferScope(this, symbol, BufferScope.Strength.REFERENCE); }
/** * From the nearest frame scoping block, get the default (possibly unnamed) frame if it exists. Returns null if no * default frame has been established yet. */ public Frame getDefaultFrame() { if (defaultFrame != null) return defaultFrame; if (!canScopeFrame()) return parent.getDefaultFrame(); return null; }
/** Attempt to get or raise a BufferScope in this block. */ private BufferScope getBufferScope(TableBuffer symbol, BufferScope.Strength creating) { // First try to find an existing buffer scope for this symbol. BufferScope buff = findBufferScope(symbol); if (buff != null) return buff; return getBufferScopeSub(symbol, creating); }