public boolean isBlockInvocation() { return _symbol.getType() instanceof IBlockType; }
private IRExpression callGlobalStaticFunction(IFunctionSymbol symbol) { if( symbol.getDisplayName().equals( StandardSymbolTable.PRINT.getName() ) ) { IRMethod method = IRMethodFactory.createIRMethod( GosuRuntimeMethods.class, "print", Object.class ); return callMethod( method, null, pushArguments( method ) ); } else { throw new UnsupportedOperationException(symbol.getDisplayName()); } }
private boolean isPrintFunction(IFunctionSymbol function) { return function.getName().equals("print"); }
protected IRExpression compile_impl() { IFunctionSymbol symbol = _expr().getFunctionSymbol(); if( symbol instanceof ILockedDownSymbol ) { // 'Global' static function call e.g., print() return callGlobalStaticFunction( symbol ); } else if( _cc().isExternalSymbol( symbol.getName() ) ) { return callExternalProgramSymbol(symbol); } else if( symbol instanceof DynamicFunctionSymbol ) { return callDynamicFunctionSymbol(symbol); } else if( symbol.getType() instanceof IPlaceholder && ((IPlaceholder)symbol.getType()).isPlaceholder() ) { return callBlockViaDynamicType( symbol ); } else { throw new UnsupportedOperationException( "Don't know how to compile symbol: " + symbol.getType() ); } }
if( function == null || !(function.getType() instanceof IFunctionType) ) verifyCase( e, strFunction, function.getDisplayName(), state, Res.MSG_FUNCTION_CASE_MISMATCH, false ); IFunctionType funcType = (IFunctionType)function.getType(); if( typeParameters != null ) e.getFunctionSymbol().isAbstract() ) e.addParseException( new ParseException( state, Res.MSG_NO_ABSTRACT_METHOD_CALL_IN_CONSTR, e.getFunctionSymbol().getDisplayName() ) );
private IRExpression callBlockViaDynamicType( IFunctionSymbol symbol ) { if( !(symbol.getType() instanceof IPlaceholder) ) { throw new IllegalArgumentException( "Expecting symbol to have dynamic type" ); } // Generates: ((IBlock)symbolValue).invokeWithArgs( args ) Identifier identifier = new Identifier(); identifier.setSymbol( symbol, symbol.getDynamicSymbolTable() ); IRExpression idExpr = IdentifierTransformer.compile( _cc(), identifier ); idExpr = buildCast( JavaClassIRType.get( IBlock.class ), idExpr ); List<IRExpression> irArgs = new ArrayList<IRExpression>(); pushArgumentsNoCasting( null, _expr().getArgs(), irArgs ); IRExpression objArray = collectArgsIntoObjArray( irArgs ); return callMethod( IBlock.class, "invokeWithArgs", new Class[]{Object[].class}, idExpr, Collections.singletonList( objArray ) ); }
@Override public Object invoke(String name, Object[] args) { IFunctionSymbol functionSymbol = (IFunctionSymbol) getSymbol(name); // Any external symbols that are functions are coming from the code block, so they implicitly take // an IExternalSymbolMap as their first argument if (shouldAddInExternalSymbolMapArgumentForFunctionSymbol(functionSymbol)) { // Swap the external symbols map into the first position if (args == null) { args = new Object[]{this}; } else { Object[] originalArgs = args; args = new Object[originalArgs.length + 1]; args[0] = this; System.arraycopy(originalArgs, 0, args, 1, originalArgs.length); } } return functionSymbol.invoke(args); }
private IRExpression callGlobalStaticFunction( IFunctionSymbol symbol ) { IRSymbol currentTemplate = TemplateStringLiteralTransformer.getCurrentTemplateSymbol(); if( currentTemplate != null && symbol == TemplateGenerator.PRINT_CONTENT_SYMBOL.get() ) { // Special case printContent() implementation for StringLiteral template // where we optimize by appending to the StringBuilder for the string. return callMethod( StringBuilder.class, "append", new Class[]{Object.class}, identifier( currentTemplate ), exprList( ExpressionTransformer.compile( _expr().getArgs()[0], _cc() ) ) ); } else { // Call the Method value of the Symbol directly IRMethod method = IRMethodFactory.createIRMethod( (java.lang.reflect.Method)symbol.getValue() ); return callMethod( method, null, pushArguments( method ) ); } }
protected IRExpression compile_impl() { IFunctionSymbol symbol = _expr().getFunctionSymbol(); if( _cc().isExternalSymbol( symbol.getName() ) ) { return callExternalProgramSymbol(symbol); } else if( symbol instanceof DynamicFunctionSymbol ) { return callDynamicFunctionSymbol(symbol); } else if( symbol instanceof CommonSymbolsScope.LockedDownSymbol ) { // 'Global' static function call e.g., print() return callGlobalStaticFunction(symbol); } else if( symbol == TemplateGenerator.PRINT_CONTENT_SYMBOL.get() ) { return callPrintContent(); } else if( symbol.getType() instanceof IPlaceholder && ((IPlaceholder)symbol.getType()).isPlaceholder() ) { return callBlockViaDynamicType( symbol ); } else { throw new UnsupportedOperationException( "Don't know how to compile symbol: " + symbol.getType() ); } }
if( function == null || !(function.getType() instanceof IFunctionType)) if( function == null || !(function.getType() instanceof IFunctionType) ) verifyCase( e, strFunction, function.getDisplayName(), state, Res.MSG_FUNCTION_CASE_MISMATCH, false ); IFunctionType funcType = (IFunctionType)function.getType(); if( typeParameters != null ) e.getFunctionSymbol().isAbstract() ) e.addParseException( new ParseException( state, Res.MSG_NO_ABSTRACT_METHOD_CALL_IN_CONSTR, e.getFunctionSymbol().getDisplayName() ) );
private IRExpression callBlockViaDynamicType( IFunctionSymbol symbol ) { if( !(symbol.getType() instanceof IPlaceholder) ) { throw new IllegalArgumentException( "Expecting symbol to have dynamic type" ); } // Generates: ((IBlock)symbolValue).invokeWithArgs( args ) Identifier identifier = new Identifier(); identifier.setSymbol( symbol, symbol.getDynamicSymbolTable() ); IRExpression idExpr = IdentifierTransformer.compile( _cc(), identifier ); idExpr = buildCast( JavaClassIRType.get( IBlock.class ), idExpr ); List<IRExpression> irArgs = new ArrayList<IRExpression>(); pushArgumentsNoCasting( null, _expr().getArgs(), irArgs ); IRExpression objArray = collectArgsIntoObjArray( irArgs ); return callMethod( IBlock.class, "invokeWithArgs", new Class[]{Object[].class}, idExpr, Collections.singletonList( objArray ) ); }
@Override public Object invoke(String name, Object[] args) { IFunctionSymbol functionSymbol = (IFunctionSymbol) getSymbol(name); // Any external symbols that are functions are coming from the code block, so they implicitly take // an IExternalSymbolMap as their first argument if (shouldAddInExternalSymbolMapArgumentForFunctionSymbol(functionSymbol)) { // Swap the external symbols map into the first position if (args == null) { args = new Object[]{this}; } else { Object[] originalArgs = args; args = new Object[originalArgs.length + 1]; args[0] = this; System.arraycopy(originalArgs, 0, args, 1, originalArgs.length); } } return functionSymbol.invoke(args); }
private boolean isBlock(IFunctionSymbol function) { return function.getType() instanceof IBlockType; }
private void parsePlainFunction( IFunctionSymbol functionSymbol ) { MethodCallExpression e = new MethodCallExpression(); e.setFunctionSymbol( functionSymbol ); IFunctionType funcType = (IFunctionType)functionSymbol.getType(); e.setType( funcType.getReturnType() ); IType[] argTypes = funcType.getParameterTypes(); boolean bNoArgsProvided; if( !(bNoArgsProvided = match( null, ')' )) || funcType.hasOptionalParams() ) { verify( e, argTypes != null && argTypes.length > 0, Res.MSG_NO_ARGUMENTS, functionSymbol.getName() ); MethodScore score = parseArgumentList( getGosuClass(), e, Collections.singletonList( funcType ), null, true, bNoArgsProvided ); if( score.isValid() ) { List<IExpression> scoreArgs = score.getArguments(); verifyArgCount( e, scoreArgs.size(), funcType ); //noinspection SuspiciousToArrayCall e.setArgs( scoreArgs.toArray( new Expression[scoreArgs.size()] ) ); e.setNamedArgOrder( score.getNamedArgOrder() ); } verify( e, bNoArgsProvided || match( null, ')' ), Res.MSG_EXPECTING_FUNCTION_CLOSE ); } else { verify( e, argTypes == null || argTypes.length == 0, Res.MSG_EXPECTING_ARGS, functionSymbol.getName() ); e.setArgs( null ); } pushExpression( e ); }
@Override public String toString() { String strOut = (_symbol == null ? "#err" : _symbol.getDisplayName()) + "("; if( _args != null && _args.length > 0 ) { strOut += " "; for( int i = 0; i < _args.length; i++ ) { if( i != 0 ) { strOut += ", "; } strOut += _args[i].toString(); } strOut += " "; } return strOut += ")"; }
private boolean isPrintFunction(IFunctionSymbol function) { return function.getName().equals("print"); }
public boolean isBlockInvocation() { return _symbol.getType() instanceof IBlockType; }
private void parsePlainFunction( IFunctionSymbol functionSymbol ) { MethodCallExpression e = new MethodCallExpression(); e.setFunctionSymbol( functionSymbol ); IFunctionType funcType = (IFunctionType)functionSymbol.getType(); e.setType( funcType.getReturnType() ); IType[] argTypes = funcType.getParameterTypes(); boolean bNoArgsProvided; if( !(bNoArgsProvided = match( null, ')' )) || funcType.hasOptionalParams() ) { verify( e, argTypes != null && argTypes.length > 0, Res.MSG_NO_ARGUMENTS, functionSymbol.getName() ); MethodScore score = parseArgumentList( e, Collections.singletonList( funcType ), null, true, bNoArgsProvided, null); if( score.isValid() ) { List<IExpression> scoreArgs = score.getArguments(); verifyArgCount( e, scoreArgs.size(), funcType ); //noinspection SuspiciousToArrayCall e.setArgs( scoreArgs.toArray( new Expression[scoreArgs.size()] ) ); e.setNamedArgOrder( score.getNamedArgOrder() ); } verify( e, bNoArgsProvided || match( null, ')' ), Res.MSG_EXPECTING_FUNCTION_CLOSE ); } else { verify( e, argTypes == null || argTypes.length == 0, Res.MSG_EXPECTING_ARGS, functionSymbol.getName() ); e.setArgs( null ); } pushExpression( e ); }
@Override public String toString() { String strOut = (_symbol == null ? "#err" : _symbol.getDisplayName()) + "("; if( _args != null && _args.length > 0 ) { strOut += " "; for( int i = 0; i < _args.length; i++ ) { if( i != 0 ) { strOut += ", "; } strOut += _args[i].toString(); } strOut += " "; } return strOut += ")"; }
for (IFunctionSymbol sym : symbolSet) { if (!(sym instanceof CommonSymbolsScope.LockedDownSymbol) && sym != null) { symbolNames.put( sym.getName(), sym);