use of org.wso2.ballerinalang.compiler.tree.BLangFunction in project ballerina by ballerina-lang.
the class SymbolEnter method createInitFunction.
private BLangFunction createInitFunction(DiagnosticPos pos, String name, Name sufix) {
BLangFunction initFunction = (BLangFunction) TreeBuilder.createFunctionNode();
initFunction.setName(createIdentifier(name + sufix.getValue()));
initFunction.flagSet = EnumSet.of(Flag.PUBLIC);
initFunction.pos = pos;
// Create body of the init function
BLangBlockStmt body = (BLangBlockStmt) TreeBuilder.createBlockNode();
body.pos = pos;
initFunction.setBody(body);
return initFunction;
}
use of org.wso2.ballerinalang.compiler.tree.BLangFunction in project ballerina by ballerina-lang.
the class SymbolEnter method defineAttachedFunctions.
private void defineAttachedFunctions(BLangFunction funcNode, BInvokableSymbol funcSymbol, SymbolEnv invokableEnv, boolean isValidAttachedFunc) {
BInvokableType funcType = (BInvokableType) funcSymbol.type;
BTypeSymbol typeSymbol = funcNode.receiver.type.tsymbol;
// Check whether there exists a struct field with the same name as the function name.
if (isValidAttachedFunc) {
if (typeSymbol.tag == SymTag.STRUCT) {
validateFunctionsAttachedToStructs(funcNode, funcSymbol, invokableEnv);
} else if (typeSymbol.tag == SymTag.OBJECT) {
validateFunctionsAttachedToObject(funcNode, funcSymbol, invokableEnv);
}
}
defineNode(funcNode.receiver, invokableEnv);
funcSymbol.receiverSymbol = funcNode.receiver.symbol;
funcType.setReceiverType(funcNode.receiver.symbol.type);
}
use of org.wso2.ballerinalang.compiler.tree.BLangFunction in project ballerina by ballerina-lang.
the class SymbolEnter method validateFunctionsAttachedToObject.
private void validateFunctionsAttachedToObject(BLangFunction funcNode, BInvokableSymbol funcSymbol, SymbolEnv invokableEnv) {
BInvokableType funcType = (BInvokableType) funcSymbol.type;
BStructSymbol objectSymbol = (BStructSymbol) funcNode.receiver.type.tsymbol;
BSymbol symbol = symResolver.lookupMemberSymbol(funcNode.receiver.pos, objectSymbol.scope, invokableEnv, names.fromIdNode(funcNode.name), SymTag.VARIABLE);
if (symbol != symTable.notFoundSymbol) {
dlog.error(funcNode.pos, DiagnosticCode.STRUCT_FIELD_AND_FUNC_WITH_SAME_NAME, funcNode.name.value, funcNode.receiver.type.toString());
return;
}
BAttachedFunction attachedFunc = new BAttachedFunction(names.fromIdNode(funcNode.name), funcSymbol, funcType);
objectSymbol.attachedFuncs.add(attachedFunc);
// Check whether this attached function is a object initializer.
if (!Names.OBJECT_INIT_SUFFIX.value.equals(funcNode.name.value)) {
// Not a object initializer.
return;
}
if (!funcNode.retParams.isEmpty()) {
// TODO change message
dlog.error(funcNode.pos, DiagnosticCode.INVALID_STRUCT_INITIALIZER_FUNCTION, funcNode.name.value, funcNode.receiver.type.toString());
}
objectSymbol.initializerFunc = attachedFunc;
}
use of org.wso2.ballerinalang.compiler.tree.BLangFunction in project ballerina by ballerina-lang.
the class TaintAnalyzer method analyzeLambdaExpressions.
private void analyzeLambdaExpressions(BLangInvocation invocationExpr, BLangExpression argExpr) {
BLangFunction function = ((BLangLambdaFunction) argExpr).function;
if (function.symbol.taintTable == null) {
addToBlockedList(invocationExpr);
} else {
int requiredParamCount = function.requiredParams.size();
int defaultableParamCount = function.defaultableParams.size();
int totalParamCount = requiredParamCount + defaultableParamCount + (function.restParam == null ? 0 : 1);
Map<Integer, TaintRecord> taintTable = function.symbol.taintTable;
for (int paramIndex = 0; paramIndex < totalParamCount; paramIndex++) {
TaintRecord taintRecord = taintTable.get(paramIndex);
BLangVariable param = getParam(function, paramIndex, requiredParamCount, defaultableParamCount);
if (taintRecord == null) {
addTaintError(argExpr.pos, param.name.value, DiagnosticCode.TAINTED_VALUE_PASSED_TO_SENSITIVE_PARAMETER);
} else if (taintRecord.taintError != null && taintRecord.taintError.size() > 0) {
addTaintError(taintRecord.taintError);
}
if (stopAnalysis) {
break;
}
}
}
}
use of org.wso2.ballerinalang.compiler.tree.BLangFunction in project ballerina by ballerina-lang.
the class TaintAnalyzer method isEntryPoint.
// Private methods related to invokable node analysis and taint-table generation.
private boolean isEntryPoint(BLangFunction funcNode) {
// Service resources are handled through BLangResource visitor.
boolean isMainFunction = false;
if (funcNode.name.value.equals(MAIN_FUNCTION_NAME) && funcNode.symbol.params.size() == 1 && funcNode.symbol.retParams.size() == 0) {
BType paramType = funcNode.symbol.params.get(0).type;
BArrayType arrayType = (BArrayType) paramType;
if (paramType.tag == TypeTags.ARRAY && arrayType.eType.tag == TypeTags.STRING) {
isMainFunction = true;
}
}
return isMainFunction;
}
Aggregations