Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Table implementation #22874

Merged
merged 175 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
175 commits
Select commit Hold shift + click to select a range
34ff65f
Add initial table type compiler side implementation
mohanvive Apr 8, 2020
c2bfcb1
Merge pull request #22510 from mohanvive/new-table-impl
gimantha Apr 8, 2020
51a311e
Add initial version of runtime classes related to tables
gimantha Apr 8, 2020
e93450a
Add table constructor initial implementation
mohanvive Apr 8, 2020
860ae06
Merge pull request #22526 from mohanvive/new-table-impl
gimantha Apr 9, 2020
d6433b3
Add table type to JVMGen
gimantha Apr 9, 2020
5458ddf
Merge branch 'new-table-impl' of https://github.com/ballerina-platfor…
gimantha Apr 9, 2020
68cbc2b
Add constructorExpr logic to runtime
gimantha Apr 9, 2020
b19886d
Add a simple test
gimantha Apr 9, 2020
0c46fd8
Make key-constraint as optional
mohanvive Apr 9, 2020
a3923b6
Merge pull request #22552 from mohanvive/new-table-impl
gimantha Apr 9, 2020
d454aed
Fix NPE when key specifier is not available
gimantha Apr 10, 2020
dde124f
Add typechecker improvements and negative test cases
mohanvive Apr 10, 2020
bb707c4
Add improvements related to table access expression
mohanvive Apr 14, 2020
ba0556c
Merge pull request #22623 from mohanvive/new-table-impl
mohanvive Apr 15, 2020
9ee4c00
Add additional type checker compile time validations
mohanvive Apr 15, 2020
0a9fe80
Merge branch 'new-table-impl' of https://github.com/ballerina-platfor…
mohanvive Apr 15, 2020
560eaf6
Fix Key hashing issue in TableValue
gimantha Apr 15, 2020
3d5581f
Add multikey member access support for tables
mohanvive Apr 15, 2020
3d09324
Fix testcase failures
mohanvive Apr 15, 2020
06c13fc
Fix testcase failures
mohanvive Apr 15, 2020
4674583
Merge branch 'master' of https://github.com/ballerina-platform/baller…
mohanvive Apr 15, 2020
5f860c3
Disable SQL testcase which depends on JDBC module
mohanvive Apr 15, 2020
2aadec3
Revert temp fix provided by maryam
mohanvive Apr 15, 2020
629c2c0
Revert temp fix provided by maryam
mohanvive Apr 15, 2020
19fabee
Disable SQL testcase which depends on JDBC module
mohanvive Apr 15, 2020
baff600
Merge pull request #22653 from mohanvive/new-table-impl
mohanvive Apr 15, 2020
e69efa4
Merge branch 'new-table-impl' of https://github.com/ballerina-platfor…
mohanvive Apr 16, 2020
e4f53fb
Merge branch 'master' of https://github.com/ballerina-platform/baller…
mohanvive Apr 16, 2020
4304239
Fix the checktyle and javadoc issues
mohanvive Apr 16, 2020
4867b55
Merge pull request #22659 from mohanvive/new-table-impl
mohanvive Apr 16, 2020
9063cd1
Merge branch 'new-table-impl' of https://github.com/ballerina-platfor…
mohanvive Apr 16, 2020
ef2b704
Fix conflicts
gimantha Apr 16, 2020
4d9a19b
Fix checkstyle issues
gimantha Apr 16, 2020
2564dac
Return 0 for null values for hashcodes
gimantha Apr 16, 2020
4cf4676
Merge pull request #22645 from gimantha/new-table-impl
mohanvive Apr 16, 2020
a12477b
Merge pull request #22652 from mohanvive/new-table-build-fix
mohanvive Apr 16, 2020
ebc97da
Add negative testcase for invalid constraint type
mohanvive Apr 16, 2020
62dcddb
Merge branch 'new-table-impl' of https://github.com/ballerina-platfor…
mohanvive Apr 16, 2020
8792040
Merge branch 'master' of https://github.com/ballerina-platform/baller…
mohanvive Apr 16, 2020
401bb4c
Add initial impl of table store and table load
gimantha Apr 16, 2020
3e1f8be
Merge branch 'new-table-impl' of https://github.com/ballerina-platfor…
gimantha Apr 16, 2020
79ff4df
Revert "Fix Key hashing issue in TableValue"
mohanvive Apr 16, 2020
36c008f
Merge pull request #22685 from ballerina-platform/revert-22645-new-ta…
mohanvive Apr 16, 2020
dbbf01f
Merge pull request #22677 from mohanvive/new-table-impl
mohanvive Apr 16, 2020
bfadc71
Fix hashing issue
gimantha Apr 17, 2020
4853802
Fix documentation issues
gimantha Apr 17, 2020
6937981
Resolve conflicts
gimantha Apr 17, 2020
f3a9c95
Add positive and negative testcases for table type
mohanvive Apr 17, 2020
9e5170a
Remove unused diagnostic codes
mohanvive Apr 17, 2020
19edce5
Merge branch 'new-table-impl' of https://github.com/ballerina-platfor…
mohanvive Apr 17, 2020
cd8a69c
Merge pull request #22735 from mohanvive/new-table-impl
mohanvive Apr 17, 2020
ceda680
Improve BTableValue test cases
mohanvive Apr 17, 2020
c579aa1
Merge pull request #22736 from mohanvive/new-table-impl
mohanvive Apr 17, 2020
80cdfb6
Fix tests
gimantha Apr 17, 2020
6cc2feb
Resolve conflicts
gimantha Apr 17, 2020
b127cba
Add initial langlib table function impl
pcnfernando Apr 10, 2020
a5104d6
Add intial lang lib table bal resources
pcnfernando Apr 10, 2020
401148d
Introduce table forEach and Map functions
pcnfernando Apr 16, 2020
7c9856f
Add getkeys, haskey, reducem remove, removeall and toarray functions
pcnfernando Apr 17, 2020
ffb6c83
Enable travis for new-table-impl branch temporally
mohanvive Apr 17, 2020
ac7d4f9
Fix checkstyle issue found
mohanvive Apr 17, 2020
8abc879
Fix the language server test cases
mohanvive Apr 18, 2020
2571a6f
Reformat language server json files
mohanvive Apr 18, 2020
2425c78
Merge pull request #22739 from gimantha/new-table-impl
mohanvive Apr 18, 2020
46cd9ec
Improve type checker validation logic
mohanvive Apr 18, 2020
ccf509d
Improve lang lib table tests
pcnfernando Apr 18, 2020
71441f9
Fix checkstyle errors
pcnfernando Apr 19, 2020
efb3e8a
Remove unused methods
pcnfernando Apr 19, 2020
fbdf12b
Revert formatting changes on untouched code
pcnfernando Apr 19, 2020
6a6fd46
Add comments to langlib table functions
pcnfernando Apr 19, 2020
bb7944f
Merge branch 'new-table-impl' of git://github.com/pcnfernando/balleri…
gimantha Apr 20, 2020
7d36c3e
Merge with langlib changes
gimantha Apr 20, 2020
1e719cb
Merge branch 'master' of https://github.com/ballerina-platform/baller…
mohanvive Apr 20, 2020
005a1f7
Fix lang server tests
gimantha Apr 20, 2020
cd9ae5f
Merge pull request #22774 from gimantha/test
mohanvive Apr 20, 2020
28332e2
Avoid overriding tsybol when it's not null
pcnfernando Apr 20, 2020
31cad9e
Merge pull request #22773 from mohanvive/new-table-impl
mohanvive Apr 20, 2020
1bd7e3b
Merge branch 'new-table-impl' of https://github.com/ballerina-platfor…
mohanvive Apr 20, 2020
e9b0c1e
Merge pull request #22762 from pcnfernando/new-table-impl
pcnfernando Apr 20, 2020
4578404
Fix member access functionality in table implementation
gimantha Apr 20, 2020
11fbaa3
Improve type checker to validate readonly fields
mohanvive Apr 20, 2020
9e18369
Merge branch 'new-table-impl' of https://github.com/ballerina-platfor…
mohanvive Apr 20, 2020
4555357
Merge with upstream
gimantha Apr 20, 2020
36cb41d
Revert changes
gimantha Apr 20, 2020
2962660
Update Table langlib test cases
mohanvive Apr 20, 2020
872a7fc
Add table langlib to distribution gradle
mohanvive Apr 20, 2020
61b65f8
Merge pull request #22792 from mohanvive/new-table-impl
mohanvive Apr 21, 2020
1b3071e
Fix langlib table tests
gimantha Apr 21, 2020
c25a0e3
Fix checkstyle issues
gimantha Apr 21, 2020
c365c2b
Fix language server core test cases
mohanvive Apr 21, 2020
d0acee1
Merge pull request #22814 from mohanvive/new-table-impl
mohanvive Apr 21, 2020
3bb7199
Merge branch 'new-table-impl' of https://github.com/ballerina-platfor…
gimantha Apr 21, 2020
0426422
Comment test until readonly fully supported
gimantha Apr 21, 2020
4947c82
Merge pull request #22803 from gimantha/new-table-impl
mohanvive Apr 21, 2020
ff23495
Add type checking validations and negative test cases
mohanvive Apr 21, 2020
3dfd1c1
Merge branch 'new-table-impl' of https://github.com/ballerina-platfor…
mohanvive Apr 21, 2020
f4429a9
Add cast instruction for primitive keys
gimantha Apr 21, 2020
c3676ee
Merge branch 'new-table-impl' of https://github.com/ballerina-platfor…
gimantha Apr 21, 2020
9d2e0e9
Merge branch 'new-table-impl' of https://github.com/ballerina-platfor…
mohanvive Apr 21, 2020
00105eb
Add tuple type to hash method
gimantha Apr 21, 2020
9d2029f
Merge branch 'new-table-impl' of https://github.com/ballerina-platfor…
mohanvive Apr 22, 2020
16c5cf8
Fix checkstyle issue
gimantha Apr 22, 2020
e73f16f
Add testcases for table member access expressions
mohanvive Apr 22, 2020
4ad432d
Enable disabled tests
pcnfernando Apr 21, 2020
c1ea98d
Add a descriptive representation for table.toString()
pcnfernando Apr 21, 2020
5d3e0fd
Add initial negative test cases
pcnfernando Apr 21, 2020
5c20276
Add tests for compilation checks
pcnfernando Apr 21, 2020
a304ddb
Add nextKey() function and tests
pcnfernando Apr 22, 2020
35036c8
Update expectedExceptionsMessageRegExp in runtime error assertions
pcnfernando Apr 22, 2020
84c0899
Use anyToInt() for numeric conversion
pcnfernando Apr 22, 2020
3312fb4
Remove unnecessary new lines
pcnfernando Apr 22, 2020
f5e5a7b
Add member access runtime negative test cases
mohanvive Apr 22, 2020
8b75ee1
Support nextKey() for Map constrained tables
pcnfernando Apr 22, 2020
f908aba
Fix checkstyle issues
mohanvive Apr 22, 2020
7207611
Add testcase for constant expr validation
mohanvive Apr 22, 2020
8742a35
Merge pull request #22832 from mohanvive/new-table-impl
mohanvive Apr 22, 2020
8cc9220
Disable nextKey support for composite key specifiers
pcnfernando Apr 22, 2020
1e6a56e
Fix language server core testcase failures
mohanvive Apr 22, 2020
5362c88
Merge branch 'new-table-impl' of https://github.com/pcnfernando/balle…
mohanvive Apr 22, 2020
627d88e
Merge pull request #22830 from pcnfernando/new-table-impl
mohanvive Apr 23, 2020
cc73a81
Fix doc gen throwing NPE in keys() function
pcnfernando Apr 22, 2020
98c8d91
Use keys.size() check for maxIntKey initialization
pcnfernando Apr 23, 2020
b01c688
Add table testcases with var type
mohanvive Apr 23, 2020
defb4b5
Add negative test cases
mohanvive Apr 23, 2020
9788e9a
Merge pull request #22853 from pcnfernando/new-table-impl
pcnfernando Apr 23, 2020
4b9b742
Merge pull request #22857 from mohanvive/new-table-impl
mohanvive Apr 23, 2020
abcda5a
Add hash function to compile time for table constructor literals
gimantha Apr 23, 2020
b1e69a9
Merge branch 'master' of https://github.com/ballerina-platform/baller…
mohanvive Apr 23, 2020
c26d59f
Merge branch 'new-table-impl' of https://github.com/ballerina-platfor…
mohanvive Apr 23, 2020
9f5ab6d
Merge pull request #22863 from mohanvive/new-table-impl
mohanvive Apr 23, 2020
79b71fd
Check for duplicate keys in compile time in table constructor expr
gimantha Apr 24, 2020
9b370be
Sync new-table-impl branch with master
pcnfernando Apr 24, 2020
e0dd0c0
Merge pull request #22878 from gimantha/new-table-impl
mohanvive Apr 24, 2020
34a9566
Improve type checker validation for table constraint
mohanvive Apr 24, 2020
265a8aa
Fix key positions for negative test cases
mohanvive Apr 24, 2020
043de0a
Merge pull request #22891 from pcnfernando/new-table-impl
mohanvive Apr 24, 2020
e527382
Merge pull request #22892 from mohanvive/new-table-impl-2
mohanvive Apr 24, 2020
787f779
Refactor Code
gimantha Apr 27, 2020
7a9d8a6
Add logic for toString methods
mohanvive Apr 27, 2020
254055d
Always keep key specifier in LHS type
gimantha Apr 27, 2020
1403074
Refactor code
gimantha Apr 27, 2020
a21b933
Merge pull request #22912 from mohanvive/new-table-impl-2
mohanvive Apr 27, 2020
6c183c6
Fix javadoc issue
gimantha Apr 27, 2020
3efabb3
Improve typechecker validation for table
mohanvive Apr 27, 2020
55a4bf5
Merge branch 'master' of https://github.com/ballerina-platform/baller…
mohanvive Apr 27, 2020
7b244f9
Merge pull request #22919 from gimantha/new-table-impl
mohanvive Apr 27, 2020
12a2f9f
Fix testcases due to addition of table type
mohanvive Apr 27, 2020
e76b1f7
Fix test failure
mohanvive Apr 28, 2020
a31921e
Fix test failure
mohanvive Apr 28, 2020
485595c
Merge pull request #22923 from mohanvive/new-table-impl-2
mohanvive Apr 28, 2020
b35d970
Improve isAssignable logic of table
mohanvive Apr 28, 2020
9b36387
Disable the testcase since JDBC impl is removed
mohanvive Apr 28, 2020
f776625
Merge branch 'new-table-impl' of https://github.com/ballerina-platfor…
mohanvive Apr 28, 2020
8194a0c
Add testcase for Table isAssignable check
mohanvive Apr 28, 2020
972ae6d
Fix typechecker validations for table
mohanvive Apr 28, 2020
92abb20
Fix type param issue in table key type
gimantha Apr 28, 2020
fc37129
Refactor imports
gimantha Apr 28, 2020
4e26cea
Merge branch 'new-table-impl-2' of git://github.com/mohanvive/balleri…
gimantha Apr 28, 2020
6b339f6
Merge pull request #3 from gimantha/mohanvive-new-table-impl-2
mohanvive Apr 28, 2020
a2e0cd2
Merge branch 'master' of https://github.com/ballerina-platform/baller…
mohanvive Apr 28, 2020
ed235ba
Disable JDBC testcase due to removal of table
mohanvive Apr 28, 2020
3d6b5a7
Merge pull request #22928 from mohanvive/new-table-impl-2
mohanvive Apr 28, 2020
156c958
Merge branch 'master' of https://github.com/ballerina-platform/baller…
mohanvive Apr 29, 2020
d41da4f
Add table module to compiler unit test
mohanvive Apr 29, 2020
aebf529
Merge pull request #22951 from mohanvive/new-table-impl-2
mohanvive Apr 29, 2020
8d6dc75
Add negative testcases for table functions
mohanvive Apr 29, 2020
a27f2e0
Add table function introduced version as a comment
pcnfernando Apr 29, 2020
398df19
Refactor IndexBasedAccess node as per review feedback
mohanvive Apr 29, 2020
9439a3d
Add modifications as per review comments
mohanvive Apr 29, 2020
06f3cb2
Merge pull request #22967 from mohanvive/new-table-impl-2
mohanvive Apr 29, 2020
76842f7
Remove invalida todo flag
mohanvive Apr 29, 2020
79200c8
Merge branch 'new-table-impl' of https://github.com/ballerina-platfor…
mohanvive Apr 29, 2020
dce77c0
Fix code review changes
gimantha Apr 29, 2020
f3bdaa4
Merge pull request #22978 from gimantha/new-table-impl
mohanvive Apr 29, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,6 @@ branches:
- packerina-dev
- next-release
- release-stage
- new-table-impl
- stage
- /^ballerina-\d*[.]\d*[.]x$/
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public class TypeTags {
public static final int BOOLEAN_TAG = STRING_TAG + 1;
public static final int JSON_TAG = BOOLEAN_TAG + 1;
public static final int XML_TAG = JSON_TAG + 1;
public static final int NULL_TAG = XML_TAG + 1;
public static final int TABLE_TAG = XML_TAG + 1;
public static final int NULL_TAG = TABLE_TAG + 1;
public static final int ANYDATA_TAG = NULL_TAG + 1;
public static final int RECORD_TYPE_TAG = ANYDATA_TAG + 1;
public static final int TYPEDESC_TAG = RECORD_TYPE_TAG + 1;
Expand Down
2 changes: 2 additions & 0 deletions bvm/ballerina-rt/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies {
dist project(path: ':ballerina-lang:map', configuration: 'birJar')
dist project(path: ':ballerina-lang:object', configuration: 'birJar')
dist project(path: ':ballerina-lang:stream', configuration: 'birJar')
dist project(path: ':ballerina-lang:table', configuration: 'birJar')
dist project(path: ':ballerina-lang:string', configuration: 'birJar')
dist project(path: ':ballerina-lang:typedesc', configuration: 'birJar')
dist project(path: ':ballerina-lang:value', configuration: 'birJar')
Expand All @@ -62,6 +63,7 @@ dependencies {
dist project(':ballerina-lang:map')
dist project(':ballerina-lang:object')
dist project(':ballerina-lang:stream')
dist project(':ballerina-lang:table')
dist project(':ballerina-lang:string')
dist project(':ballerina-lang:typedesc')
dist project(':ballerina-lang:value')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.ballerinalang.jvm;

import org.ballerinalang.jvm.types.BType;
import org.ballerinalang.jvm.types.TypeTags;
import org.ballerinalang.jvm.util.exceptions.BLangExceptionHelper;
import org.ballerinalang.jvm.util.exceptions.BallerinaException;
import org.ballerinalang.jvm.util.exceptions.RuntimeErrors;
import org.ballerinalang.jvm.values.ArrayValue;
import org.ballerinalang.jvm.values.IteratorValue;
import org.ballerinalang.jvm.values.MapValue;
import org.ballerinalang.jvm.values.RefValue;
import org.ballerinalang.jvm.values.TableValue;

import java.util.List;
import java.util.Map;

import static org.ballerinalang.jvm.util.exceptions.BallerinaErrorReasons.CONSTRUCT_FROM_CYCLIC_VALUE_REFERENCE_ERROR;

/**
* This class contains the utility methods required by the table implementation.
*
* @since 1.3.0
*/

public class TableUtils {

/**
* Generates a hash value which is same for the same shape.
*
* @param obj Ballerina value which the hash is generated from
* @param checkedValues List of already hashed objects
* @return The hash value
*/
public static Integer hash(Object obj, List<Object> checkedValues) {
int result = 0;

if (checkedValues.contains(obj)) {
throw new BallerinaException(CONSTRUCT_FROM_CYCLIC_VALUE_REFERENCE_ERROR,
BLangExceptionHelper.getErrorMessage(RuntimeErrors.CYCLIC_VALUE_REFERENCE,
TypeChecker.getType(obj)));
}

checkedValues.add(obj);

if (obj instanceof RefValue) {
RefValue refValue = (RefValue) obj;
BType refType = refValue.getType();
if (refType.getTag() == TypeTags.MAP_TAG || refType.getTag() == TypeTags.RECORD_TYPE_TAG) {
MapValue mapValue = (MapValue) refValue;
for (Object entry : mapValue.entrySet()) {
result = 31 * result + hash(((Map.Entry) entry).getKey(), checkedValues) +
(((Map.Entry) entry).getValue() == null ? 0 : hash(((Map.Entry) entry).getValue(),
checkedValues));
}
return result;
} else if (refType.getTag() == TypeTags.ARRAY_TAG || refType.getTag() == TypeTags.TUPLE_TAG) {
ArrayValue arrayValue = (ArrayValue) refValue;
IteratorValue arrayIterator = arrayValue.getIterator();
while (arrayIterator.hasNext()) {
result = 31 * result + hash(arrayIterator.next(), checkedValues);
}
return result;
} else {
return obj.hashCode();
}
} else {
return obj.hashCode();
}
}

/**
* Handles table insertion/store functionality.
*
* @param tableValue Table value which the values are inserted to
* @param key The key associated with the value
* @param value The value being inserted
*/
public static void handleTableStore(TableValue<Object, Object> tableValue, Object key, Object value) {
tableValue.put(key, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.ballerinalang.jvm.types.BPackage;
import org.ballerinalang.jvm.types.BRecordType;
import org.ballerinalang.jvm.types.BStreamType;
import org.ballerinalang.jvm.types.BTableType;
import org.ballerinalang.jvm.types.BTupleType;
import org.ballerinalang.jvm.types.BType;
import org.ballerinalang.jvm.types.BTypedescType;
Expand Down Expand Up @@ -626,6 +627,8 @@ private static boolean checkIsRecursiveType(BType sourceType, BType targetType,
return checkIsMapType(sourceType, (BMapType) targetType, unresolvedTypes);
case TypeTags.STREAM_TAG:
return checkIsStreamType(sourceType, (BStreamType) targetType, unresolvedTypes);
case TypeTags.TABLE_TAG:
return checkIsTableType(sourceType, (BTableType) targetType, unresolvedTypes);
case TypeTags.JSON_TAG:
return checkIsJSONType(sourceType, unresolvedTypes);
case TypeTags.RECORD_TYPE_TAG:
Expand Down Expand Up @@ -695,12 +698,12 @@ private static boolean checkIsMapType(BType sourceType, BMapType targetType, Lis
BType targetConstrainedType = targetType.getConstrainedType();
switch (sourceType.getTag()) {
case TypeTags.MAP_TAG:
return checkContraints(((BMapType) sourceType).getConstrainedType(), targetConstrainedType,
return checkConstraints(((BMapType) sourceType).getConstrainedType(), targetConstrainedType,
unresolvedTypes);
case TypeTags.RECORD_TYPE_TAG:
BRecordType recType = (BRecordType) sourceType;
BUnionType wideTypeUnion = new BUnionType(getWideTypeComponents(recType));
return checkContraints(wideTypeUnion, targetConstrainedType, unresolvedTypes);
return checkConstraints(wideTypeUnion, targetConstrainedType, unresolvedTypes);
default:
return false;
}
Expand Down Expand Up @@ -741,10 +744,26 @@ private static boolean checkIsStreamType(BType sourceType, BStreamType targetTyp
if (sourceType.getTag() != TypeTags.STREAM_TAG) {
return false;
}
return checkContraints(((BStreamType) sourceType).getConstrainedType(), targetType.getConstrainedType(),
return checkConstraints(((BStreamType) sourceType).getConstrainedType(), targetType.getConstrainedType(),
unresolvedTypes);
}

private static boolean checkIsTableType(BType sourceType, BTableType targetType, List<TypePair> unresolvedTypes) {
if (sourceType.getTag() != TypeTags.TABLE_TAG) {
return false;
}
BTableType srcTableType = (BTableType) sourceType;
boolean isTableType = checkConstraints(srcTableType.getConstrainedType(), targetType.getConstrainedType(),
unresolvedTypes);

String[] targetKeySpecifier = targetType.getFieldNames();
if (targetKeySpecifier == null || targetKeySpecifier.length == 0) {
return isTableType;
}

return isTableType && Arrays.equals(srcTableType.getFieldNames(), targetKeySpecifier);
}

private static boolean checkIsJSONType(BType sourceType, List<TypePair> unresolvedTypes) {
BJSONType jsonType = (BJSONType) BTypes.typeJSON;

Expand Down Expand Up @@ -987,7 +1006,7 @@ private static boolean checkIsFutureType(BType sourceType, BFutureType targetTyp
if (sourceType.getTag() != TypeTags.FUTURE_TAG) {
return false;
}
return checkContraints(((BFutureType) sourceType).getConstrainedType(), targetType.getConstrainedType(),
return checkConstraints(((BFutureType) sourceType).getConstrainedType(), targetType.getConstrainedType(),
unresolvedTypes);
}

Expand Down Expand Up @@ -1134,8 +1153,8 @@ private static boolean isReadonlyType(BType sourceType) {
return false;
}

private static boolean checkContraints(BType sourceConstraint, BType targetConstraint,
List<TypePair> unresolvedTypes) {
private static boolean checkConstraints(BType sourceConstraint, BType targetConstraint,
List<TypePair> unresolvedTypes) {
if (sourceConstraint == null) {
sourceConstraint = BTypes.typeAny;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.ballerinalang.jvm.types;

import org.ballerinalang.jvm.values.TableValue;

/**
* {@code BTableType} represents tabular data in Ballerina.
*
* @since 1.3.0
*/
public class BTableType extends BType {

private BType constraint;
private BType keyType;
private String[] fieldNames;

public BTableType(BType constraint, String[] fieldNames) {
super(TypeConstants.TABLE_TNAME, null, TableValue.class);
this.constraint = constraint;
this.fieldNames = fieldNames;
this.keyType = null;
}

public BTableType(BType constraint) {
super(TypeConstants.TABLE_TNAME, null, TableValue.class);
this.constraint = constraint;
}

public BType getConstrainedType() {
return constraint;
}

public BType getKeyType() {
return keyType;
}

public String[] getFieldNames() {
return fieldNames;
}

@Override
public <V> V getZeroValue() {
return null;
}

@Override
public <V> V getEmptyValue() {
return null;
}

@Override
public int getTag() {
return TypeTags.TABLE_TAG;
}

@Override
public String toString() {
if (constraint == null) {
return super.toString();
}

StringBuilder keyStringBuilder = new StringBuilder();
if (fieldNames != null) {
for (String fieldName : fieldNames) {
if (!keyStringBuilder.toString().equals("")) {
keyStringBuilder.append(", ");
}
keyStringBuilder.append(fieldName);
}
return super.toString() + "<" + constraint.getName() + "> key(" + keyStringBuilder.toString() + ")";
}

return super.toString() + "<" + constraint.getName() + "> " +
((keyType != null) ? ("key<" + keyType + ">") : "");
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj) || !(obj instanceof BTableType)) {
return false;
}

BTableType other = (BTableType) obj;
if (constraint == other.constraint && keyType == other.keyType) {
return true;
}

if (constraint == null || other.constraint == null) {
return false;
}

if (keyType == null || other.keyType == null) {
return false;
}

return constraint.equals(other.constraint) && keyType.equals(other.keyType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public class TypeTags {
public static final int BOOLEAN_TAG = STRING_TAG + 1;
public static final int JSON_TAG = BOOLEAN_TAG + 1;
public static final int XML_TAG = JSON_TAG + 1;
public static final int NULL_TAG = XML_TAG + 1;
public static final int TABLE_TAG = XML_TAG + 1;
public static final int NULL_TAG = TABLE_TAG + 1;
public static final int ANYDATA_TAG = NULL_TAG + 1;
public static final int RECORD_TYPE_TAG = ANYDATA_TAG + 1;
public static final int TYPEDESC_TAG = RECORD_TYPE_TAG + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.ballerinalang.jvm.util.BLangConstants.FUTURE_LANG_LIB;
import static org.ballerinalang.jvm.util.BLangConstants.MAP_LANG_LIB;
import static org.ballerinalang.jvm.util.BLangConstants.STRING_LANG_LIB;
import static org.ballerinalang.jvm.util.BLangConstants.TABLE_LANG_LIB;
import static org.ballerinalang.jvm.util.BLangConstants.TYPEDESC_LANG_LIB;
import static org.ballerinalang.jvm.util.BLangConstants.VALUE_LANG_LIB;
import static org.ballerinalang.jvm.util.BLangConstants.XML_LANG_LIB;
Expand Down Expand Up @@ -78,6 +79,10 @@ public class BallerinaErrorReasons {
public static final String XML_OPERATION_ERROR = getModulePrefixedReason(XML_LANG_LIB, "XMLOperationError");
public static final String MAP_KEY_NOT_FOUND_ERROR = getModulePrefixedReason(MAP_LANG_LIB,
KEY_NOT_FOUND_ERROR_IDENTIFIER);
public static final String TABLE_KEY_NOT_FOUND_ERROR = getModulePrefixedReason(TABLE_LANG_LIB,
KEY_NOT_FOUND_ERROR_IDENTIFIER);
public static final String TABLE_HAS_A_VALUE_FOR_KEY_ERROR = getModulePrefixedReason(TABLE_LANG_LIB,
"KeyConstraintViolation");
public static final String ILLEGAL_LIST_INSERTION_ERROR = getModulePrefixedReason(ARRAY_LANG_LIB,
"IllegalListInsertion");
public static final String FUTURE_CANCELLED = getModulePrefixedReason(FUTURE_LANG_LIB, "FutureAlreadyCancelled");
Expand Down
Loading