Package gnu.expr
Class InlineCalls
- java.lang.Object
-
- gnu.expr.ExpVisitor<Expression,D>
-
- gnu.expr.ExpExpVisitor<Type>
-
- gnu.expr.InlineCalls
-
- All Implemented Interfaces:
SourceLocator,SourceLocator,Locator
public class InlineCalls extends ExpExpVisitor<Type>
The main Expression re-writing pass. This pass handles type-checking (work in progress). Also checks for calls to known Procedures, and may call a procedure-specific handler, which may do inlining, constant-folding, error-checking, and general munging. Should perhaps rename to something like "Validate" since we do type-checking and other stuff beyond inlining.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classInlineCalls.LenientExpectedTypeNew helper Type class, used for "lenient" conversions.static classInlineCalls.ProcedureInCallContextstatic classInlineCalls.ValueNeededTypeA marker type to indicate that void is invalid.-
Nested classes/interfaces inherited from interface gnu.text.SourceLocator
SourceLocator.Simple
-
-
Field Summary
Fields Modifier and Type Field Description static ThreadLocal<InlineCalls>currentVisitor-
Fields inherited from class gnu.expr.ExpVisitor
currentLambda, exitValue, messages
-
-
Constructor Summary
Constructors Constructor Description InlineCalls(Compilation comp)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static IntegercheckIntValue(Expression exp)static LongcheckLongValue(Expression exp)ExpressioncheckType(Expression exp, Type required)protected booleandeferableInit(Expression init)QuoteExpfixIntValue(Expression exp)QuoteExpfixLongValue(Expression exp)static ExpressioninlineCall(LambdaExp lexp, ApplyExp aexp, boolean makeCopy)Attempt to inline a function call.static ExpressioninlineCalls(Expression exp, Compilation comp)static intisCompatibleWithValue(Type required, Type expType)ExpressionmaybeInline(ApplyExp exp, Type required, Procedure proc)booleanprocessingAnnotations()If currently processing an annotation belonging to a declaration.static TypetypeForCalledFunction(Expression exp)Return a required type for procedure application context.Expressionvisit(Expression exp, Type required)Call the visit method of argument Expression.protected voidvisitAnnotations(Declaration decl)protected ExpressionvisitApplyExp(ApplyExp exp, Type required)ExpressionvisitApplyOnly(ApplyExp exp, Type required)Visit an ApplyExp assuming function and arguments have been visited.protected ExpressionvisitBeginExp(BeginExp exp, Type required)protected ExpressionvisitCaseExp(CaseExp exp, Type required)protected ExpressionvisitClassExp(ClassExp exp, Type required)voidvisitDefaultArgs(LambdaExp exp, Type required)protected ExpressionvisitFluidLetExp(FluidLetExp exp, Type required)protected ExpressionvisitIfExp(IfExp exp, Type required)protected ExpressionvisitLambdaExp(LambdaExp exp, Type required)protected ExpressionvisitLetExp(LetExp exp, Type required)protected ExpressionvisitModuleExp(ModuleExp exp, Type required)protected ExpressionvisitQuoteExp(QuoteExp exp, Type required)protected ExpressionvisitReferenceExp(ReferenceExp exp, Type required)protected voidvisitRemainingDeclaredLambdas(ScopeExp exp)Visit any named functions that haven't been visit yet.protected ExpressionvisitScopeExp(ScopeExp exp, Type required)protected ExpressionvisitSetExp(SetExp exp, Type required)protected ExpressionvisitTryExp(TryExp exp, Type required)-
Methods inherited from class gnu.expr.ExpExpVisitor
defaultValue, error, error, update
-
Methods inherited from class gnu.expr.ExpVisitor
error, getColumnNumber, getCompilation, getCurrentLambda, getEndColumn, getEndLine, getExitValue, getFileName, getLanguage, getLineNumber, getMessages, getPublicId, getStartColumn, getStartLine, getSystemId, isStableSourceLocation, noteError, setColumn, setContext, setFile, setLine, setLine, visit, visitAndUpdate, visitBlockExp, visitDeclarationType, visitDeclarationTypes, visitExitExp, visitExpression, visitExps, visitExps, visitLangExp, visitObjectExp, visitSynchronizedExp, visitThisExp
-
-
-
-
Field Detail
-
currentVisitor
public static ThreadLocal<InlineCalls> currentVisitor
-
-
Constructor Detail
-
InlineCalls
public InlineCalls(Compilation comp)
-
-
Method Detail
-
inlineCalls
public static Expression inlineCalls(Expression exp, Compilation comp)
-
visit
public Expression visit(Expression exp, Type required)
Description copied from class:ExpVisitorCall the visit method of argument Expression. Could call Expression's visit directly, but this allows us to interpose a method call on each Expression. We use it to note the Expression's line number. Should not need to be overridden; if you do, you may also want to override visitExps.- Overrides:
visitin classExpVisitor<Expression,Type>
-
checkType
public Expression checkType(Expression exp, Type required)
-
visitApplyExp
protected Expression visitApplyExp(ApplyExp exp, Type required)
- Overrides:
visitApplyExpin classExpVisitor<Expression,Type>
-
typeForCalledFunction
public static Type typeForCalledFunction(Expression exp)
Return a required type for procedure application context. This is ProcedureInCallContext.INSTANCE or null. The value ProcedureInCallContext.INSTANCE indicates the expression is used in application context and setCanCall is appropriate. This means the function expression must be a lambda or reference. (Consider a function that is an IfExp: If the required type is passed down to two branches that are both lambdas, we might think the lambdas are called but not read and thus safe for inlining - but that would be false, since we need the If to yield a procedure value.)
-
visitApplyOnly
public final Expression visitApplyOnly(ApplyExp exp, Type required)
Visit an ApplyExp assuming function and arguments have been visited.
-
checkIntValue
public static Integer checkIntValue(Expression exp)
-
checkLongValue
public static Long checkLongValue(Expression exp)
-
fixIntValue
public QuoteExp fixIntValue(Expression exp)
-
fixLongValue
public QuoteExp fixLongValue(Expression exp)
-
visitQuoteExp
protected Expression visitQuoteExp(QuoteExp exp, Type required)
- Overrides:
visitQuoteExpin classExpVisitor<Expression,Type>
-
visitReferenceExp
protected Expression visitReferenceExp(ReferenceExp exp, Type required)
- Overrides:
visitReferenceExpin classExpVisitor<Expression,Type>
-
visitIfExp
protected Expression visitIfExp(IfExp exp, Type required)
- Overrides:
visitIfExpin classExpVisitor<Expression,Type>
-
visitBeginExp
protected Expression visitBeginExp(BeginExp exp, Type required)
- Overrides:
visitBeginExpin classExpVisitor<Expression,Type>
-
visitCaseExp
protected Expression visitCaseExp(CaseExp exp, Type required)
- Overrides:
visitCaseExpin classExpVisitor<Expression,Type>
-
visitScopeExp
protected Expression visitScopeExp(ScopeExp exp, Type required)
- Overrides:
visitScopeExpin classExpVisitor<Expression,Type>
-
visitRemainingDeclaredLambdas
protected void visitRemainingDeclaredLambdas(ScopeExp exp)
Visit any named functions that haven't been visit yet. This should be called at the end of a LetExp or ModuleExp.
-
visitModuleExp
protected Expression visitModuleExp(ModuleExp exp, Type required)
- Overrides:
visitModuleExpin classExpVisitor<Expression,Type>
-
visitLetExp
protected Expression visitLetExp(LetExp exp, Type required)
- Overrides:
visitLetExpin classExpVisitor<Expression,Type>
-
deferableInit
protected boolean deferableInit(Expression init)
-
visitFluidLetExp
protected Expression visitFluidLetExp(FluidLetExp exp, Type required)
- Overrides:
visitFluidLetExpin classExpVisitor<Expression,Type>
-
visitLambdaExp
protected Expression visitLambdaExp(LambdaExp exp, Type required)
- Overrides:
visitLambdaExpin classExpVisitor<Expression,Type>
-
visitDefaultArgs
public void visitDefaultArgs(LambdaExp exp, Type required)
- Overrides:
visitDefaultArgsin classExpVisitor<Expression,Type>
-
visitClassExp
protected Expression visitClassExp(ClassExp exp, Type required)
- Overrides:
visitClassExpin classExpVisitor<Expression,Type>
-
visitTryExp
protected Expression visitTryExp(TryExp exp, Type required)
- Overrides:
visitTryExpin classExpVisitor<Expression,Type>
-
processingAnnotations
public boolean processingAnnotations()
If currently processing an annotation belonging to a declaration. In this case expressions must resolve to constants, annotations must resolve to know annotation types.
-
visitAnnotations
protected void visitAnnotations(Declaration decl)
-
visitSetExp
protected Expression visitSetExp(SetExp exp, Type required)
- Overrides:
visitSetExpin classExpVisitor<Expression,Type>
-
maybeInline
public Expression maybeInline(ApplyExp exp, Type required, Procedure proc)
-
inlineCall
public static Expression inlineCall(LambdaExp lexp, ApplyExp aexp, boolean makeCopy)
Attempt to inline a function call.- Parameters:
lexp- function to inlinemakeCopy- true if the body of lexp should of copied; false if we can re-use lexp because it is no longer needed.- Returns:
- the inlined expression (a LetExp), or null if we weren't able to inline.
-
-