|
| 1 | +private import Raw.Raw as Raw |
| 2 | +private import Location |
| 3 | +private import Ast as Ast |
| 4 | +private import Synthesis |
| 5 | +private import Expr |
| 6 | +private import Internal::Private |
| 7 | +private import Internal::Public |
| 8 | + |
| 9 | +private predicate mkSynthChild(SynthKind kind, Raw::Ast parent, ChildIndex i) { |
| 10 | + any(Synthesis s).child(parent, i, SynthChild(kind)) |
| 11 | +} |
| 12 | + |
| 13 | +cached |
| 14 | +private module Cached { |
| 15 | + private predicate excludeStringConstExpr(Raw::StringConstExpr e) { |
| 16 | + // i.e., "Node" or "Script" |
| 17 | + dynamic_keyword_statement_command_elements(_, 0, e) |
| 18 | + } |
| 19 | + |
| 20 | + cached |
| 21 | + newtype TAst = |
| 22 | + TAttributedExpr(Raw::AttributedExpr a) or |
| 23 | + TArrayExpr(Raw::ArrayExpr e) or |
| 24 | + TArrayLiteral(Raw::ArrayLiteral lit) or |
| 25 | + TAssignStmt(Raw::AssignStmt s) or |
| 26 | + TAttribute(Raw::Attribute a) or |
| 27 | + TBinaryExpr(Raw::BinaryExpr bin) or |
| 28 | + TBreakStmt(Raw::BreakStmt br) or |
| 29 | + TCatchClause(Raw::CatchClause cc) or |
| 30 | + TCmd(Raw::Cmd c) or |
| 31 | + TExprStmtSynth(Raw::Ast parent, ChildIndex i) { mkSynthChild(ExprStmtKind(), parent, i) } or |
| 32 | + TTopLevelFunction(Raw::TopLevelScriptBlock scriptBlock) or |
| 33 | + TFunctionSynth(Raw::Ast parent, ChildIndex i) { mkSynthChild(FunctionSynthKind(), parent, i) } or |
| 34 | + TConfiguration(Raw::Configuration c) or |
| 35 | + TConstExpr(Raw::ConstExpr c) or |
| 36 | + TContinueStmt(Raw::ContinueStmt c) or |
| 37 | + TConvertExpr(Raw::ConvertExpr c) or |
| 38 | + TDataStmt(Raw::DataStmt d) or |
| 39 | + TDoUntilStmt(Raw::DoUntilStmt d) or |
| 40 | + TDoWhileStmt(Raw::DoWhileStmt d) or |
| 41 | + TDynamicStmt(Raw::DynamicStmt d) or |
| 42 | + TErrorExpr(Raw::ErrorExpr e) or |
| 43 | + TErrorStmt(Raw::ErrorStmt e) or |
| 44 | + TExitStmt(Raw::ExitStmt e) or |
| 45 | + TExpandableStringExpr(Raw::ExpandableStringExpr e) or |
| 46 | + TFunctionDefinitionStmt(Raw::FunctionDefinitionStmt f) { not excludeFunctionDefinitionStmt(f) } or |
| 47 | + TForEachStmt(Raw::ForEachStmt f) or |
| 48 | + TForStmt(Raw::ForStmt f) or |
| 49 | + THashTableExpr(Raw::HashTableExpr h) or |
| 50 | + TIf(Raw::IfStmt i) or |
| 51 | + TIndexExpr(Raw::IndexExpr i) or |
| 52 | + TInvokeMemberExpr(Raw::InvokeMemberExpr i) or |
| 53 | + TMethod(Raw::Method m) or |
| 54 | + TMemberExpr(Raw::MemberExpr m) or |
| 55 | + TNamedAttributeArgument(Raw::NamedAttributeArgument n) or |
| 56 | + TNamedBlock(Raw::NamedBlock n) or |
| 57 | + TParenExpr(Raw::ParenExpr p) or |
| 58 | + TPipeline(Raw::Pipeline p) or |
| 59 | + TPipelineChain(Raw::PipelineChain p) or |
| 60 | + TPropertyMember(Raw::PropertyMember p) or |
| 61 | + TRedirection(Raw::Redirection r) or |
| 62 | + TReturnStmt(Raw::ReturnStmt r) or |
| 63 | + TScriptBlock(Raw::ScriptBlock s) or |
| 64 | + TScriptBlockExpr(Raw::ScriptBlockExpr s) or |
| 65 | + TExpandableSubExpr(Raw::ExpandableSubExpr e) or |
| 66 | + TStmtBlock(Raw::StmtBlock s) or |
| 67 | + TStringConstExpr(Raw::StringConstExpr s) { not excludeStringConstExpr(s) } or |
| 68 | + TSwitchStmt(Raw::SwitchStmt s) or |
| 69 | + TConditionalExpr(Raw::ConditionalExpr t) or |
| 70 | + TThrowStmt(Raw::ThrowStmt t) or |
| 71 | + TTrapStmt(Raw::TrapStmt t) or |
| 72 | + TThisExprReal(Raw::ThisAccess t) or |
| 73 | + TTryStmt(Raw::TryStmt t) or |
| 74 | + TTypeDefinitionStmt(Raw::TypeStmt t) or |
| 75 | + TTypeSynth(Raw::Ast parent, ChildIndex i) { mkSynthChild(TypeSynthKind(), parent, i) } or |
| 76 | + TTypeConstraint(Raw::TypeConstraint t) or |
| 77 | + TUnaryExpr(Raw::UnaryExpr u) or |
| 78 | + TUsingStmt(Raw::UsingStmt u) or |
| 79 | + TWhileStmt(Raw::WhileStmt w) or |
| 80 | + TTypeNameExpr(Raw::TypeNameExpr t) or |
| 81 | + TUsingExpr(Raw::UsingExpr u) or |
| 82 | + TBoolLiteral(Raw::Ast parent, ChildIndex i) { mkSynthChild(BoolLiteralKind(_), parent, i) } or |
| 83 | + TNullLiteral(Raw::Ast parent, ChildIndex i) { mkSynthChild(NullLiteralKind(), parent, i) } or |
| 84 | + TEnvVariable(Raw::Ast parent, ChildIndex i) { mkSynthChild(EnvVariableKind(_), parent, i) } or |
| 85 | + TAutomaticVariable(Raw::Ast parent, ChildIndex i) { |
| 86 | + mkSynthChild(AutomaticVariableKind(_), parent, i) |
| 87 | + } |
| 88 | + |
| 89 | + class TAstReal = |
| 90 | + TArrayExpr or TArrayLiteral or TAssignStmt or TAttribute or TOperation or TBreakStmt or |
| 91 | + TCatchClause or TCmd or TConfiguration or TConstExpr or TContinueStmt or TConvertExpr or |
| 92 | + TDataStmt or TDoUntilStmt or TDoWhileStmt or TDynamicStmt or TErrorExpr or TErrorStmt or |
| 93 | + TExitStmt or TExpandableStringExpr or TForEachStmt or TForStmt or TGotoStmt or |
| 94 | + THashTableExpr or TIf or TIndexExpr or TInvokeMemberExpr or TMemberExpr or |
| 95 | + TNamedAttributeArgument or TNamedBlock or TPipeline or TPipelineChain or TPropertyMember or |
| 96 | + TRedirection or TReturnStmt or TScriptBlock or TScriptBlockExpr or TStmtBlock or |
| 97 | + TStringConstExpr or TSwitchStmt or TConditionalExpr or TThrowStmt or TTrapStmt or |
| 98 | + TTryStmt or TTypeDefinitionStmt or TTypeConstraint or TUsingStmt or |
| 99 | + TWhileStmt or TFunctionDefinitionStmt or TExpandableSubExpr or TMethod or TTypeNameExpr or |
| 100 | + TAttributedExpr or TUsingExpr or TThisExprReal or TParenExpr ; |
| 101 | + |
| 102 | + class TAstSynth = |
| 103 | + TExprStmtSynth or TFunctionSynth or TBoolLiteral or TNullLiteral or |
| 104 | + TEnvVariable or TTypeSynth or TAutomaticVariable; |
| 105 | + |
| 106 | + class TExpr = |
| 107 | + TArrayExpr or TArrayLiteral or TOperation or TConstExpr or TConvertExpr or TErrorExpr or |
| 108 | + THashTableExpr or TIndexExpr or TInvokeMemberExpr or TCmd or TMemberExpr or TPipeline or |
| 109 | + TPipelineChain or TStringConstExpr or TConditionalExpr or |
| 110 | + TExpandableStringExpr or TScriptBlockExpr or TExpandableSubExpr or TTypeNameExpr or |
| 111 | + TUsingExpr or TAttributedExpr or TIf or TBoolLiteral or TNullLiteral or TThisExpr or |
| 112 | + TEnvVariable or TAutomaticVariable or TParenExpr; |
| 113 | + |
| 114 | + class TStmt = |
| 115 | + TAssignStmt or TBreakStmt or TContinueStmt or TDataStmt or TDoUntilStmt or TDoWhileStmt or |
| 116 | + TDynamicStmt or TErrorStmt or TExitStmt or TForEachStmt or TForStmt or TGotoStmt or |
| 117 | + TReturnStmt or TStmtBlock or TSwitchStmt or TThrowStmt or TTrapStmt or TTryStmt or |
| 118 | + TUsingStmt or TWhileStmt or TConfiguration or TTypeDefinitionStmt or |
| 119 | + TFunctionDefinitionStmt or TExprStmt; |
| 120 | + |
| 121 | + class TType = TTypeSynth; |
| 122 | + |
| 123 | + class TOperation = TBinaryExpr or TUnaryExpr; |
| 124 | + |
| 125 | + class TMember = TPropertyMember or TMethod; |
| 126 | + |
| 127 | + class TExprStmt = TExprStmtSynth; |
| 128 | + |
| 129 | + class TAttributeBase = TAttribute or TTypeConstraint; |
| 130 | + |
| 131 | + class TFunction = TFunctionSynth or TTopLevelFunction; |
| 132 | + |
| 133 | + class TFunctionBase = TFunction or TMethod; |
| 134 | + |
| 135 | + class TAttributedExprBase = TAttributedExpr or TConvertExpr; |
| 136 | + |
| 137 | + class TCallExpr = TCmd or TInvokeMemberExpr; |
| 138 | + |
| 139 | + class TLoopStmt = TDoUntilStmt or TDoWhileStmt or TForEachStmt or TForStmt or TWhileStmt; |
| 140 | + |
| 141 | + class TLiteral = TBoolLiteral or TNullLiteral; |
| 142 | + |
| 143 | + class TGotoStmt = TContinueStmt or TBreakStmt; |
| 144 | + |
| 145 | + class TThisExpr = TThisExprReal; |
| 146 | + |
| 147 | + cached |
| 148 | + Raw::Ast toRaw(TAstReal n) { |
| 149 | + n = TArrayExpr(result) or |
| 150 | + n = TArrayLiteral(result) or |
| 151 | + n = TAssignStmt(result) or |
| 152 | + n = TAttribute(result) or |
| 153 | + n = TBinaryExpr(result) or |
| 154 | + n = TBreakStmt(result) or |
| 155 | + n = TCatchClause(result) or |
| 156 | + n = TCmd(result) or |
| 157 | + n = TConfiguration(result) or |
| 158 | + n = TConstExpr(result) or |
| 159 | + n = TContinueStmt(result) or |
| 160 | + n = TConvertExpr(result) or |
| 161 | + n = TDataStmt(result) or |
| 162 | + n = TDoUntilStmt(result) or |
| 163 | + n = TDoWhileStmt(result) or |
| 164 | + n = TDynamicStmt(result) or |
| 165 | + n = TErrorExpr(result) or |
| 166 | + n = TErrorStmt(result) or |
| 167 | + n = TExitStmt(result) or |
| 168 | + n = TExpandableStringExpr(result) or |
| 169 | + n = TForEachStmt(result) or |
| 170 | + n = TForStmt(result) or |
| 171 | + n = THashTableExpr(result) or |
| 172 | + n = TIf(result) or |
| 173 | + n = TIndexExpr(result) or |
| 174 | + n = TInvokeMemberExpr(result) or |
| 175 | + n = TMemberExpr(result) or |
| 176 | + n = TNamedAttributeArgument(result) or |
| 177 | + n = TNamedBlock(result) or |
| 178 | + n = TPipeline(result) or |
| 179 | + n = TParenExpr(result) or |
| 180 | + n = TPipelineChain(result) or |
| 181 | + n = TPropertyMember(result) or |
| 182 | + n = TRedirection(result) or |
| 183 | + n = TReturnStmt(result) or |
| 184 | + n = TScriptBlock(result) or |
| 185 | + n = TScriptBlockExpr(result) or |
| 186 | + n = TStmtBlock(result) or |
| 187 | + n = TStringConstExpr(result) or |
| 188 | + n = TSwitchStmt(result) or |
| 189 | + n = TConditionalExpr(result) or |
| 190 | + n = TThrowStmt(result) or |
| 191 | + n = TTrapStmt(result) or |
| 192 | + n = TTryStmt(result) or |
| 193 | + n = TTypeDefinitionStmt(result) or |
| 194 | + n = TThisExprReal(result) or |
| 195 | + n = TTypeConstraint(result) or |
| 196 | + n = TUnaryExpr(result) or |
| 197 | + n = TUsingStmt(result) or |
| 198 | + n = TWhileStmt(result) or |
| 199 | + n = TFunctionDefinitionStmt(result) or |
| 200 | + n = TExpandableSubExpr(result) or |
| 201 | + n = TTypeNameExpr(result) or |
| 202 | + n = TMethod(result) or |
| 203 | + n = TAttributedExpr(result) or |
| 204 | + n = TUsingExpr(result) or |
| 205 | + } |
| 206 | + |
| 207 | + cached |
| 208 | + Raw::Ast toRawIncludingSynth(Ast::Ast n) { |
| 209 | + result = toRaw(n) |
| 210 | + or |
| 211 | + not exists(toRaw(n)) and |
| 212 | + exists(Raw::Ast parent | |
| 213 | + synthChild(parent, _, n) and |
| 214 | + result = parent |
| 215 | + ) |
| 216 | + } |
| 217 | + |
| 218 | + cached |
| 219 | + TAstReal fromRaw(Raw::Ast a) { toRaw(result) = a } |
| 220 | + |
| 221 | + cached |
| 222 | + Ast::Ast getSynthChild(Raw::Ast parent, ChildIndex i) { |
| 223 | + result = TExprStmtSynth(parent, i) or |
| 224 | + result = TFunctionSynth(parent, i) or |
| 225 | + result = TBoolLiteral(parent, i) or |
| 226 | + result = TNullLiteral(parent, i) or |
| 227 | + result = TEnvVariable(parent, i) or |
| 228 | + result = TTypeSynth(parent, i) or |
| 229 | + result = TAutomaticVariable(parent, i) |
| 230 | + } |
| 231 | + |
| 232 | + cached |
| 233 | + predicate synthChild(Raw::Ast parent, ChildIndex i, Ast::Ast child) { |
| 234 | + child = getSynthChild(parent, i) |
| 235 | + or |
| 236 | + any(Synthesis s).child(parent, i, RealChildRef(child)) |
| 237 | + or |
| 238 | + any(Synthesis s).child(parent, i, SynthChildRef(child)) |
| 239 | + } |
| 240 | +} |
| 241 | + |
| 242 | +import Cached |
0 commit comments