import { CharCode , DecoratorKind , DecoratorNode , Expression , IdentifierExpression , NodeKind } from "assemblyscript" ; import { ContractDecoratorKind } from "../enums/decorator" ; import { RangeUtil } from "../utils/utils" ; function fromNode ( nameNode ) { if ( nameNode . kind == NodeKind . IDENTIFIER ) { let nameStr = ( < IdentifierExpression > nameNode ) . text ; switch ( nameStr . charCodeAt ( 0 ) ) { case CharCode . c : { if ( nameStr == "contract" ) return ContractDecoratorKind . CONTRACT ; if ( nameStr == "constructor" ) return ContractDecoratorKind . CONSTRUCTOR ; break ; } case CharCode . d : { if ( nameStr == 'doc' ) return ContractDecoratorKind . DOC ; if ( nameStr == "dynamic" ) return ContractDecoratorKind . DYNAMIC ; break ; } case CharCode . e : { if ( nameStr == "event" ) return ContractDecoratorKind . EVENT ; break ; } case CharCode . i : { if ( nameStr == "ignore" ) return ContractDecoratorKind . IGNORE ; break ; } case CharCode . m : { if ( nameStr == "message" ) return ContractDecoratorKind . MESSAGE ; break ; } case CharCode . p : { if ( nameStr == "packed" ) return ContractDecoratorKind . PACKED ; break ; } case CharCode . s : { if ( nameStr == "storage" ) return ContractDecoratorKind . STORAGE ; if ( nameStr == "spread" ) return ContractDecoratorKind . SPREAD ; break ; } case CharCode . t : { if ( nameStr == "topic" ) return ContractDecoratorKind . TOPIC ; break ; } } } return ContractDecoratorKind . OTHER ; } export function getCustomDecoratorKind ( decorator ) { if ( decorator . decoratorKind != DecoratorKind . CUSTOM ) { return ContractDecoratorKind . INTERNAL ; } let kind = fromNode ( decorator . name ) ; if ( kind == ContractDecoratorKind . OTHER ) { throw new Error ( `The contract don't support the decorator ${ decorator . name . range . toString ( ) }, please eheck ${ RangeUtil . location ( decorator . range ) }` ) ; } return kind ; }