Debian Codegraph @

net/sf/saxon/style/SourceBinding.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.style;
9
10 import net.sf.saxon.expr.*;
11 import net.sf.saxon.expr.instruct.DocumentInstr;
12 import net.sf.saxon.expr.instruct.GlobalVariable;
13 import net.sf.saxon.expr.instruct.SlotManager;
14 import net.sf.saxon.expr.instruct.ValueOf;
15 import net.sf.saxon.expr.parser.RoleDiagnostic;
16 import net.sf.saxon.lib.NamespaceConstant;
17 import net.sf.saxon.om.*;
18 import net.sf.saxon.pattern.NodeKindTest;
19 import net.sf.saxon.trans.Visibility;
20 import net.sf.saxon.trans.XPathException;
21 import net.sf.saxon.tree.AttributeLocation;
22 import net.sf.saxon.tree.iter.AxisIterator;
23 import net.sf.saxon.type.ItemType;
24 import net.sf.saxon.type.TypeHierarchy;
25 import net.sf.saxon.type.UType;
26 import net.sf.saxon.value.Cardinality;
27 import net.sf.saxon.value.SequenceType;
28 import net.sf.saxon.value.StringValue;
29 import net.sf.saxon.value.Whitespace;
30
31 import java.util.ArrayList;
32 import java.util.List;
33
34
35 /**
36 * Helper class for xsl:variable and xsl:param elements. <br>
37 */
38
39 public class SourceBinding {
40
41 private StyleElement sourceElement;
42 private StructuredQName name;
43 private Expression select = null;
44 private SequenceType declaredType = null;
45 private SequenceType inferredType = null;
46 protected SlotManager slotManager = null; // used only for global variable declarations
47 private Visibility visibility;
48 private GroundedValue<?> constantValue = null;
49
50 private int properties;
51
52 public static final int PRIVATE = 1;
53 public static final int GLOBAL = 2;
54 public static final int PARAM = 4;
55 public static final int TUNNEL = 8;
56 public static final int REQUIRED = 16;
57 public static final int IMPLICITLY_REQUIRED = 32;
58 public static final int ASSIGNABLE = 64;
59 public static final int SELECT = 128;
60 public static final int AS = 256;
61 public static final int DISALLOWS_CONTENT = 512;
62 public static final int STATIC = 2048;
63 public static final int VISIBILITY = 4096;
64 public static final int IMPLICITLY_DECLARED = 8192;
65
66 // List of VariableReference objects that reference this XSLVariableDeclaration
67 private List<BindingReference> references = new ArrayList<>(10);
68
69 public SourceBinding(StyleElement sourceElement) {
70 this.sourceElement = sourceElement;
71 }
72
73
74 public void prepareAttributes(int permittedAttributes) throws XPathException {
75
76 AttributeCollection atts = sourceElement.getAttributeList();
77
78 String selectAtt = null;
79 String asAtt = null;
80 String extraAsAtt = null;
81 String requiredAtt = null;
82 String tunnelAtt = null;
83 String assignableAtt = null;
84 String staticAtt = null;
85 String visibilityAtt = null;
86
87 for (int a = 0; a < atts.getLength(); a++) {
88 String f = atts.getQName(a);
89 if (f.equals("name")) {
90 if (name == null || name.equals(errorName())) {
91 processVariableName(atts.getValue(a));
92 }
93 } else if (f.equals("select")) {
94 if ((permittedAttributes & SELECT) != 0) {
95 selectAtt = atts.getValue(a);
96 } else {
97 sourceElement.compileErrorInAttribute(
98 "The select attribute is not permitted on a function parameter", "XTSE0760", "select");
99 }
100 } else if (f.equals("as") && ((permittedAttributes & AS) != 0)) {
101 asAtt = atts.getValue(a);
102 } else if (f.equals("required") && ((permittedAttributes & REQUIRED) != 0)) {
103 requiredAtt = Whitespace.trim(atts.getValue(a));
104 } else if (f.equals("tunnel")) {
105 tunnelAtt = Whitespace.trim(atts.getValue(a));
106 } else if (f.equals("static") && ((permittedAttributes & STATIC) != 0)) {
107 staticAtt = Whitespace.trim(atts.getValue(a));
108 } else if (f.equals("visibility") && ((permittedAttributes & VISIBILITY) != 0)) {
109 visibilityAtt = Whitespace.trim(atts.getValue(a));
110 } else if (NamespaceConstant.SAXON.equals(atts.getURI(a))) {
111 if (atts.getLocalName(a).equals("assignable") && ((permittedAttributes & ASSIGNABLE) != 0)) {
112 assignableAtt = Whitespace.trim(atts.getValue(a));
113 } else if (atts.getLocalName(a).equals("as")) {
114 extraAsAtt = atts.getValue(a);
115 } else {
116 sourceElement.checkUnknownAttribute(atts.getNodeName(a));
117 }
118 } else {
119 sourceElement.checkUnknownAttribute(atts.getNodeName(a));
120 }
121 }
122
123 if (name == null) {
124 sourceElement.reportAbsence("name");
125 name = errorName();
126 }
127
128 if (selectAtt != null) {
129 select = sourceElement.makeExpression(selectAtt, sourceElement.getAttributeList().getIndex("", "select"));
130 }
131
132 if (requiredAtt != null) {
133 boolean required = sourceElement.processBooleanAttribute("required", requiredAtt);
134 setProperty(REQUIRED, required);
135 if (required && select != null) {
136 sourceElement.compileError("xsl:param: cannot supply a default value when required='yes'");
137 }
138 }
139
140 if (tunnelAtt != null) {
141 boolean tunnel = sourceElement.processBooleanAttribute("tunnel", tunnelAtt);
142 if (tunnel && ((permittedAttributes & TUNNEL) == 0)) {
143 sourceElement.compileErrorInAttribute("The only permitted value of the 'tunnel' attribute is 'no'", "XTSE0020", "tunnel");
144 }
145 setProperty(TUNNEL, tunnel);
146 }
147
148 if (assignableAtt != null) {
149 boolean assignable = sourceElement.processBooleanAttribute("saxon:assignable", assignableAtt);
150 setProperty(ASSIGNABLE, assignable);
151 }
152
153 if (staticAtt != null) {
154 boolean statick = sourceElement.processBooleanAttribute("static", staticAtt);
155 setProperty(STATIC, statick);
156 if (statick) {
157 setProperty(SourceBinding.DISALLOWS_CONTENT, true);
158 }
159 if (statick && !hasProperty(GLOBAL)) {
160 sourceElement.compileErrorInAttribute("Only global declarations can be static", "XTSE0020", "static");
161 }
162 }
163
164 declaredType = combineTypeDeclarations(asAtt, extraAsAtt);
165
166
167 if (visibilityAtt != null) {
168 if (hasProperty(PARAM)) {
169 sourceElement.compileErrorInAttribute("The visibility attribute is not allowed on xsl:param", "XTSE0020", "visibility");
170 } else {
171 visibility = sourceElement.interpretVisibilityValue(visibilityAtt, "");
172 }
173 if (!hasProperty(GLOBAL)) {
174 sourceElement.compileErrorInAttribute("The visibility attribute is allowed only on global declarations", "XTSE0020", "visibility");
175 }
176 }
177
178 if (hasProperty(STATIC) && visibility != Visibility.PRIVATE && visibilityAtt != null) {
179 sourceElement.compileErrorInAttribute("A static variable or parameter must be private", "XTSE0020", "static");
180 }
181 }
182
183 /**
184 * This method is called to establish basic signature information for local parameters of a named template,
185 * so that this can be checked against xsl:call-template instructions. It is called while a named template
186 * is being indexed: see bug 3722.
187 *
188 * @throws XPathException if things go wrong
189 */
190
191 public void prepareTemplateSignatureAttributes() throws XPathException {
192
193 AttributeCollection atts = sourceElement.getAttributeList();
194
195 String asAtt = null;
196 String extraAsAtt = null;
197
198 for (int a = 0; a < atts.getLength(); a++) {
199 String f = atts.getQName(a);
200 if (f.equals("name")) {
201 if (name == null || name.equals(errorName())) {
202 processVariableName(atts.getValue(a));
203 }
204 } else if (f.equals("as")) {
205 asAtt = atts.getValue(a);
206 } else if (f.equals("required")) {
207 String requiredAtt = Whitespace.trim(atts.getValue(a));
208 boolean required = sourceElement.processBooleanAttribute("required", requiredAtt);
209 setProperty(REQUIRED, required);
210 } else if (f.equals("tunnel")) {
211 String tunnelAtt = Whitespace.trim(atts.getValue(a));
212 boolean tunnel = sourceElement.processBooleanAttribute("tunnel", tunnelAtt);
213 setProperty(TUNNEL, tunnel);
214 } else if (NamespaceConstant.SAXON.equals(atts.getURI(a))) {
215 if (atts.getLocalName(a).equals("as")) {
216 extraAsAtt = atts.getValue(a);
217 }
218 }
219 }
220
221 if (name == null) {
222 sourceElement.reportAbsence("name");
223 name = errorName();
224 }
225
226 declaredType = combineTypeDeclarations(asAtt, extraAsAtt);
227 }
228
229
230 private SequenceType combineTypeDeclarations(String asAtt, String extraAsAtt) {
231 SequenceType declaredType = null;
232
233 if (asAtt != null) {
234 try {
235 declaredType = sourceElement.makeSequenceType(asAtt);
236 } catch (XPathException e) {
237 sourceElement.compileErrorInAttribute(e.getMessage(), e.getErrorCodeLocalPart(), "as");
238 }
239 }
240
241 if (extraAsAtt != null) {
242 SequenceType extraResultType = null;
243 try {
244 extraResultType = sourceElement.makeExtendedSequenceType(extraAsAtt);
245 } catch (XPathException e) {
246 sourceElement.compileErrorInAttribute(e.getMessage(), e.getErrorCodeLocalPart(), "saxon:as");
247 extraResultType = SequenceType.ANY_SEQUENCE;
248 }
249 if (asAtt != null) {
250 int rel = sourceElement.getConfiguration().getTypeHierarchy().sequenceTypeRelationship(extraResultType, declaredType);
251 if (rel == TypeHierarchy.SAME_TYPE || rel == TypeHierarchy.SUBSUMED_BY) {
252 declaredType = extraResultType;
253 } else {
254 sourceElement.compileErrorInAttribute("When both are present, @saxon:as must be a subtype of @as", "SXER7TBA", "as");
255 }
256 } else {
257 declaredType = extraResultType;
258 }
259 }
260
261 return declaredType;
262
263 }
264
265 /**
266 * Get the declaration in the stylesheet
267 *
268 * @return the node in the stylesheet containing this variable binding
269 */
270
271 public StyleElement getSourceElement() {
272 return sourceElement;
273 }
274
275 /**
276 * Set the name of the variable
277 *
278 * @param name the name of the variable as a QName
279 */
280
281 public void setVariableQName(StructuredQName name) {
282 this.name = name;
283 }
284
285 /**
286 * Set the declared type of the variable
287 *
288 * @param declaredType the declared type
289 */
290
291 public void setDeclaredType(SequenceType declaredType) {
292 this.declaredType = declaredType;
293 }
294
295 /**
296 * Process the QName of the variable. Validate the name and place it in the "name" field;
297 * if invalid, construct an error message and place a dummy name in the "name" field for
298 * recovery purposes.
299 *
300 * @param nameAttribute the lexical QName
301 * @throws XPathException if the name is invalid
302 */
303
304 private void processVariableName(String nameAttribute) throws XPathException {
305 try {
306 if (nameAttribute != null) {
307 name = sourceElement.makeQName(nameAttribute);
308 }
309 } catch (XPathException err) {
310 name = errorName();
311 StructuredQName n = StructuredQName.fromClarkName("name");
312 throw new XPathException("Invalid variable name: " + err.getMessage() +
313 (nameAttribute.startsWith("$") ? " (No '$' sign needed)" : ""), "XTSE0020",
314 new AttributeLocation(sourceElement, n));
315 }
316 }
317
318 /**
319 * Fallback name to be returned if there is anything wrong with the variable's real name
320 * (after reporting an error)
321 *
322 * @return a fallback name
323 */
324
325 private StructuredQName errorName() {
326 return new StructuredQName("saxon", NamespaceConstant.SAXON, "error-variable-name");
327 }
328
329 /**
330 * Validate the declaration
331 *
332 * @throws XPathException if the declaration is invalid
333 */
334
335 public void validate() throws XPathException {
336 if (select != null && sourceElement.hasChildNodes()) {
337 sourceElement.compileError("An " + sourceElement.getDisplayName() + " element with a select attribute must be empty", "XTSE0620");
338 }
339 if (hasProperty(DISALLOWS_CONTENT) && sourceElement.hasChildNodes()) {
340 if (isStatic()) {
341 sourceElement.compileError("A static variable or parameter must have no content", "XTSE0010");
342 } else {
343 sourceElement.compileError("Within xsl:function, an xsl:param element must have no content", "XTSE0620");
344 }
345 }
346 if (visibility == Visibility.ABSTRACT && (select != null || sourceElement.hasChildNodes())) {
347 sourceElement.compileError("An abstract variable must have no select attribute and no content", "XTSE0620");
348 }
349 }
350
351 /**
352 * Hook to allow additional validation of a parent element immediately after its
353 * children have been validated.
354 *
355 * @throws XPathException if the declaration is invalid
356 */
357
358 public void postValidate() throws XPathException {
359 checkAgainstRequiredType(declaredType);
360
361 if (select == null && !hasProperty(DISALLOWS_CONTENT) && visibility != Visibility.ABSTRACT) {
362 AxisIterator kids = sourceElement.iterateAxis(AxisInfo.CHILD);
363 NodeInfo first = kids.next();
364 if (first == null) {
365 if (declaredType == null) {
366 select = new StringLiteral(StringValue.EMPTY_STRING);
367 select.setRetainedStaticContext(sourceElement.makeRetainedStaticContext());
368 } else {
369 if (sourceElement instanceof XSLLocalParam || sourceElement instanceof XSLGlobalParam) {
370 if (!hasProperty(REQUIRED)) {
371 if (Cardinality.allowsZero(declaredType.getCardinality())) {
372 select = Literal.makeEmptySequence();
373 select.setRetainedStaticContext(sourceElement.makeRetainedStaticContext());
374 } else {
375 // The implicit default value () is not valid for the required type, so
376 // it is treated as if there is no default
377 setProperty(IMPLICITLY_REQUIRED, true);
378 }
379 }
380 } else {
381 if (Cardinality.allowsZero(declaredType.getCardinality())) {
382 select = Literal.makeEmptySequence();
383 select.setRetainedStaticContext(sourceElement.makeRetainedStaticContext());
384 } else {
385 sourceElement.compileError("The implicit value () is not valid for the declared type", "XTTE0570");
386 }
387 }
388 }
389 }
390 }
391 select = sourceElement.typeCheck("select", select);
392 }
393
394 public boolean isStatic() {
395 return hasProperty(STATIC);
396 }
397
398 /**
399 * Check the supplied select expression against the required type.
400 *
401 * @param required The type required by the variable declaration, or in the case
402 * of xsl:with-param, the signature of the called template
403 */
404
405 public void checkAgainstRequiredType(SequenceType required) {
406 if (visibility != Visibility.ABSTRACT) {
407 try {
408 if (required != null) {
409 // check that the expression is consistent with the required type
410 if (select != null) {
411 int category = RoleDiagnostic.VARIABLE;
412 String errorCode = "XTTE0570";
413 if (sourceElement instanceof XSLLocalParam) {
414 category = RoleDiagnostic.PARAM;
415 errorCode = "XTTE0600";
416 } else if (sourceElement instanceof XSLWithParam || sourceElement instanceof XSLGlobalParam) {
417 category = RoleDiagnostic.PARAM;
418 errorCode = "XTTE0590";
419 }
420 RoleDiagnostic role = new RoleDiagnostic(category, name.getDisplayName(), 0);
421 //role.setSourceLocator(new ExpressionLocation(this));
422 role.setErrorCode(errorCode);
423 select = sourceElement.getConfiguration().getTypeChecker(false).staticTypeCheck(select, required, role, sourceElement.makeExpressionVisitor());
424 } else {
425 // do the check later
426 }
427 }
428 } catch (XPathException err) {
429 err.setLocator(sourceElement); // because the expression wasn't yet linked into the module
430 sourceElement.compileError(err);
431 select = new ErrorExpression(err);
432 }
433 }
434 }
435
436
437 /**
438 * Get the name of the variable
439 *
440 * @return the variable's name
441 */
442
443 public StructuredQName getVariableQName() {
444 if (name == null) {
445 try {
446 processVariableName(sourceElement.getAttributeValue("", "name"));
447 } catch (XPathException e) {
448 return errorName();
449 }
450 }
451 return name;
452 }
453
454 /**
455 * Set a boolean property of the variable
456 *
457 * @param prop the property to be set (e.g. {@link #TUNNEL})
458 * @param flag true to set the property on, false to set it off
459 */
460
461 public void setProperty(int prop, boolean flag) {
462 if (flag) {
463 properties |= prop;
464 } else {
465 properties &= ~prop;
466 }
467 }
468
469 /**
470 * Get a boolean property of the variable
471 *
472 * @param prop the property whose value is required
473 * @return true if the variable has the specified property, otherwise false
474 */
475
476 public boolean hasProperty(int prop) {
477 return (properties & prop) != 0;
478 }
479
480 /**
481 * Get all the known references to this variable
482 *
483 * @return the list of references
484 */
485
486 public List<BindingReference> getReferences() {
487 return references;
488 }
489
490 /**
491 * Get the SlotManager associated with this stylesheet construct. The SlotManager contains the
492 * information needed to manage the local stack frames used by run-time instances of the code.
493 *
494 * @return the associated SlotManager object
495 */
496
497 public SlotManager getSlotManager() {
498 return slotManager;
499 }
500
501 /**
502 * If the element contains a sequence constructor, convert this to an expression and assign it to the
503 * select attribute
504 *
505 * @param compilation the compilation episode
506 * @param decl the declaration being compiled
507 * @throws XPathException if a static error is found, for example a type error
508 */
509
510 public void handleSequenceConstructor(Compilation compilation, ComponentDeclaration decl) throws XPathException {
511 // handle the "temporary tree" case by creating a Document sub-instruction
512 // to construct and return a document node.
513 if (sourceElement.hasChildNodes()) {
514 if (declaredType == null) {
515 Expression b = sourceElement.compileSequenceConstructor(compilation, decl, true);
516 if (b == null) {
517 b = Literal.makeEmptySequence();
518 }
519 boolean textonly = UType.TEXT.subsumes(b.getItemType().getUType());
520 String constant = null; // bug 3748
521 if (textonly && b instanceof ValueOf && ((ValueOf) b).getSelect() instanceof StringLiteral) {
522 constant = ((StringLiteral) ((ValueOf) b).getSelect()).getStringValue();
523 }
524 DocumentInstr doc = new DocumentInstr(textonly, constant);
525 doc.setContentExpression(b);
526 doc.setRetainedStaticContext(sourceElement.makeRetainedStaticContext());
527 select = doc;
528 } else {
529 select = sourceElement.compileSequenceConstructor(compilation, decl, true);
530 if (select == null) {
531 select = Literal.makeEmptySequence();
532 }
533 try {
534 RoleDiagnostic role =
535 new RoleDiagnostic(RoleDiagnostic.VARIABLE, name.getDisplayName(), 0);
536 role.setErrorCode("XTTE0570");
537 select = select.simplify();
538 select = sourceElement.getConfiguration().getTypeChecker(false).staticTypeCheck(
539 select, declaredType, role, sourceElement.makeExpressionVisitor());
540 } catch (XPathException err) {
541 err.setLocator(sourceElement);
542 sourceElement.compileError(err);
543 select = new ErrorExpression(err);
544 }
545 }
546 }
547 }
548
549 /**
550 * Get the type actually declared for the attribute
551 *
552 * @return the type appearing in the "as" attribute, or null if the attribute was absent
553 */
554
555 public SequenceType getDeclaredType() {
556 if (declaredType == null) {
557 // may be handling a forwards reference - see hof-038
558 String asAtt = sourceElement.getAttributeValue("", "as");
559 if (asAtt == null) {
560 return null;
561 } else {
562 try {
563 declaredType = sourceElement.makeSequenceType(asAtt);
564 } catch (XPathException err) {
565 // the error will be reported when we get round to processing the function declaration
566 }
567 }
568
569 }
570 return declaredType;
571 }
572
573 /**
574 * Get the select expression actually appearing in the variable declaration
575 *
576 * @return the select expression as it appears, or null if it is absent
577 */
578
579 public Expression getSelectExpression() {
580 return select;
581 }
582
583 /**
584 * Get the best available static type of the variable.
585 *
586 * @param useContentRules set to true if the standard rules for xsl:variable and similar elements apply,
587 * whereby the element's contained sequence constructor substitutes for the select attribute
588 * @return the static type declared for the variable, or inferred from its initialization
589 */
590
591 public SequenceType getInferredType(boolean useContentRules) {
592 if (inferredType != null) {
593 return inferredType;
594 }
595 Visibility visibility = sourceElement.getVisibility();
596 if (hasProperty(PARAM) || hasProperty(ASSIGNABLE) ||
597 !(visibility == Visibility.PRIVATE || visibility == Visibility.FINAL)) {
598 SequenceType declared = getDeclaredType();
599 return inferredType = declared == null ? SequenceType.ANY_SEQUENCE : declared;
600 }
601 if (select != null) {
602 TypeHierarchy th = sourceElement.getConfiguration().getTypeHierarchy();
603 if (Literal.isEmptySequence(select)) {
604 // returning Type.EMPTY gives problems with static type checking
605 return inferredType = declaredType == null ? SequenceType.ANY_SEQUENCE : declaredType;
606 }
607 ItemType actual = select.getItemType();
608 int card = select.getCardinality();
609 if (declaredType != null) {
610 if (!th.isSubType(actual, declaredType.getPrimaryType())) {
611 actual = declaredType.getPrimaryType();
612 }
613 if (!Cardinality.subsumes(declaredType.getCardinality(), card)) {
614 card = declaredType.getCardinality();
615 }
616 }
617 inferredType = SequenceType.makeSequenceType(actual, card);
618 return inferredType;
619 }
620 if (useContentRules) {
621 if (sourceElement.hasChildNodes()) {
622 if (declaredType == null) {
623 return SequenceType.makeSequenceType(NodeKindTest.DOCUMENT, StaticProperty.EXACTLY_ONE);
624 } else {
625 return declaredType;
626 }
627 } else {
628 if (declaredType == null) {
629 // no select attribute or content: value is an empty string
630 return SequenceType.SINGLE_STRING;
631 } else {
632 return declaredType;
633 }
634 }
635 }
636 return declaredType;
637 }
638
639 /**
640 * Method called by VariableReference to register the variable reference for
641 * subsequent fixup
642 *
643 * @param ref the variable reference being registered
644 */
645
646 public void registerReference(BindingReference ref) {
647 references.add(ref);
648 }
649
650
651 public GroundedValue<?> getConstantValue() {
652 if (constantValue == null) {
653 final SequenceType type = getInferredType(true);
654 final TypeHierarchy th = sourceElement.getConfiguration().getTypeHierarchy();
655 if (!hasProperty(ASSIGNABLE) && !hasProperty(PARAM) && !(visibility == Visibility.PUBLIC || visibility == Visibility.ABSTRACT)) {
656 if (select instanceof Literal) {
657 // we can't rely on the constant value because it hasn't yet been type-checked,
658 // which could change it (eg by numeric promotion). Rather than attempt all the type-checking
659 // now, we do a quick check. See test bug64
660 int relation = th.relationship(select.getItemType(), type.getPrimaryType());
661 if (relation == TypeHierarchy.SAME_TYPE || relation == TypeHierarchy.SUBSUMED_BY) {
662 constantValue = ((Literal) select).getValue();
663 }
664 }
665 }
666 }
667 return constantValue;
668 }
669
670 /**
671 * Notify all references to this variable of the data type
672 *
673 * @param compiledGlobalVariable null if this is a local variable; otherwise, the compiled global variable
674 */
675
676 public void fixupReferences(GlobalVariable compiledGlobalVariable) {
677 final SequenceType type = getInferredType(true);
678 final TypeHierarchy th = sourceElement.getConfiguration().getTypeHierarchy();
679 GroundedValue constantValue = null;
680 int properties = 0;
681 if (!hasProperty(ASSIGNABLE) && !hasProperty(PARAM) && !(visibility == Visibility.PUBLIC || visibility == Visibility.ABSTRACT)) {
682 /*if (select instanceof Literal) {
683 // we can't rely on the constant value because it hasn't yet been type-checked,
684 // which could change it (eg by numeric promotion). Rather than attempt all the type-checking
685 // now, we do a quick check. See test bug64
686 int relation = th.relationship(select.getItemType(), type.getPrimaryType());
687 if (relation == TypeHierarchy.SAME_TYPE || relation == TypeHierarchy.SUBSUMED_BY) {
688 constantValue = ((Literal) select).getValue();
689 }
690 } */
691 if (select != null) {
692 properties = select.getSpecialProperties();
693 }
694 }
695 for (BindingReference reference : references) {
696 if (compiledGlobalVariable != null) {
697 reference.fixup(compiledGlobalVariable);
698 }
699 reference.setStaticType(type, getConstantValue(), properties);
700 }
701 }
702
703 /**
704 * Notify all variable references of the Binding instruction
705 *
706 * @param binding the Binding that represents this variable declaration in the executable code tree
707 */
708
709 protected void fixupBinding(Binding binding) {
710 for (BindingReference reference : references) {
711 reference.fixup(binding);
712 }
713 }
714
715 }
716