Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import pt.up.fe.specs.clava.ast.expr.data.designator.Designator;
import pt.up.fe.specs.clava.ast.expr.data.designator.FieldDesignator;
import pt.up.fe.specs.clava.ast.expr.data.offsetof.OffsetOfArray;
import pt.up.fe.specs.clava.ast.expr.data.offsetof.OffsetOfBase;
import pt.up.fe.specs.clava.ast.expr.data.offsetof.OffsetOfComponent;
import pt.up.fe.specs.clava.ast.expr.data.offsetof.OffsetOfComponentKind;
import pt.up.fe.specs.clava.ast.expr.data.offsetof.OffsetOfField;
Expand Down Expand Up @@ -459,6 +460,9 @@ public static OffsetOfComponent offsetOfComponent(LineStream lines, ClangAstData
case IDENTIFIER:
component.set(OffsetOfIdentifier.FIELD_NAME, lines.nextLine());
break;
case BASE:
parserData.getClavaNodes().queueSetNode(component, OffsetOfBase.TYPE, lines.nextLine());
break;
default:
throw new NotImplementedException(kind);
}
Expand Down
16 changes: 9 additions & 7 deletions ClavaAst/src/pt/up/fe/specs/clava/ast/expr/OffsetOfExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,20 @@ private String getComponentsCode() {

StringBuilder code = new StringBuilder();

boolean isFirst = true;
boolean hasCode = false;
for (OffsetOfComponent component : get(COMPONENTS)) {
String componentCode = component.getCode();

if (component.isField() && !isFirst) {
code.append(".");
if (componentCode.isEmpty()) {
continue;
}

code.append(component.getCode());

if (isFirst) {
isFirst = false;
if (component.isField() && hasCode) {
code.append(".");
}

code.append(componentCode);
hasCode = true;
}
return code.toString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright 2026 SPeCS.
* <p>
* Licensed 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 pt.up.fe.specs.clava.ast.expr.data.offsetof;

import org.suikasoft.jOptions.Datakey.DataKey;
import org.suikasoft.jOptions.Datakey.KeyFactory;

import pt.up.fe.specs.clava.ast.type.Type;

public class OffsetOfBase extends OffsetOfComponent {

/// DATAKEYS BEGIN

public final static DataKey<Type> TYPE = KeyFactory.object("type", Type.class);

/// DATAKEYS END

@Override
public String getCode() {
// Clang adds the base to the semantic path, but it is not part of the source designator.
return "";
}

@Override
public OffsetOfComponentKind getKind() {
return OffsetOfComponentKind.BASE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public static OffsetOfComponent newInstance(OffsetOfComponentKind kind) {
return new OffsetOfField();
case IDENTIFIER:
return new OffsetOfIdentifier();
case BASE:
return new OffsetOfBase();
default:
throw new NotImplementedException(kind);
}
Expand Down
Loading