Skip to content

Commit f3099a8

Browse files
committed
赋值相关提示
移除多余文件
1 parent 82ecdcc commit f3099a8

39 files changed

+216
-420
lines changed

src/main/kotlin/top/mcfpp/antlr/McfppFuncManager.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package top.mcfpp.antlr
22

33
import top.mcfpp.lang.*
44
import top.mcfpp.lang.type.MCFPPType
5+
import top.mcfpp.model.CanSelectMember
6+
import top.mcfpp.model.CompoundDataCompanion
57
import top.mcfpp.model.function.Function
68
import top.mcfpp.model.Member
79
import top.mcfpp.util.LogProcessor

src/main/kotlin/top/mcfpp/antlr/McfppLeftExprVisitor.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import top.mcfpp.lang.*
66
import top.mcfpp.model.*
77
import top.mcfpp.model.function.Function
88
import top.mcfpp.model.field.GlobalField
9-
import top.mcfpp.model.function.ExtensionFunction
109
import top.mcfpp.model.function.FunctionParam
1110
import top.mcfpp.model.function.UnknownFunction
1211
import top.mcfpp.model.generic.Generic

src/main/kotlin/top/mcfpp/command/Commands.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import top.mcfpp.Project
66
import top.mcfpp.lang.*
77
import top.mcfpp.lang.type.MCFPPClassType
88
import top.mcfpp.lib.NBTPath
9+
import top.mcfpp.model.CanSelectMember
910
import top.mcfpp.model.function.Function
1011
import top.mcfpp.model.function.NoStackFunction
1112
import java.util.*

src/main/kotlin/top/mcfpp/lang/ClassBase.kt

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/main/kotlin/top/mcfpp/lang/ClassObject.kt

Lines changed: 0 additions & 126 deletions
This file was deleted.

src/main/kotlin/top/mcfpp/lang/ClassPointer.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import top.mcfpp.model.function.NoStackFunction
1616
import top.mcfpp.model.function.UnknownFunction
1717
import top.mcfpp.util.LogProcessor
1818
import top.mcfpp.util.StringHelper
19+
import top.mcfpp.util.TextTranslator
20+
import top.mcfpp.util.TextTranslator.translate
1921
import java.util.*
2022

