Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Modeling ASTs with FAST (mooseday13)

Modeling ASTs with FAST (mooseday13)

Yuriy Tymchuk

April 04, 2013
Tweet

More Decks by Yuriy Tymchuk

Other Decks in Science

Transcript

  1. MODELING ASTS WITH FAST
    Yuriy “Uko” Tymchuk

    View full-size slide

  2. FAMIX
    Access
    Invocation

    View full-size slide

  3. PROBLEM?
    • Calculating metrics
    • Rule checking
    • Detecting duplication
    • Representing (eg. visualizing)
    • Language conversions
    • And more…

    View full-size slide

  4. can’t handle that!
    AST
    FAMIX
    we need

    View full-size slide

  5. FAST
    0%
    25%
    50%
    75%
    100%
    Smalltalk Java

    View full-size slide

  6. FAST IMPORTERS
    PetitParser

    View full-size slide

  7. GENERAL FAST DIAGRAM
    FASTBehaviouralEntity
    0..*
    statements
    0..1
    parentStatementBlock
    FASTStatement
    FASTNamedEntity
    name : String
    0..*
    parameters
    0..*
    localVariables
    FAMIXBehaviouralEntity
    0..1
    fastNamedBehaviouralEntity
    0..1
    famixBehaviouralEntity
    FAMIXNamedEntity
    0..*
    fastNamedEntities
    0..1
    famixNamedEntity
    FASTNamedBehaviouralEntity
    name : String
    FASTExpression
    0..1
    parentBehaviouralEntity
    0..1
    parentExpression**
    0..1
    parentStatement**
    FASTStatementBlock
    0..1
    parentBehaviouralEntity
    0..1
    statementBlock
    FASTVariableExpression
    0..1
    parentVariableExpression
    0..1
    variable
    FASTLiteral
    signature : string

    View full-size slide

  8. SMALLTALK FAST
    DIAGRAM
    FASTBehaviouralEntity
    0..*
    statements
    0..1
    parentStatementBlock
    FASTVariableExpression FASTLiteral
    signature : String
    FASTMessageSend
    kind
    selector
    isUnary()
    isBinary()
    isKey()
    cascaded()
    receiver()
    FASTStatement
    0..1
    parentExpression
    0..*
    arguments
    FASTAssignmentExpression
    0..1
    parentAssignmentExpression
    0..1
    variable
    FASTExpression
    0..1
    parentStatement 0..1
    expression
    FASTArrayExpression FASTCascade
    0..1
    parentCascade
    0..*
    messages
    0..1
    parentExpression
    0..1
    concreteReceiver
    0..1
    parentExpression
    0..1
    block
    FASTSmalltalkReturnStatement
    FASTSmalltalkExpressionStatement
    0..1
    parentStatement 0..1
    expression
    0..1
    parentExpression
    0..1
    expression
    FASTNamedEntity
    name : String
    0..*
    parameters
    0..*
    localVariables
    0..1
    parentVariableExpression
    0..1
    variable
    FASTBlockDefinition
    FAMIXBehaviouralEntity
    0..1
    fastNamedBehaviouralEntity
    0..1
    famixBehaviouralEntity
    FAMIXNamedEntity
    0..*
    fastNamedEntities
    0..1
    famixNamedEntity
    FASTNamedBehaviouralEntity
    name : String
    FASTNumberLiteral
    value : Number
    FASTCharacterLiteral
    value : Object
    FASTStringLiteral
    value : String
    FASTSymbolLiteral
    value : Object
    FASTArrayLiteral FASTByteArrayLiteral
    0..*
    contents
    0..*
    contents
    FASTBlockExpression
    0..1
    parentExpression
    0..*
    contents
    FASTBooleanLiteral
    value : Boolean
    FASTUndefinedLiteral
    0..1
    parentExpression
    0..1
    receiver
    0..1
    parentBehaviouralEntity
    FAMIXInvocation
    0..1
    messageSend
    0..1
    invocation
    FASTStatementBlock
    0..1
    parentBehaviouralEntity
    0..1
    statementBlock

    View full-size slide

  9. RB CASCADE DESIGN
    Cascade
    Message1 arguments…
    Message2 arguments…
    Message3 arguments…
    RECEIVER

    View full-size slide

  10. FAST CASCADE DESIGN
    Cascade
    RECEIVER
    Message1 arguments…
    Message2 arguments…
    Message3 arguments…

    View full-size slide

  11. SMALLTALK / JAVA
    COMPARISON
    0
    8
    15
    23
    30
    Statements
    Expression
    Smalltalk Java

    View full-size slide

  12. http://uko-on-code.blogspot.com

    View full-size slide

  13. JAVA FAST DIAGRAM
    FASTBehaviouralEntity
    0..*
    statements
    0..1
    parentStatementBlock
    FASTStatement
    FASTNamedEntity
    name : String
    0..*
    parameters
    0..*
    localVariables
    FAMIXBehaviouralEntity
    0..1
    fastNamedBehaviouralEntity
    0..1
    famixBehaviouralEntity
    FAMIXNamedEntity
    0..*
    fastNamedEntities
    0..1
    famixNamedEntity
    FASTNamedBehaviouralEntity
    name : String
    FASTExpression
    0..1
    parentBehaviouralEntity
    StatementBlock
    0..1
    parentBehaviouralEntity
    0..1
    statementBlock
    FASTVariableExpression
    0..1
    parentVariableExpression
    0..1
    variable
    FASTLiteral
    signature : string
    FASTJavaExpressionStatement
    FASTJavaReturnStatement
    0..1
    parentStatement
    0..1
    expression
    0..1
    parentStatement
    0..1
    expression
    FASTWhileStatement
    0..1
    parentStatement
    0..1
    condition
    0..1
    parentStatement
    0..1
    body
    FASTVariableDeclarationStatement
    FASTVariableDeclarator
    0..1
    parentStatement
    0..*
    declarators
    0..1
    variable
    0..1
    initializer
    FASTJavaIntegerLiteral FASTJavaBooleanLiteral FASTJavaStringLiteral
    FASTInfixOperation 0..1
    parentExpression
    0..1
    leftOperand
    0..1
    parentExpression
    0..1
    rightOperand

    View full-size slide

  14. FAST ANALYSES

    View full-size slide

  15. SYMBOL RESOLUTION
    #middleOf:and:
    b
    a
    sum
    ^st
    st
    :=
    sum +
    a b
    /
    sum 2
    middleOf: a and: b
    | sum |
    sum := a + b.
    ^ sum / 2

    View full-size slide

  16. SYMBOL RESOLUTION
    b
    a
    sum
    #middleOf:and:
    b
    a
    sum
    ^st
    st
    :=
    sum +
    a b
    /
    sum 2

    View full-size slide

  17. SYMBOL RESOLUTION
    b
    a
    sum
    #middleOf:and:
    b
    a
    sum
    ^st
    st
    :=
    sum +
    a b
    /
    sum 2

    View full-size slide

  18. RESOLVING SYMBOLS
    Scope
    • name-variable dictionary
    • parent scope
    • owner entity
    Scope
    • name-variable dictionary
    • parent scope
    • owner entity

    View full-size slide

  19. CALCULATING METRICS
    • nodes of a Kind
    • cyclomatic complexity
    Amount of something in code

    View full-size slide

  20. CALCULATING METRICS
    collection inject: initial into: [block]
    CollectorVisitor newWithSeed: initial andBlock: [block]

    View full-size slide

  21. CYCLOMATIC COMPLEXITY
    Each node knows it’s complexity contribution
    • Class = 0
    • ReturnStatement = 0
    • IfStatement = 1
    • WhileStatement = 1
    • MessageSend (#ifTrue:) = 1! ! ! ! calculated at runtime
    • MessageSend (#detect:ifNone:) = 2
    • “for ... else” statement = 2!! ! ! ! python

    View full-size slide

  22. FAST CONTRIBUTION
    http://smalltalkhub.com/#!/~YuriyTymchuk/FAST
    https://github.com/Uko/FAST
    https://ci.inria.fr/moose/job/FAST-On-Moose

    View full-size slide

  23. FAST GSOC
    FAST Java Model Tree models visualization
    The idea behind this project is to
    develop an inter active tree
    visualization that will gradually
    improve analysis of the underlying
    model.
    The goal of this project is to create a
    Java version of FAST.

    View full-size slide

  24. THANKS
    Stéphane Ducasse
    Nicolas Anquetil
    RMoD team

    View full-size slide