src/jdk/nashorn/internal/codegen/CodeGenerator.java

Print this page




4725             if (CompilerConstants.__FILE__.name().equals(name)) {
4726                 replaceCompileTimeProperty(getCurrentSource().getName());
4727             } else if (CompilerConstants.__DIR__.name().equals(name)) {
4728                 replaceCompileTimeProperty(getCurrentSource().getBase());
4729             } else if (CompilerConstants.__LINE__.name().equals(name)) {
4730                 replaceCompileTimeProperty(getCurrentSource().getLine(identNode.position()));
4731             }
4732         }
4733 
4734         /**
4735          * When an ident with name __FILE__, __DIR__, or __LINE__ is loaded, we'll try to look it up as any other
4736          * identifier. However, if it gets all the way up to the Global object, it will send back a special value that
4737          * represents a placeholder for these compile-time location properties. This method will generate code that loads
4738          * the value of the compile-time location property and then invokes a method in Global that will replace the
4739          * placeholder with the value. Effectively, if the symbol for these properties is defined anywhere in the lexical
4740          * scope, they take precedence, but if they aren't, then they resolve to the compile-time location property.
4741          * @param propertyValue the actual value of the property
4742          */
4743         private void replaceCompileTimeProperty(final Object propertyValue) {
4744             assert method.peekType().isObject();
4745             if(propertyValue instanceof String) {
4746                 method.load((String)propertyValue);
4747             } else if(propertyValue instanceof Integer) {
4748                 method.load(((Integer)propertyValue).intValue());
4749                 method.convert(Type.OBJECT);
4750             } else {
4751                 throw new AssertionError();
4752             }
4753             globalReplaceLocationPropertyPlaceholder();
4754             convertOptimisticReturnValue();
4755         }
4756 
4757         /**
4758          * Returns the type that should be used as the return type of the dynamic invocation that is emitted as the code
4759          * for the current optimistic operation. If the type bounds is exact boolean or narrower than the expression's
4760          * optimistic type, then the optimistic type is returned, otherwise the coercing type. Effectively, this method
4761          * allows for moving the coercion into the optimistic type when it won't adversely affect the optimistic
4762          * evaluation semantics, and for preserving the optimistic type and doing a separate coercion when it would
4763          * affect it.
4764          * @return
4765          */




4725             if (CompilerConstants.__FILE__.name().equals(name)) {
4726                 replaceCompileTimeProperty(getCurrentSource().getName());
4727             } else if (CompilerConstants.__DIR__.name().equals(name)) {
4728                 replaceCompileTimeProperty(getCurrentSource().getBase());
4729             } else if (CompilerConstants.__LINE__.name().equals(name)) {
4730                 replaceCompileTimeProperty(getCurrentSource().getLine(identNode.position()));
4731             }
4732         }
4733 
4734         /**
4735          * When an ident with name __FILE__, __DIR__, or __LINE__ is loaded, we'll try to look it up as any other
4736          * identifier. However, if it gets all the way up to the Global object, it will send back a special value that
4737          * represents a placeholder for these compile-time location properties. This method will generate code that loads
4738          * the value of the compile-time location property and then invokes a method in Global that will replace the
4739          * placeholder with the value. Effectively, if the symbol for these properties is defined anywhere in the lexical
4740          * scope, they take precedence, but if they aren't, then they resolve to the compile-time location property.
4741          * @param propertyValue the actual value of the property
4742          */
4743         private void replaceCompileTimeProperty(final Object propertyValue) {
4744             assert method.peekType().isObject();
4745             if(propertyValue instanceof String || propertyValue == null) {
4746                 method.load((String)propertyValue);
4747             } else if(propertyValue instanceof Integer) {
4748                 method.load(((Integer)propertyValue).intValue());
4749                 method.convert(Type.OBJECT);
4750             } else {
4751                 throw new AssertionError();
4752             }
4753             globalReplaceLocationPropertyPlaceholder();
4754             convertOptimisticReturnValue();
4755         }
4756 
4757         /**
4758          * Returns the type that should be used as the return type of the dynamic invocation that is emitted as the code
4759          * for the current optimistic operation. If the type bounds is exact boolean or narrower than the expression's
4760          * optimistic type, then the optimistic type is returned, otherwise the coercing type. Effectively, this method
4761          * allows for moving the coercion into the optimistic type when it won't adversely affect the optimistic
4762          * evaluation semantics, and for preserving the optimistic type and doing a separate coercion when it would
4763          * affect it.
4764          * @return
4765          */