2123
/**
@@ -86,19 +88,24 @@ class ClassPointer : Var<Int>{
8688
@InsertCommand
8789
@Throws(VariableConverseException::class)
8890
override fun assign(b: Var<*>): ClassPointer {
91+
var v = b.implicitCast(this.type)
92+
if(!v.isError){
93+
v = b
94+
}
8995
hasAssigned = true
9096
//TODO 不支持指针作为类成员的时候
91-
when (b) {
97+
when (v) {
9298
is ClassPointer -> {
93-
if (!b.clazz.canCastTo(clazz)) {
94-
throw VariableConverseException()
99+
if (!v.clazz.canCastTo(clazz)) {
100+
LogProcessor.error(TextTranslator.ASSIGN_ERROR.translate(v.type.typeName, type.typeName))
101+
return this
95102
}
96103
if (!isNull) {
97104
//原实体中的实例减少一个指针
98105
val c = Commands.selectRun(this,Commands.sbPlayerRemove(MCInt("@s").setObj(SbObject.MCFPP_POINTER_COUNTER) as MCInt, 1))
99106
Function.addCommands(c)
100107
}
101-
isNull = b.isNull
108+
isNull = v.isNull
102109
//地址储存
103110
Function.addCommand(
104111
Command.build("data modify")
@@ -112,7 +119,7 @@ class ClassPointer : Var<Int>{
112119
}
113120

114121
else -> {
115-
throw VariableConverseException()
122+
LogProcessor.error(TextTranslator.ASSIGN_ERROR.translate(v.type.typeName, type.typeName))
116123
}
117124
}
118125
return this

src/main/kotlin/top/mcfpp/lang/DataTemplateObject.kt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,33 +48,38 @@ open class DataTemplateObject : Var<CompoundTag> {
4848

4949

5050
override fun assign(b: Var<*>): Var<CompoundTag> {
51-
when(b){
51+
var v = b.implicitCast(this.type)
52+
if(!v.isError){
53+
v = b
54+
}
55+
hasAssigned = true
56+
when(v){
5257
is NBTBasedDataConcrete<*> -> {
53-
if(b.value !is CompoundTag){
58+
if(v.value !is CompoundTag){
5459
throw VariableConverseException()
5560
}
56-
if(templateType.checkCompoundStruct(b.value as CompoundTag)){
57-
this.assignMembers(b.value as CompoundTag)
61+
if(templateType.checkCompoundStruct(v.value as CompoundTag)){
62+
this.assignMembers(v.value as CompoundTag)
5863
return this
5964
}else{
6065
throw VariableConverseException()
6166
}
6267
}
6368

6469
is DataTemplateObjectConcrete -> {
65-
if(templateType.checkCompoundStruct(b.value)){
66-
this.assignMembers(b.value)
70+
if(templateType.checkCompoundStruct(v.value)){
71+
this.assignMembers(v.value)
6772
return this
6873
}else{
6974
throw VariableConverseException()
7075
}
7176
}
7277

7378
is DataTemplateObject -> {
74-
if (!b.templateType.canCastTo(templateType)) {
79+
if (!v.templateType.canCastTo(templateType)) {
7580
throw VariableConverseException()
7681
}else{
77-
assignCommand(b)
82+
assignCommand(v)
7883
return this
7984
}
8085
}
@@ -83,7 +88,6 @@ open class DataTemplateObject : Var<CompoundTag> {
8388
throw VariableConverseException()
8489
}
8590
}
86-
return this
8791
}
8892

8993
fun assignMembers(tag: CompoundTag){

src/main/kotlin/top/mcfpp/lang/EntityVar.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import top.mcfpp.model.FieldContainer
1818
import top.mcfpp.model.Member
1919
import top.mcfpp.model.function.Function
2020
import top.mcfpp.util.LogProcessor
21+
import top.mcfpp.util.TextTranslator
22+
import top.mcfpp.util.TextTranslator.translate
2123
import java.util.UUID
2224

2325

@@ -73,13 +75,17 @@ open class EntityVar : NBTBasedData<IntArrayTag>{
7375
* @param b 变量的对象
7476
*/
7577
override fun assign(b: Var<*>): EntityVar {
78+
var v = b.implicitCast(this.type)
79+
if(!v.isError){
80+
v = b
81+
}
7682
hasAssigned = true
77-
when (b) {
83+
when (v) {
7884
is EntityVar -> {
79-
assignCommand(b)
85+
assignCommand(v)
8086
}
8187
else -> {
82-
LogProcessor.error("Cannot cast [${this.type}] to [$type]")
88+
LogProcessor.error(TextTranslator.ASSIGN_ERROR.translate(v.type.typeName, type.typeName))
8389
}
8490
}
8591
return this

src/main/kotlin/top/mcfpp/lang/EnumVar.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import top.mcfpp.model.FieldContainer
1414
import top.mcfpp.model.Member
1515
import top.mcfpp.model.function.Function
1616
import top.mcfpp.util.LogProcessor
17+
import top.mcfpp.util.TextTranslator
18+
import top.mcfpp.util.TextTranslator.translate
1719
import java.util.*
1820

1921
open class EnumVar : Var<Int> {
@@ -60,14 +62,20 @@ open class EnumVar : Var<Int> {
6062
}
6163

6264
override fun assign(b: Var<*>): Var<Int> {
63-
return when(b){
65+
var v = b.implicitCast(this.type)
66+
if(!v.isError){
67+
v = b
68+
}
69+
hasAssigned = true
70+
return when(v){
6471
is EnumVar -> {
65-
val i = this.getIntVar().assign(b.getIntVar())
72+
val i = this.getIntVar().assign(v.getIntVar())
6673
if(i is MCIntConcrete) EnumVarConcrete(i, enum)
6774
else EnumVar(i, enum)
6875
}
6976
else -> {
70-
throw Exception("Cannot assign ${b::class.simpleName} to EnumVar")
77+
LogProcessor.error(TextTranslator.ASSIGN_ERROR.translate(v.type.typeName, type.typeName))
78+
this
7179
}
7280
}
7381
}

src/main/kotlin/top/mcfpp/lang/JavaVar.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,17 @@ class JavaVar : Var<Any>, MCFPPValue<Any?>{
7070
* @param b 变量的对象
7171
*/
7272
override fun assign(b: Var<*>): Var<Any> {
73+
var v = b.implicitCast(this.type)
74+
if(!v.isError){
75+
v = b
76+
}
7377
hasAssigned = true
74-
when (b) {
78+
when (v) {
7579
is JavaVar -> {
76-
this.value = b.value
80+
this.value = v.value
7781
}
7882
else -> {
79-
this.value = b
83+
this.value = v
8084
}
8185
}
8286
return this

0 commit comments

Comments
 (0)