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 class
InlineCalls.LenientExpectedType
New helper Type class, used for "lenient" conversions.static class
InlineCalls.ProcedureInCallContext
static class
InlineCalls.ValueNeededType
A 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 Integer
checkIntValue(Expression exp)
static Long
checkLongValue(Expression exp)
Expression
checkType(Expression exp, Type required)
protected boolean
deferableInit(Expression init)
QuoteExp
fixIntValue(Expression exp)
QuoteExp
fixLongValue(Expression exp)
static Expression
inlineCall(LambdaExp lexp, ApplyExp aexp, boolean makeCopy)
Attempt to inline a function call.static Expression
inlineCalls(Expression exp, Compilation comp)
static int
isCompatibleWithValue(Type required, Type expType)
Expression
maybeInline(ApplyExp exp, Type required, Procedure proc)
boolean
processingAnnotations()
If currently processing an annotation belonging to a declaration.static Type
typeForCalledFunction(Expression exp)
Return a required type for procedure application context.Expression
visit(Expression exp, Type required)
Call the visit method of argument Expression.protected void
visitAnnotations(Declaration decl)
protected Expression
visitApplyExp(ApplyExp exp, Type required)
Expression
visitApplyOnly(ApplyExp exp, Type required)
Visit an ApplyExp assuming function and arguments have been visited.protected Expression
visitBeginExp(BeginExp exp, Type required)
protected Expression
visitCaseExp(CaseExp exp, Type required)
protected Expression
visitClassExp(ClassExp exp, Type required)
void
visitDefaultArgs(LambdaExp exp, Type required)
protected Expression
visitFluidLetExp(FluidLetExp exp, Type required)
protected Expression
visitIfExp(IfExp exp, Type required)
protected Expression
visitLambdaExp(LambdaExp exp, Type required)
protected Expression
visitLetExp(LetExp exp, Type required)
protected Expression
visitModuleExp(ModuleExp exp, Type required)
protected Expression
visitQuoteExp(QuoteExp exp, Type required)
protected Expression
visitReferenceExp(ReferenceExp exp, Type required)
protected void
visitRemainingDeclaredLambdas(ScopeExp exp)
Visit any named functions that haven't been visit yet.protected Expression
visitScopeExp(ScopeExp exp, Type required)
protected Expression
visitSetExp(SetExp exp, Type required)
protected Expression
visitTryExp(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:ExpVisitor
Call 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:
visit
in classExpVisitor<Expression,Type>
-
checkType
public Expression checkType(Expression exp, Type required)
-
visitApplyExp
protected Expression visitApplyExp(ApplyExp exp, Type required)
- Overrides:
visitApplyExp
in 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:
visitQuoteExp
in classExpVisitor<Expression,Type>
-
visitReferenceExp
protected Expression visitReferenceExp(ReferenceExp exp, Type required)
- Overrides:
visitReferenceExp
in classExpVisitor<Expression,Type>
-
visitIfExp
protected Expression visitIfExp(IfExp exp, Type required)
- Overrides:
visitIfExp
in classExpVisitor<Expression,Type>
-
visitBeginExp
protected Expression visitBeginExp(BeginExp exp, Type required)
- Overrides:
visitBeginExp
in classExpVisitor<Expression,Type>
-
visitCaseExp
protected Expression visitCaseExp(CaseExp exp, Type required)
- Overrides:
visitCaseExp
in classExpVisitor<Expression,Type>
-
visitScopeExp
protected Expression visitScopeExp(ScopeExp exp, Type required)
- Overrides:
visitScopeExp
in 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:
visitModuleExp
in classExpVisitor<Expression,Type>
-
visitLetExp
protected Expression visitLetExp(LetExp exp, Type required)
- Overrides:
visitLetExp
in classExpVisitor<Expression,Type>
-
deferableInit
protected boolean deferableInit(Expression init)
-
visitFluidLetExp
protected Expression visitFluidLetExp(FluidLetExp exp, Type required)
- Overrides:
visitFluidLetExp
in classExpVisitor<Expression,Type>
-
visitLambdaExp
protected Expression visitLambdaExp(LambdaExp exp, Type required)
- Overrides:
visitLambdaExp
in classExpVisitor<Expression,Type>
-
visitDefaultArgs
public void visitDefaultArgs(LambdaExp exp, Type required)
- Overrides:
visitDefaultArgs
in classExpVisitor<Expression,Type>
-
visitClassExp
protected Expression visitClassExp(ClassExp exp, Type required)
- Overrides:
visitClassExp
in classExpVisitor<Expression,Type>
-
visitTryExp
protected Expression visitTryExp(TryExp exp, Type required)
- Overrides:
visitTryExp
in 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:
visitSetExp
in 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.
-
-